This page is READ-ONLY. It is generated from the old site.
All timestamps are relative to 2013 (when this page is generated).
If you are looking for TeX support, please go to VietTUG.org

(linux) Assign new IP address to an inteface

Hi, try man ip first!
Added by icy over 1 year ago  »  Votes: 1/1

Keywords: Linux, ip

If your system is running well, then how can you add new ip address to an interface without any rebooting?

Ah... there is very simple tool named ip. The tool ip is very powerful and it can do many jobs, but let us first anwser the above question.

1 $ /sbin/ip addr add 10.0.0.95/32 dev eth0

After this command, the interface eth0 will have a new IP address "10.0.0.95". To view the result, you can use ifconfig, or sometimes you have to use ip addr:

1 $ ip addr
2 ....
3 3: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
4     link/ether 00:26:9e:9e:30:8f brd ff:ff:ff:ff:ff:ff
5     inet 10.0.0.95/32 scope global eth0

Final note: When using ip addr, the routing table isn't updated automatically, so you may want to use "route" to update it. Moreover, some services need to be restarted to listen on the new address.


Comments

Added by whatvn [G] over 1 year ago

using ifconfig adding sub interface also works well (but iproute2 is more efficient)

ifconfig eth0:0 a.b.c.d broadcast 
ifconfig eth0:1 e.f.g.h broadcast

and so on.

Added by icy over 1 year ago

Thanks H. Actually, I used ifconfig with no luck with my Virtualbox guest (and I didn't really know why). ip addr just worked :)