{"id":75,"date":"2018-11-26T14:15:52","date_gmt":"2018-11-26T14:15:52","guid":{"rendered":"http:\/\/tamer-az.com\/?p=75"},"modified":"2018-11-26T18:19:52","modified_gmt":"2018-11-26T18:19:52","slug":"adding-secondary-ip-addresses-centos-rhel%ef%bb%bf","status":"publish","type":"post","link":"https:\/\/tamer-az.com\/?p=75","title":{"rendered":"Adding Secondary IP Addresses (CentOS\/RHEL)\ufeff"},"content":{"rendered":"\n<p>There are plenty of reasons you would need to add secondary IP addresses (and everyone agrees that <strong>SEO<\/strong>is not one of them). Getting a secondary IP address is a simple process if it is done for the right reasons and done correctly. You do NOT need additional NIC cards but you will be creating virtual adapters as the secondary IP will be routing through the primary IP.<\/p>\n\n\n\n<p>&nbsp;Also, this is a great thing to do athome as I&#8217;ve done it to run multiple internal IP addresses on one server to run multiple applications across the same ports (for KISS** sake). Please note that I am doing this is in a virtual testing environment so your settings will definitely be different.<\/p>\n\n\n\n<p>** KISS = Keep It Stupid Simple **<\/p>\n\n\n\n<p>You will need to be the root user and navigate to your \/etc\/sysconfig\/network-scripts<\/p>\n\n\n\n<p>#\ncd \/etc\/sysconfig\/network-scripts<\/p>\n\n\n\n<p>When getting a list of files in the directory you will see &#8220;ifcfg-eth0&#8221; (or eth1 if you&#8217;re doing it for a different adapter)<\/p>\n\n\n\n<p>#\nls -l | grep ifcfg-eth<\/p>\n\n\n\n<p>-rw-r&#8211;r&#8211;\n1 root root&nbsp;&nbsp; 119 Jan 11 19:16 ifcfg-eth0<\/p>\n\n\n\n<p>-rw-r&#8211;r&#8211;\n1 root root&nbsp;&nbsp; 119 Jan&nbsp; 3 08:45 ifcfg-eth0.bak<\/p>\n\n\n\n<p>-rw-r&#8211;r&#8211;\n1 root root&nbsp;&nbsp; 119 Feb 24 04:34 ifcfg-eth1<\/p>\n\n\n\n<p>-rw-r&#8211;r&#8211;\n1 root root&nbsp;&nbsp; 128 Jan 19 18:20\nifcfg-eth1.bak<\/p>\n\n\n\n<p>Now adding the virtual adapters is easy. Basically if the main adapter is called &#8220;eth0&#8221; you have to call the next (virtual) adapter in a sequential order like so:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>ifcfg-eth0 (primary adapter, physical)<\/li><li>ifcfg-eth0:1 (first virtual adapter to the physical\n     primary adapter)<\/li><li>ifcfg-eth0:2 (second virtual adapter to the physical\n     primary adapter)<\/li><li>and so on&#8230;<\/li><\/ul>\n\n\n\n<p>That being said, lets go ahead and\ncopy our primary adapter configuration file and name it to be the first virtual\nadapter for the physical primary:<\/p>\n\n\n\n<p>#\ncp ifcfg-eth0 ifcfg-eth0:1<\/p>\n\n\n\n<p>#\nls -l | grep ifcfg-eth<\/p>\n\n\n\n<p>-rw-r&#8211;r&#8211;\n1 root root&nbsp;&nbsp; 119 Jan 11 19:16 ifcfg-eth0<\/p>\n\n\n\n<p><strong>-rw-r&#8211;r&#8211;\n1 root root&nbsp;&nbsp; 119 Feb 24 08:53\nifcfg-eth0:1<\/strong><\/p>\n\n\n\n<p>-rw-r&#8211;r&#8211;\n1 root root&nbsp;&nbsp; 119 Jan&nbsp; 3 08:45 ifcfg-eth0.bak<\/p>\n\n\n\n<p>-rw-r&#8211;r&#8211;\n1 root root&nbsp;&nbsp; 119 Feb 24 04:34 ifcfg-eth1<\/p>\n\n\n\n<p>-rw-r&#8211;r&#8211;\n1 root root&nbsp;&nbsp; 128 Jan 19 18:20 ifcfg-eth1.bak<\/p>\n\n\n\n<p>Now, we have to configure this virtual adapter to be: a static IP (of course), no hardware address (MAC),configure net mask and of course rename the device.<\/p>\n\n\n\n<p>#\nvim ifcfg-eth0:1<\/p>\n\n\n\n<p>DEVICE=eth0:1<\/p>\n\n\n\n<p>BOOTPROTO=static<\/p>\n\n\n\n<p>ONBOOT=yes<\/p>\n\n\n\n<p>IPADDR=10.1.1.2<\/p>\n\n\n\n<p>NETMASK=255.255.255.0<\/p>\n\n\n\n<p>There is no need to specify a MAC address as it is a virtual adapter and there is also no need to specify a default gateway as it is already routed through the primary adapter. Basically there are only four things that you will need to change:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>File name for the adapter itself<\/li><li>DEVICE=&lt;device name&gt; (should correspond with the\n     file name)<\/li><li>IPADDR=&lt;ip address&gt;<\/li><li>NETMASK=&lt;netmask&gt;<\/li><\/ul>\n\n\n\n<p>Afterwards, just restart the networking service:<\/p>\n\n\n\n<p>#\nservice network restart<\/p>\n\n\n\n<p>That&#8217;s it; lets check ifconfig to\nmake sure the virtual adapter is there and working:<\/p>\n\n\n\n<p>#\nifconfig eth0:1<\/p>\n\n\n\n<p>eth0:1&nbsp;&nbsp;&nbsp; Link encap:Ethernet&nbsp; HWaddr 08:00:27:ED:05:B7<\/p>\n\n\n\n<p>inet\naddr:10.1.1.2&nbsp; Bcast:10.1.1.255&nbsp; Mask:255.255.255.0<\/p>\n\n\n\n<p>UP\nBROADCAST RUNNING MULTICAST&nbsp;\nMTU:1500&nbsp; Metric:1<\/p>\n\n\n\n<p>#\nping 10.1.1.2<\/p>\n\n\n\n<p>PING\n10.1.1.2 (10.1.1.2) 56(84) bytes of data.<\/p>\n\n\n\n<p>64\nbytes from 10.1.1.2: icmp_seq=1 ttl=64 time=0.073 ms<\/p>\n\n\n\n<p>64\nbytes from 10.1.1.2: icmp_seq=2 ttl=64 time=0.042 ms<\/p>\n\n\n\n<p>64\nbytes from 10.1.1.2: icmp_seq=3 ttl=64 time=0.029 ms<\/p>\n\n\n\n<p>64\nbytes from 10.1.1.2: icmp_seq=4 ttl=64 time=0.029 ms<\/p>\n\n\n\n<p>&#8212;\n10.1.1.2 ping statistics &#8212;<\/p>\n\n\n\n<p>4\npackets transmitted, 4 received, 0% packet loss, time 2999ms<\/p>\n\n\n\n<p>rtt\nmin\/avg\/max\/mdev = 0.029\/0.043\/0.073\/0.018 ms<\/p>\n\n\n\n<p>Per Steven&#8217;s comment: a second note.\nIf you&#8217;re not sure if you&#8217;ve done it right and you do not want to restart the\nentire network server, you can use the following:<\/p>\n\n\n\n<p>#\nifup eth0:1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are plenty of reasons you would need to add secondary IP addresses (and everyone agrees that SEOis not one of them). Getting a secondary IP address is a simple process if it is done for the right reasons and done correctly. You do NOT need additional NIC cards but you will be creating virtual adapters as the secondary IP<\/p>\n<div class=\"clearfix\"><\/div>\n<div class=\"pull-left padding-top-25\"><a href=\"https:\/\/tamer-az.com\/?p=75\" class=\"btn btn-theme\">Continue reading<span class=\"screen-reader-text\"> &#8220;Adding Secondary IP Addresses (CentOS\/RHEL)\ufeff&#8221;<\/span> <i class=\"fa fa-fw fa-long-arrow-right\"><\/i> <\/a>  <\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,1],"tags":[],"class_list":["post-75","post","type-post","status-publish","format-standard","hentry","category-linux","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/tamer-az.com\/index.php?rest_route=\/wp\/v2\/posts\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tamer-az.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tamer-az.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tamer-az.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tamer-az.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=75"}],"version-history":[{"count":2,"href":"https:\/\/tamer-az.com\/index.php?rest_route=\/wp\/v2\/posts\/75\/revisions"}],"predecessor-version":[{"id":82,"href":"https:\/\/tamer-az.com\/index.php?rest_route=\/wp\/v2\/posts\/75\/revisions\/82"}],"wp:attachment":[{"href":"https:\/\/tamer-az.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=75"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tamer-az.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=75"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tamer-az.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}