This article will describe the procedure to configure static Ip address on RHEL 7/CentOS 7/Oracle Linux 7 minimal installation. Network interface configuration files control the software interfaces for individual network devices. As the system boots, it uses these files to determine what interfaces to bring up and how to configure them. These files are usually named ifcfg-name. Since the release of RHEL 7, redhat come with the new naming scheme for the network devices. In RHEL7/CentOS7/Oracle Linux 7, the default network interface name is based on firmware, topology, and location information. In this procedure, the network interface name is ifcfg-ens160.
1. Original ip configuration :
# cat /etc/sysconfig/network-scripts/ifcfg-ens160 HWADDR=00:02:22:G4:EE:FF TYPE=Ethernet BOOTPROTO=dhcp DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=ens160 UUID=34796933-af4b-4a41-8287-6e57ac131234 ONBOOT=no
2. Please change BOOTPROTO to static or none, ONBOOT statement is set on YES and don’t change HWADDR and UUID values provided by default. Please add IPADDR, NETMASK, GATEWAY and DNS1 line as below :
HWADDR=00:02:22:G4:EE:FF TYPE=Ethernet BOOTPROTO=none DEFROUTE=yes PEERDNS=yes PEERROUTES=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_PEERDNS=yes IPV6_PEERROUTES=yes IPV6_FAILURE_FATAL=no NAME=ens160 UUID=34796933-af4b-4a41-8287-6e57ac131234 ONBOOT=yes IPADDR=192.168.0.70 NETMASK=255.255.255.0 GATEWAY=192.168.0.1 DNS1=8.8.8.8
3. Restart network interface to take effect :
# systemctl restart network
or
# service network restart Restarting network (via systemctl): [ OK ]
4. Run ifconfig to display the ip address. If your ifconfig command is not found, please follow this instruction to install it.(How to Install ifconfig and netstat on RHEL 7.0/CentOS 7.0):
# ifconfig ens160: flags=4163mtu 1500 inet 192.168.0.70 netmask 255.255.255.0 broadcast 192.168.0.255 inet6 fe80::20c:29ff:feba:3efe prefixlen 64 scopeid 0x20 ether 00:0c:29:ba:3e:fe txqueuelen 1000 (Ethernet) RX packets 20775 bytes 1455662 (1.3 MiB) RX errors 0 dropped 40 overruns 0 frame 0 TX packets 1289 bytes 179594 (175.3 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10 loop txqueuelen 0 (Local Loopback) RX packets 8 bytes 656 (656.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 8 bytes 656 (656.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0