Configure multiple ip address on a
single NIC is possible with virtual network interfaces. as the name sugest, the
ip is configured virtually. Usually virtual network interface is used for
configuring multiple website with different ip address on a single web server,
also you can manage or classification your local network with virtual network
interface for security, maintenance, and troubleshooting purpose. The main advantages
is, you can configure multiple ip address in a single NIC. Here step by step to configure virtual network
interface.
Go
to default directory of network interface.
# cd /etc/sysconfig/network-scripts/
if
you type “ls” command you will see the following files
ifcfg-eth0 ifdown-isdn ifup-aliases
ifup-plusb init.ipv6-global
ifcfg-lo ifdown-post ifup-bnep
ifup-post net.hotplug
ifdown
ifdown-ppp ifup-eth ifup-ppp
network-functions
ifdown-bnep ifdown-routes ifup-ippp ifup-routes network-functions-ipv6
ifdown-eth ifdown-sit ifup-ipv6 ifup-sit
ifdown-ippp ifdown-tunnel ifup-isdn ifup-tunnel
ifdown-ipv6 ifup ifup-plip ifup-wireless
the
network interfaces files is called ifcfg-eth0.
Now
in this tutorial, we will create 2 virtual network interface. The configuration
will be like this
Physical
network interfaces
|
Virtual network interface 1
|
Virtual network interface 2
|
IP : 192.168.43.2
Netmask : 255.255.255.0
Gateway : 192.168.43.1
|
IP : 192.168.43.3
Netmask : 255.255.255.0
Gateway : 192.168.43.1
|
IP : 192.168.43.4
Netmask : 255.255.255.0
Gateway : 192.168.43.1
|
Copy
the network interface file
# cp ifcfg-eth0
ifcfg-eth0:0
# cp ifcfg-eth0
ifcfg-eth0:1
Ifcfg-eth0:0 and ifcfg-eth0:1 will be
our virtual network interface file.
Open the virtual network interface files
with nano editor
# nano ifcfg-eth0:0 ifcfg-eth0
ifcfg-eth0:1
Configuration the files similar to below
Eth0:0
DEVICE=eth0:0
HWADDR=00:0C:29:AA:79:28
TYPE=Ethernet
UUID=6b1c6abc-ecfe-4e91-832d-8a4ce3ea45c1
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.43.3
NETMASK=255.255.255.0
GATEWAY=192.168.43.1
Eth0:1
DEVICE=eth0:1
HWADDR=00:0C:29:AA:79:28
TYPE=Ethernet
UUID=6b1c6abc-ecfe-4e91-832d-8a4ce3ea45c1
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.43.4
NETMASK=255.255.255.0
GATEWAY=192.168.43.1
After that exit and save. Restart virtual network
interface
/etc/init.d/network
restart
To verify
your configuration, use command
ifconfig
if your
configuration success, you will see something similar like this in your terminal
eth0 Link encap:Ethernet HWaddr 00:0C:29:AA:79:28
inet addr:192.168.43.248 Bcast:192.168.43.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:feaa:7928/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1159 errors:0 dropped:0 overruns:0 frame:0
TX packets:1061 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:126925 (123.9 KiB) TX bytes:132598 (129.4 KiB)
Interrupt:19 Base address:0x2000
eth0:0 Link encap:Ethernet HWaddr 00:0C:29:AA:79:28
inet addr:192.168.43.3 Bcast:192.168.43.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2000
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:AA:79:28
inet addr:192.168.43.4 Bcast:192.168.43.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:19 Base address:0x2000