Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I change a remote host primary IP address without getting disconnected at all (without being in a "no IP addr" state).

The matter is poorly discussed on Internet (according to my research). The best resource I found is a little bit tricky.

EXAMPLE : change to

1. ssh root@
2. ip addr add dev eth0 
3. logout

4. ssh root@
5. ip addr del dev eth0 

Problem: The last command removes both IP addresses and the connection is lost because is primary, and it removes its secondary addresses (to which belongs) when deleted.

I know I could "cheat" by adding (instead of 24). However, I think it is theoretically possible to do this properly.

What do you think?

share|improve this question
it is no cheat if you use /32 mask... – zb' Mar 13 '13 at 1:57
but it would not work because a /32 cannot communicate with anything but itself... – Totor Mar 13 '13 at 10:35
ok, but /25 will also not work than. – zb' Mar 13 '13 at 10:41
up vote 10 down vote accepted

You need to set the promote_secondaries option on the interface, or on all interfaces:

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


sysctl net.ipv4.conf.eth0.promote_secondaries=1

Change eth0 to all to have it work on all interfaces.

This option has been in since 2.6.12.

I tested this with a dummy interface and it worked there.

share|improve this answer
Exactly what I needed, thanks! See the original commit. – Totor Jan 13 '13 at 4:26
Please note that this option is available since 2.6.12, so before 2.6.16. – Totor Aug 27 '13 at 15:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.