{"id":6722,"date":"2017-05-08T16:50:17","date_gmt":"2017-05-08T08:50:17","guid":{"rendered":"http:\/\/rmohan.com\/?p=6722"},"modified":"2017-05-08T16:50:17","modified_gmt":"2017-05-08T08:50:17","slug":"centos-rhel-7-configuring-static-ip-adress-using-network-interface-configuration-files","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6722","title":{"rendered":"CentOS \/ RHEL 7 : Configuring static IP adress using network interface configuration files"},"content":{"rendered":"<p>There are various ways you can configure an IP address in RHEL 7. The posts discusses the use of network interface configuration files to configure the IP address. Each physical network device has an associated network interface configuration file. Network interface configuration files are located in the \/etc\/sysconfig\/network-scripts directory.<\/p>\n<p>1. Use the ip addr command to display your available network interfaces.<\/p>\n<p># ip addr<br \/>\n1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN<br \/>\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00<br \/>\n    inet 127.0.0.1\/8 scope host lo<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 ::1\/128 scope host<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000<br \/>\n    link\/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff<br \/>\n    inet 192.168.43.104\/24 brd 192.168.43.255 scope global dynamic eth0<br \/>\n       valid_lft 2792sec preferred_lft 2792sec<br \/>\n    inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc\/64 scope global<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 fe80::250:56ff:fe23:2fbc\/64 scope link<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000<br \/>\n    link\/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff<br \/>\nNote that you have 3 Ethernet interfaces (eth0, eth1) and the loopback interface (lo). If you interface names are somthing like eno16777736, refere this post to change the interface naming to eth0 and eth1.<\/p>\n<p>2. cd into the \/etc\/sysconfig\/network-scripts directory which holds the network interface configuration files.<\/p>\n<p># cd \/etc\/sysconfig\/network-scripts<br \/>\nHere you would find the network configuration file for the eth1 interface i.e. ifcfg-eth1. If not already present you can copy the interface configuration file of interface eth0.<\/p>\n<p>3. We want to assign IP address 192.168.1.30 to the interface eth1. Edit the configuration file for the interface and change the highlighted parameters as show below :<\/p>\n<p># vi ifcfg-eth1<br \/>\nTYPE=&#8221;Ethernet&#8221;<br \/>\nBOOTPROTO=&#8221;none&#8221;<br \/>\nDEFROUTE=&#8221;no&#8221;<br \/>\nIPV4_FAILURE_FATAL=&#8221;no&#8221;<br \/>\nIPV6INIT=&#8221;yes&#8221;<br \/>\nIPV6_AUTOCONF=&#8221;yes&#8221;<br \/>\nIPV6_DEFROUTE=&#8221;yes&#8221;<br \/>\nIPV6_FAILURE_FATAL=&#8221;no&#8221;<br \/>\nNAME=&#8221;eno16777736&#8243;<br \/>\nUUID=&#8221;7fe712d2-5e3a-4f68-b34b-4b3f6c787a56&#8243;<br \/>\nONBOOT=&#8221;yes&#8221;<br \/>\nIPADDR0=&#8221;192.168.1.30&#8243;<br \/>\nPREFIX0=&#8221;24&#8243;<br \/>\nHWADDR=&#8221;00:0C:29:D5:6E:9C&#8221;<br \/>\nIPV6_PEERDNS=&#8221;yes&#8221;<br \/>\nIPV6_PEERROUTES=&#8221;yes&#8221;<br \/>\n4. Edit the \/etc\/hosts file to add the entry for the new IP address :<\/p>\n<p># cat \/etc\/hosts<br \/>\n127.0.0.1   \tlocalhost localhost.localdomain localhost4 localhost4.localdomain4<br \/>\n::1         \tlocalhost localhost.localdomain localhost6 localhost6.localdomain6<br \/>\n192.168.1.30\tgeeklab<br \/>\n5. Restart the network services :<\/p>\n<p># systemctl restart network<br \/>\n# ip addr<br \/>\n1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN<br \/>\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00<br \/>\n    inet 127.0.0.1\/8 scope host lo<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 ::1\/128 scope host<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000<br \/>\n    link\/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff<br \/>\n    inet 192.168.43.104\/24 brd 192.168.43.255 scope global dynamic eth0<br \/>\n       valid_lft 2538sec preferred_lft 2538sec<br \/>\n    inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc\/64 scope global<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 fe80::250:56ff:fe23:2fbc\/64 scope link<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000<br \/>\n    link\/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff<br \/>\n    inet 192.168.1.30\/24 brd 192.168.1.255 scope global eth1<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 fe80::20c:29ff:fed5:6ea6\/64 scope link<br \/>\n       valid_lft forever preferred_lft forever<br \/>\nUsing network interface control scripts to stop\/start a specific network interface<\/p>\n<p>The network interface control scripts i.e. ifup and ifdown. Use the ifdown command to stop the interface and eno16777736. Verify the status of the interface using \u201cif addr\u201d command (the ip address should have disappeared):<\/p>\n<p># ifdown eth1<br \/>\n# ip a<br \/>\n1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN<br \/>\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00<br \/>\n    inet 127.0.0.1\/8 scope host lo<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 ::1\/128 scope host<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000<br \/>\n    link\/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff<br \/>\n    inet 192.168.43.104\/24 brd 192.168.43.255 scope global dynamic eth0<br \/>\n       valid_lft 2751sec preferred_lft 2751sec<br \/>\n    inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc\/64 scope global<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 fe80::250:56ff:fe23:2fbc\/64 scope link<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000<br \/>\n    link\/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff<br \/>\nUse the ifup command to start the interface again :<\/p>\n<p># ifup eth1<br \/>\n# ip addr<br \/>\n1: lo: [LOOPBACK,UP,LOWER_UP] mtu 65536 qdisc noqueue state UNKNOWN<br \/>\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00<br \/>\n    inet 127.0.0.1\/8 scope host lo<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 ::1\/128 scope host<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n2: eth0: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000<br \/>\n    link\/ether 00:50:56:23:2f:bc brd ff:ff:ff:ff:ff:ff<br \/>\n    inet 192.168.43.104\/24 brd 192.168.43.255 scope global dynamic eth0<br \/>\n       valid_lft 2720sec preferred_lft 2720sec<br \/>\n    inet6 2405:204:10a:6c1:250:56ff:fe23:2fbc\/64 scope global<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 fe80::250:56ff:fe23:2fbc\/64 scope link<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n3: eth1: [BROADCAST,MULTICAST,UP,LOWER_UP] mtu 1500 qdisc pfifo_fast state UP qlen 1000<br \/>\n    link\/ether 00:0c:29:d5:6e:a6 brd ff:ff:ff:ff:ff:ff<br \/>\n    inet 192.168.1.30\/24 brd 192.168.1.255 scope global eth1<br \/>\n       valid_lft forever preferred_lft forever<br \/>\n    inet6 fe80::20c:29ff:fed5:6ea6\/64 scope link<br \/>\n       valid_lft forever preferred_lft forever<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are various ways you can configure an IP address in RHEL 7. The posts discusses the use of network interface configuration files to configure the IP address. Each physical network device has an associated network interface configuration file. Network interface configuration files are located in the \/etc\/sysconfig\/network-scripts directory.<\/p>\n<p>1. Use the ip addr command [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6722"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6722"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6722\/revisions"}],"predecessor-version":[{"id":6723,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6722\/revisions\/6723"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6722"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6722"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6722"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}