Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

If I add two IPs like this:

ip addr add 1.1.1.1/24 dev eth2
ip addr add 1.1.1.2/24 dev eth2

and then I try to delete one of like this:

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
    
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 –  slimsuperhero Mar 12 '13 at 7:54

3 Answers 3

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

ip addr del 1.1.1.2/32 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 1.1.1.2 dev eth2 –  slimsuperhero 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? –  slimsuperhero 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 1.1.1.1/24 scope global eth0
    inet 1.1.2.3/24 scope global eth0
    inet 1.1.1.2/24 scope global secondary eth0
    inet 1.1.1.3/24 scope global secondary eth0

If you delete 1.1.1.1 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 1.1.1.2 dev eth2

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.