Home   >>   Networking   >>   Add Additional IP To One Interface On Linux
Add Additional IP To One Interface On Linux PDF Print E-mail
( 0 Votes )
How To - Networking
Written by Christian Foronda   
Tuesday, 07 September 2010 08:37

This is tested only on CentOS.

# cat /etc/sysconfig/network-scripts/ifcfg-eth0

 

DEVICE=eth0
HWADDR=EE:1E:2E:6E:EB:EC
IPADDR=192.168.1.1
NETMASK=255.255.255.0
ONBOOT=yes

 

# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0

 

# vi /etc/sysconfig/network-scripts/ifcfg-eth0:0

 

DEVICE=eth0:0
HWADDR=EE:1E:2E:6E:EB:EC
IPADDR=192.168.1.2
NETMASK=255.255.255.0
ONBOOT=yes

 

# ifup eth0:0

 

Verify:

eth0	Link encap:Ethernet  HWaddr EE:1E:2E:6E:EB:EC
		inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
		UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
		RX packets:261372616 errors:0 dropped:0 overruns:0 frame:0
		TX packets:211532108 errors:0 dropped:0 overruns:0 carrier:0
		collisions:0 txqueuelen:1000 
		RX bytes:117056751250 (109.0 GiB)  TX bytes:289980767749 (270.0 GiB)

eth0:0	Link encap:Ethernet  HWaddr EE:1E:2E:6E:EB:EC  
		inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
		UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

 

Quick and dirty way:

Via ifconfig command:

# ifconfig eth0:0 192.168.1.2
# route add -host 192.168.1.2 dev eth0:0 

 

To add additional IP addresses:

# ifconfig eth0:1 192.168.1.3
# ifconfig eth0:2 192.168.1.4
# ifconfig eth0:3 192.168.1.5
# route add -host 192.168.1.3 dev eth0:1
# route add -host 192.168.1.4 dev eth0:2 
# route add -host 192.168.1.5 dev eth0:3 

 

To remove virtual interfaces or network aliases:

# ifconfig eth0:1 down

 

Via ip command:

# ip addr add 192.168.1.2/24 brd + dev eth0

 

Verify:

# ip addr show
2: eth0:  mtu 1500 qdisc noop qlen 1000
    link/ether 00:03:6d:00:83:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.1/24 brd 192.168.1.255 scope global eth0
    inet 192.168.1.2/24 brd 192.168.1.255 scope global eth0

 

Remove unwanted address:

# ip addr del 192.168.1.2/24 dev eth0

 




blog comments powered by Disqus
Last Updated on Friday, 20 May 2011 11:25