Change Linux primary IP address without losing connectivity
You need to change an IP address on an interface without loosing connectivity....
(modify IPs and interface names as required)
First you have to add a secondary IP address to the interface:
ip addr add 192.168.1.10/24 dev eth0
and confirm like so:
ip addr show eth0
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 44:38:39:00:11:aa brd ff:ff:ff:ff:ff:ff
inet 192.168.1.5/24 scope global eth0
inet 192.168.1.10/24 scope global secondary eth0
Now setup the interface so it will promote the secondary IP address when we remove the first:
echo 1 > /proc/sys/net/ipv4/conf/eth0/promote_secondaries
or
sysctl net.ipv4.conf.eth0.promote_secondaries=1
** L33t TIP: Change eth0 to 'all' to have it work on all interfaces.
Lastly, remove the original IP address and confirm:
ip addr del 192.168.1.5/24 dev eth0
ip addr show dev eth0
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
link/ether 44:38:39:00:11:aa brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 scope global eth0
Enjoy !