{"id":11440,"date":"2019-03-14T07:37:02","date_gmt":"2019-03-14T07:37:02","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11440"},"modified":"2019-03-14T07:37:02","modified_gmt":"2019-03-14T07:37:02","slug":"create-multiple-ip-addresses-to-one-single-network-interface","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/create-multiple-ip-addresses-to-one-single-network-interface\/","title":{"rendered":"Create Multiple IP Addresses to One Single Network Interface"},"content":{"rendered":"<p>The concept of creating or configuring multiple IP addresses on a single network interface is called\u00a0<strong>IP aliasing<\/strong>. IP aliasing is very useful for setting up multiple virtual sites on\u00a0<strong>Apache<\/strong>\u00a0using one single network interface with different\u00a0<strong>IP addresses<\/strong>\u00a0on a single subnet network.<\/p>\n<p>The main advantage of using this\u00a0<strong>IP aliasing<\/strong>\u00a0is, you don\u2019t need to have a physical adapter attached to each\u00a0<strong>IP<\/strong>, but instead you can create multiple or many virtual interfaces (<strong>aliases<\/strong>) to a single physical card.<\/p>\n<div id=\"attachment_3336\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/07\/Linux-IP-Aliasing.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3336\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/07\/Linux-IP-Aliasing.png\" alt=\"Linux IP Aliasing\" width=\"435\" height=\"321\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Create Multiple IP Addresses in One NiC<\/p>\n<\/div>\n<p>The instructions given here are applies to all major Linux distributions like\u00a0<strong>Red Hat<\/strong>,\u00a0<strong>Fedora<\/strong>, and\u00a0<strong>CentOS<\/strong>. Creating multiple interfaces and assign IP address to it manually is a daunting task. Here we\u2019ll see how we can assign IP address to it defining a set of IP range. Also understand how we are going to create a virtual interface and assign different range of IP Address to an interface in one go. In this article we used\u00a0<strong>LAN IP<\/strong>\u2018<strong>s<\/strong>, so replace those with ones you will be using.<\/p>\n<h3>Creating Virtual Interface and Assign Multiple IP Addresses<\/h3>\n<p>Here I have an interface called \u201c<strong>ifcfg-eth0<\/strong>\u201c, the default interface for the\u00a0<strong>Ethernet<\/strong>\u00a0device. If you\u2019ve attached second\u00a0<strong>Ethernet<\/strong>\u00a0device, then there would be an \u201c<strong>ifcfg-eth1<\/strong>\u201d device and so on for each device you\u2019ve attached. These device network files are located in \u201c<strong>\/etc\/sysconfig\/network-scripts\/<\/strong>\u201d directory. Navigate to the directory and do \u201c<strong>ls -l<\/strong>\u201d to list all devices.<\/p>\n<pre># cd \/etc\/sysconfig\/network-scripts\/\r\n# ls -l<\/pre>\n<h5>Sample Output<\/h5>\n<pre>ifcfg-eth0   ifdown-isdn    ifup-aliases  ifup-plusb     init.ipv6-global\r\nifcfg-lo     ifdown-post    ifup-bnep     ifup-post      net.hotplug\r\nifdown       ifdown-ppp     ifup-eth      ifup-ppp       network-functions\r\nifdown-bnep  ifdown-routes  ifup-ippp     ifup-routes    network-functions-ipv6\r\nifdown-eth   ifdown-sit     ifup-ipv6     ifup-sit\r\nifdown-ippp  ifdown-tunnel  ifup-isdn     ifup-tunnel\r\nifdown-ipv6  ifup           ifup-plip     ifup-wireless<\/pre>\n<p>Let\u2019s assume that we want to create three additional virtual interfaces to bind three IP addresses (<strong>172.16.16.126<\/strong>,\u00a0<strong>172.16.16.127<\/strong>, and\u00a0<strong>172.16.16.128<\/strong>) to the\u00a0<strong>NIC<\/strong>. So, we need to create three additional alias files, while \u201c<strong>ifcfg-eth0<\/strong>\u201d keeps the same primary\u00a0<strong>IP<\/strong>\u00a0address. This is how we moving forward to setup three aliases to bind the following\u00a0<strong>IP<\/strong>\u00a0addresses.<\/p>\n<pre><strong>Adapter<\/strong>            <strong>IP Address<\/strong>                <strong>Type<\/strong>\r\n-------------------------------------------------\r\neth0              172.16.16.125            Primary\r\neth0:0            172.16.16.126            Alias 1\r\neth0:1            172.16.16.127            Alias 2\r\neth0:2            172.16.16.128            Alias 3<\/pre>\n<p>Where \u201c<strong>:X<\/strong>\u201d is the device (<strong>interface<\/strong>) number to create the aliases for interface\u00a0<strong>eth0<\/strong>. For each alias you must assign a number sequentially. For example, we copying existing parameters of interface \u201c<strong>ifcfg-eth0<\/strong>\u201d in virtual interfaces called\u00a0<strong>ifcfg-eth0:0<\/strong>,\u00a0<strong>ifcfg-eth0:1<\/strong>\u00a0and\u00a0<strong>ifcfg-eth0:2<\/strong>. Go into the network directory and create the files as shown below.<\/p>\n<pre># cd \/etc\/sysconfig\/network-scripts\/\r\n# cp ifcfg-eth0 ifcfg-eth0:0\r\n# cp ifcfg-eth0 ifcfg-eth0:1\r\n# cp ifcfg-eth0 ifcfg-eth0:2<\/pre>\n<p>Open a file \u201c<strong>ifcfg-eth0<\/strong>\u201d and view the contents.<\/p>\n<pre>[root@tecmint network-scripts]# vi ifcfg-eth0\r\n\r\n<strong>DEVICE<\/strong>=\"eth0\"\r\nBOOTPROTO=static\r\nONBOOT=yes\r\nTYPE=\"Ethernet\"\r\n<strong>IPADDR<\/strong>=172.16.16.125\r\nNETMASK=255.255.255.224\r\nGATEWAY=172.16.16.100\r\nHWADDR=00:0C:29:28:FD:4C<\/pre>\n<p>Here we only need two parameters (<strong>DEVICE<\/strong>\u00a0and\u00a0<strong>IPADDR<\/strong>). So, open each file with\u00a0<strong>VI<\/strong>\u00a0editor and rename the\u00a0<strong>DEVICE<\/strong>\u00a0name to its corresponding alias and change the\u00a0<strong>IPADDR<\/strong>\u00a0address. For example, open files \u201c<strong>ifcfg-eth0:0<\/strong>\u201c, \u201c<strong>ifcfg-eth0:1<\/strong>\u201d and \u201c<strong>ifcfg-eth0:2<\/strong>\u201d using\u00a0<strong>VI<\/strong>\u00a0editor and change both the parameters. Finally it will look similar to below.<\/p>\n<h5>ifcfg-eth0:0<\/h5>\n<pre><strong>DEVICE=\"eth0:0\"<\/strong>\r\nBOOTPROTO=static\r\nONBOOT=yes\r\nTYPE=\"Ethernet\"\r\n<strong>IPADDR=172.16.16.126<\/strong>\r\nNETMASK=255.255.255.224\r\nGATEWAY=172.16.16.100\r\nHWADDR=00:0C:29:28:FD:4C<\/pre>\n<h5>ifcfg-eth0:1<\/h5>\n<pre><strong>DEVICE=\"eth0:1\"<\/strong>\r\nBOOTPROTO=static\r\nONBOOT=yes\r\nTYPE=\"Ethernet\"\r\n<strong>IPADDR=172.16.16.127<\/strong>\r\nNETMASK=255.255.255.224\r\nGATEWAY=172.16.16.100\r\nHWADDR=00:0C:29:28:FD:4C<\/pre>\n<h5>ifcfg-eth0:2<\/h5>\n<pre><strong>DEVICE=\"eth0:2\"<\/strong>\r\nBOOTPROTO=static\r\nONBOOT=yes\r\nTYPE=\"Ethernet\"\r\n<strong>IPADDR=172.16.16.128<\/strong>\r\nNETMASK=255.255.255.224\r\nGATEWAY=172.16.16.100\r\nHWADDR=00:0C:29:28:FD:4C<\/pre>\n<p>Once, you\u2019ve made all changes, save all your changes and restart\/start the network service for the changes to reflect.<\/p>\n<pre>[root@tecmint network-scripts]# \/etc\/init.d\/network restart<\/pre>\n<p>To verify all the aliases (virtual interface) are up and running, you can use \u201c<a title=\"ifconfig commands\" href=\"https:\/\/www.tecmint.com\/ifconfig-command-examples\/\" target=\"_blank\" rel=\"noopener\">ifconfig<\/a>\u201d or \u201c<a title=\"ip command examples\" href=\"https:\/\/www.tecmint.com\/ip-command-examples\/\" target=\"_blank\" rel=\"noopener\">ip<\/a>\u201d command.<\/p>\n<pre>[root@tecmint network-scripts]# ifconfig\r\neth0      Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:172.16.16.125  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          inet6 addr: fe80::20c:29ff:fe28:fd4c\/64 Scope:Link\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          RX packets:237 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:198 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:1000\r\n          RX bytes:25429 (24.8 KiB)  TX bytes:26910 (26.2 KiB)\r\n          Interrupt:18 Base address:0x2000\r\n\r\n<strong>eth0:0<\/strong>    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:<strong>172.16.16.126<\/strong>  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          Interrupt:18 Base address:0x2000\r\n\r\n<strong>eth0:1<\/strong>    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:<strong>172.16.16.127<\/strong>  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          Interrupt:18 Base address:0x2000\r\n\r\n<strong>eth0:2<\/strong>    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:<strong>172.16.16.128<\/strong>  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          Interrupt:18 Base address:0x2000<\/pre>\n<p>Ping each of them from different machine. If everything setup correctly, you will get a ping response from each of them.<\/p>\n<pre>ping 172.16.16.126\r\nping 172.16.16.127\r\nping 172.16.16.128<\/pre>\n<h5>Sample Output<\/h5>\n<pre>[root@tecmint ~]# ping <strong>172.16.16.126<\/strong>\r\nPING 172.16.16.126 (172.16.16.126) 56(84) bytes of data.\r\n64 bytes from 172.16.16.126: icmp_seq=1 ttl=64 time=1.33 ms\r\n64 bytes from 172.16.16.126: icmp_seq=2 ttl=64 time=0.165 ms\r\n64 bytes from 172.16.16.126: icmp_seq=3 ttl=64 time=0.159 ms\r\n\r\n--- 172.16.16.126 ping statistics ---\r\n3 packets transmitted, 3 received, 0% packet loss, time 2002ms\r\nrtt min\/avg\/max\/mdev = 0.159\/0.552\/1.332\/0.551 ms\r\n\r\n[root@tecmint ~]# ping <strong>172.16.16.127<\/strong>\r\nPING 172.16.16.127 (172.16.16.127) 56(84) bytes of data.\r\n64 bytes from 172.16.16.127: icmp_seq=1 ttl=64 time=1.33 ms\r\n64 bytes from 172.16.16.127: icmp_seq=2 ttl=64 time=0.165 ms\r\n64 bytes from 172.16.16.127: icmp_seq=3 ttl=64 time=0.159 ms\r\n\r\n--- 172.16.16.127 ping statistics ---\r\n3 packets transmitted, 3 received, 0% packet loss, time 2002ms\r\nrtt min\/avg\/max\/mdev = 0.159\/0.552\/1.332\/0.551 ms\r\n\r\n[root@tecmint ~]# ping <strong>172.16.16.128<\/strong>\r\nPING 172.16.16.128 (172.16.16.128) 56(84) bytes of data.\r\n64 bytes from 172.16.16.128: icmp_seq=1 ttl=64 time=1.33 ms\r\n64 bytes from 172.16.16.128: icmp_seq=2 ttl=64 time=0.165 ms\r\n64 bytes from 172.16.16.128: icmp_seq=3 ttl=64 time=0.159 ms\r\n\r\n--- 172.16.16.128 ping statistics ---\r\n3 packets transmitted, 3 received, 0% packet loss, time 2002ms\r\nrtt min\/avg\/max\/mdev = 0.159\/0.552\/1.332\/0.551 ms<\/pre>\n<p>Seems everything working smoothly, With these new IPs\u2019 you can setup virtual sites in\u00a0<strong>Apache<\/strong>,\u00a0<strong>FTP<\/strong>\u00a0accounts and many other things.<\/p>\n<h3>Assign Multiple IP Address Range<\/h3>\n<p>If you would like to create a\u00a0<strong>range<\/strong>\u00a0of\u00a0<strong>Multiple IP Addresses<\/strong>\u00a0to a particular interface called \u201c<strong>ifcfg-eth0<\/strong>\u201c, we use \u201c<strong>ifcfg-eth0-range0<\/strong>\u201d and copy the contains of\u00a0<strong>ifcfg-eth0<\/strong>\u00a0on it as shown below.<\/p>\n<pre>[root@tecmint network-scripts]# cd \/etc\/sysconfig\/network-scripts\/\r\n[root@tecmint network-scripts]# cp -p ifcfg-eth0 ifcfg-eth0-range0<\/pre>\n<p>Now open \u201c<strong>ifcfg-eth0-range0<\/strong>\u201d file and add \u201c<strong>IPADDR_START<\/strong>\u201d and \u201c<strong>IPADDR_END<\/strong>\u201d IP address range as shown below.<\/p>\n<pre>[root@tecmint network-scripts]# vi ifcfg-eth0-range0\r\n\r\n#DEVICE=\"eth0\"\r\n#BOOTPROTO=none\r\n#NM_CONTROLLED=\"yes\"\r\n#ONBOOT=yes\r\nTYPE=\"Ethernet\"\r\n<strong>IPADDR_START=172.16.16.126<\/strong>\r\n<strong>IPADDR_END=172.16.16.130<\/strong>\r\nIPV6INIT=no\r\n#GATEWAY=172.16.16.100<\/pre>\n<p>Save it and restart\/start network service<\/p>\n<pre>[root@tecmint network-scripts]# \/etc\/init.d\/network restart<\/pre>\n<p>Verify that virtual interfaces are created with\u00a0<strong>IP Address<\/strong>.<\/p>\n<pre>[root@tecmint network-scripts]# ifconfig\r\neth0      Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:172.16.16.125  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          inet6 addr: fe80::20c:29ff:fe28:fd4c\/64 Scope:Link\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          RX packets:1385 errors:0 dropped:0 overruns:0 frame:0\r\n          TX packets:1249 errors:0 dropped:0 overruns:0 carrier:0\r\n          collisions:0 txqueuelen:1000\r\n          RX bytes:127317 (124.3 KiB)  TX bytes:200787 (196.0 KiB)\r\n          Interrupt:18 Base address:0x2000\r\n\r\n<strong>eth0:0<\/strong>     Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:<strong>172.16.16.126<\/strong>  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          Interrupt:18 Base address:0x2000\r\n\r\n<strong>eth0:1<\/strong>    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:<strong>172.16.16.127<\/strong>  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          Interrupt:18 Base address:0x2000\r\n\r\n<strong>eth0:2<\/strong>    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:<strong>172.16.16.128<\/strong>  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          Interrupt:18 Base address:0x2000\r\n\r\n<strong>eth0:3<\/strong>    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:<strong>172.16.16.129<\/strong>  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          Interrupt:18 Base address:0x2000\r\n\r\n<strong>eth0:4<\/strong>    Link encap:Ethernet  HWaddr 00:0C:29:28:FD:4C\r\n          inet addr:<strong>172.16.16.130<\/strong>  Bcast:172.16.16.100  Mask:255.255.255.224\r\n          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1\r\n          Interrupt:18 Base address:0x2000<\/pre>\n<p>If you having any trouble in setting up, please do post your queries in the comment section.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/create-multiple-ip-addresses-to-one-single-network-interface\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The concept of creating or configuring multiple IP addresses on a single network interface is called\u00a0IP aliasing. IP aliasing is very useful for setting up multiple virtual sites on\u00a0Apache\u00a0using one single network interface with different\u00a0IP addresses\u00a0on a single subnet network. The main advantage of using this\u00a0IP aliasing\u00a0is, you don\u2019t need to have a physical adapter &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/14\/create-multiple-ip-addresses-to-one-single-network-interface\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Create Multiple IP Addresses to One Single Network Interface&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11440","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11440"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11440\/revisions"}],"predecessor-version":[{"id":11441,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11440\/revisions\/11441"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}