Configuring Virtual Interface and Assign Multiple IP Addresses
Today In this short article, We will seen how to configure Multiple IP Addresses To Single NIC Card on RHEL/Centos7/Fedora22. Suppose Some times you might want to use more than one IP address for your network interface card, at that time you are going for extra network card and assign the new IP address. But its not necessary, On Linux we can creating or configuring multiple IP addresses on a single network interface is called “IP Aliasing”.
Let’s started with by showing a current network configuration using “ip addr” or “ifconfig” command.
[root@server1 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:d5:b2:a2 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.10/24 brd 192.168.1.255 scope global enp0s3
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fed5:b2a2/64 scope link
valid_lft forever preferred_lft forever
[root@server1 ~]#
As you seen above output, We have an interface called “enp0s3” device. if you will attached other Ethernet devices then there would be “enp0s8” or “enp0s9” devices.
Now as you know, Navigate to the network card configuration files of your system is stored under “/etc/sysconfig/network-scripts/” directory and do “ls” to list all devices.
[root@server1 ~]# cd /etc/sysconfig/network-scripts/
[root@server1 network-scripts]# ls
ifcfg-enp0s3 ifdown-ppp ifup-ib ifup-Team
ifcfg-lo ifdown-routes ifup-ippp ifup-TeamPort
ifdown ifdown-sit ifup-ipv6 ifup-tunnel
ifdown-bnep ifdown-Team ifup-isdn ifup-wireless
ifdown-eth ifdown-TeamPort ifup-plip init.ipv6-global
ifdown-ib ifdown-tunnel ifup-plusb network-functions
ifdown-ippp ifup ifup-post network-functions-ipv6
ifdown-ipv6 ifup-aliases ifup-ppp
ifdown-isdn ifup-bnep ifup-routes
ifdown-post ifup-eth ifup-sit
[root@server1 network-scripts]#
Lets check the full information of “enp0s3” device.
# cat ifcfg-enp0s3
[root@server1 network-scripts]# cat ifcfg-enp0s3 TYPE=Ethernet BOOTPROTO=static DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no NAME=enp0s3 UUID=c1d25750-1959-4034-a6b1-637dec60a04d DEVICE=enp0s3 ONBOOT=yes IPADDR0=192.168.1.10 NETMASK0=255.255.255.0 DNS1=192.168.1.10 [root@server1 network-scripts]#
Now, Edit the “ifcfg-enp0s3” file and assign Multiple addresses with subnet, as shown below example.
#vim ifcfg-enp0s3
TYPE=Ethernet BOOTPROTO=static DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no NAME=enp0s3 UUID=c1d25750-1959-4034-a6b1-637dec60a04d DEVICE=enp0s3 ONBOOT=yes IPADDR0=192.168.1.10 IPADDR1=192.168.1.20 IPADDR2=172.16.1.10 IPADDR3=10.88.0.10 NETMASK0=255.255.255.0 NETMASK1=255.255.255.0 NETMASK2=255.255.0.0 NETMASK3=255.0.0.0 DNS1=192.168.1.10 ~ ~ :wq
We added the ClassA(ex. 10.88.0.10), ClassB(172.16.1.10), ClassC(192.168.1.20) IP Addresses. After that we save and close the file and then Restart network service using below command.
[root@server1 network-scripts]# systemctl restart network [root@server1 network-scripts]#
Let check the status of “enp0s3” device using “ip addr” command.
[root@server1 network-scripts]# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:d5:b2:a2 brd ff:ff:ff:ff:ff:ff inet 192.168.1.10/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 172.16.1.10/16 brd 172.16.255.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 10.88.0.10/8 brd 10.255.255.255 scope global enp0s3 valid_lft forever preferred_lft forever inet 192.168.1.20/24 brd 192.168.1.255 scope global secondary enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fed5:b2a2/64 scope link valid_lft forever preferred_lft forever [root@server1 network-scripts]#
As you see above, the single network interface card has four IP addresses with subnet. Let check the pinging status newly added IP addresses.
[root@server1 ~]# ping -c3 192.168.1.20 PING 192.168.1.20 (192.168.1.20) 56(84) bytes of data. 64 bytes from 192.168.1.20: icmp_seq=1 ttl=64 time=0.069 ms 64 bytes from 192.168.1.20: icmp_seq=2 ttl=64 time=0.048 ms 64 bytes from 192.168.1.20: icmp_seq=3 ttl=64 time=0.069 ms --- 192.168.1.20 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 1999ms rtt min/avg/max/mdev = 0.048/0.062/0.069/0.009 ms [root@server1 ~]# [root@server1 ~]# ping -c3 172.16.1.10 PING 172.16.1.10 (172.16.1.10) 56(84) bytes of data. 64 bytes from 172.16.1.10: icmp_seq=1 ttl=64 time=0.110 ms 64 bytes from 172.16.1.10: icmp_seq=2 ttl=64 time=0.128 ms 64 bytes from 172.16.1.10: icmp_seq=3 ttl=64 time=0.123 ms --- 172.16.1.10 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2000ms rtt min/avg/max/mdev = 0.110/0.120/0.128/0.011 ms [root@server1 ~]# [root@server1 ~]# ping -c3 10.88.0.10 PING 10.88.0.10 (10.88.0.10) 56(84) bytes of data. 64 bytes from 10.88.0.10: icmp_seq=1 ttl=64 time=0.090 ms 64 bytes from 10.88.0.10: icmp_seq=2 ttl=64 time=0.125 ms 64 bytes from 10.88.0.10: icmp_seq=3 ttl=64 time=0.068 ms --- 10.88.0.10 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2004ms rtt min/avg/max/mdev = 0.068/0.094/0.125/0.024 ms [root@server1 ~]#
Hope this post will help Linux/Unix beginners. Please share you feedback and Comments. Till then connected with us at ittroubleshooter.in .!!!
Leave a Reply
Be the First to Comment!