Ubuntu – Apply static IP address change in /etc/network/interfaces in Ubuntu 16.04


TL;DR: In Ubuntu 14.04, If you change a static IP address in /etc/network/interfaces and apply the changes with ifdown and then ifup command everything works fine. But this sequence is not working in 16.04. What is the best alternative?

In ubuntu 16.04, after changing interfaces file and ifdown/ifup sequence, ip addr show <device> command shows both old and new static IP addresses for <device>. I used -v (verbose) argument with ifdown/ifup in both ubuntu 14.04 and 16.04. The difference was in ifdown. In ubuntu 14.04 ifdown executes this command:

ip -4 addr flush dev <device> label <device>

While in 16.04:

ip addr del <ip-address-in-network-interfaces>/<subnet> dev <device> label <device>

So I figured out, in 16.04, If I first run the ifdown command. Then change the IP address in /etc/network/interfaces file and then use the ifup command to bring the interface up again, the old IP address will be deleted correctly.

Another solution is running the ip addr flush command before ifdown/ifup:

ip addr flush dev <device>

It seems that I already answered my question, but I want to know what are the alternatives and what is the best solution to change a static IP address in Ubuntu 16.04?

Best Answer

you can add flush inside interfaces definition like

iface eth0 inet manual
post-down ip addr flush dev $IFACE