Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I add two IPs like this:

  1. ip addr add 1.1.1.1/24 dev eth2
  2. ip addr add 1.1.1.2/24 dev eth2

and then I try to delete one of like this:

  1. ip addr del 1.1.1.2/24 dev eth2

BOTH IPs will be deleted and I don't know how to handle it.

Any one knows how to solve it?

share|improve this question

2 Answers 2

up vote 1 down vote accepted

If you do ip addr list dev eth2 after your two add commands, you will see something like this (emphasis mine):

2: eth2:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
     link/ether 00:11:22:33:44:55 brd ff:ff:ff:ff:ff:ff
     inet 192.168.1.1/24 brd 192.168.1.255 scope global eth2
     inet 1.1.1.1/24 scope global eth2
     inet 1.1.1.2/24 scope global secondary eth2

The important part to notice is that Linux treats the second address as secondary to the first one, as they are in the same logical subnet (/24). Deleting the secondary address has no impact on the primary one, but vice versa.

If you need to add/del addresses in 1.1.1.0/24, you probably should first add one address which is always valid (e.g. 1.1.1.99/24) and then add 1.1.1.1 and 1.1.1.2 as secondary addresses. Then you can add/delete the .1 and .2 address at will.

If this is not possible, then you can also temporarily add 1.1.1.2/32 before deleting 1.1.1.1. This will maintain connectivity for all connections from outside your network. Depending on your network setup (i.e., whether your router supports proxy ARP), you may also be able to use 1.1.1.2/0 temporarily.

share|improve this answer

Something else is likely doing things behind your back. NetworkManager is a known offender.

Run ip monitor while executing your commands, and see if someone else is modifying the configuration.

share|improve this answer

Your Answer

 
discard

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.