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.

With ifconfig we can change the netmask with the folowing:

ifconfig eth0 netmask <new netmask>

How can we do this with the command ip?

I know ifconfig is deprecated and this mostly why I would like to do it the iproute2 way.

My objective is to extend our current network from a /24 to a /21 on-the-fly without disturbing services running on our servers. As a workaround currently I simply add a new route to the /21 and eventually a planned network restart will officialize the change. It works but I was wondering if there is a better way.

Thanks,

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

How about:

ip address add 1.2.3.4/21 dev <device>
ip address del 1.2.3.4/24 dev <device>

(Where 1.2.3.4 is your current IP). ip address show Will list all of the assigned addresses.

share|improve this answer
    
Wow this works. I though I tried it with a resulting error problably a mistake. And this is better then ifconfig conterpart, with the ifconfig solution routes were dropped. –  NastyTux May 11 '11 at 15:08
    
Yeah, I'm still amazed by how powerful ip is. Also you get to shorten most of the keywords to two or three characters, which makes you look like a ninja when someone is watching you type. :) –  SmallClanger May 11 '11 at 15:24
    
Is this really the supposed way to do it? When I try this with ipv6 addresses I get "RTNETLINK answers: File exists" –  rudimeier Jul 8 '13 at 16:10
add comment

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.