How safely change ip address on remote host ?

Sun 05 October 2014 by admin

Routine task change ip address on remote host without cut off. There are a lot of possibilites i.e. from reboot with new ip address to some fancy stuff with cron job. But there is a one method to make it clear and elegant.

Simply set:

echo 1 > /proc/sys/net/ipv4/conf/all/promote_secondaries

and set secondary/new ip address:

ip addr add <my_new_ip_addr_with_netmask> dev <my_interface>

delete old ip address:

ip addr del <my_old_ip_addr_with_netmask> dev <my_interface>

and without promote_secondaries option you will end up with no net, but fortunately secondary ip address become primary. Of course you should take care to of change default route if necessary i.e. by putting new default route with higher metric, so it becomes active when old ip will be deleted.