Server Fault is a question and answer site for system and network administrators. 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

If I add two IPs like this:

ip addr add dev eth2
ip addr add dev eth2

and then I try to delete one of like this:

ip addr del 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
Your requuirement is not clear. Can you tell what is the expected output here? – Guru Mar 12 '13 at 7:12
I need to say ip just to delete one IP not both of them – Hamed JML Mar 12 '13 at 7:18
Please add ip addr show output – Gevial Mar 12 '13 at 7:54

Deleting a primary IP address from an interface will, by default, delete all other address on the same subnet.

This is a reply to a REHL bug 1136733 reported by the user lain who provided an answer on 12-Mar-13 ...

You're adding multiple addresses in the same subnet, thus the second and subsequent ones become secondaries. This can be seen in the "ip addr show" output, note the keyword "secondary" next to those addresses.

By default, when deleting a primary address, kernel deletes also all respective secondaries.

If you want one of the secondaries to be promoted to be a new primary on primary deletion, set the net.ipv4.conf.eth9.promote_secondaries sysctl.

share|improve this answer

This happens because you use /24 network mask when delete. It is applied to address you input. Try the following:

ip addr del dev eth2

The /32 mask defines exactly one host.

share|improve this answer
This does not work as I have gave the system /24 netmask not /32. – Hamed JML Mar 12 '13 at 7:22
Try without netmask at all: ip addr del dev eth2 – Gevial Mar 12 '13 at 7:35
Again it Delete both IPs!! – Hamed JML Mar 12 '13 at 7:37
Strange. On my testing CentOS box deleting without netmask was successful. Though deleting with /24 also affected only one address. What distro are you using? – Gevial Mar 12 '13 at 7:38
I am using Ubuntu 12.04 – Hamed JML Mar 12 '13 at 7:46

I don't have an eth2 to check this on but it works correctly on eth0 and I see no reason why eth2 should be magical. I presume you're using ip addr show dev eth2 as ifconfig eth2 doesn't appear to show the additional addresses added by ip.

One thing I have noticed is that the order you create/delete the addresses is important. The second and subsequent addresses added within the same network will be deleted if the primary address is deleted. Consider ...

    inet scope global eth0
    inet scope global eth0
    inet scope global secondary eth0
    inet scope global secondary eth0

If you delete then the 1.2 and 1.3 addresses will be deleted too. If you delete any other address then only that address will be deleted.

share|improve this answer
So, how can I delete first address without removing others? – Hamed JML Mar 13 '13 at 12:53

I would try the following:

ip addr del dev eth2

share|improve this answer

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.