How to Configure Static IP Address on RHEL 7.0/CentOS 7.0/Oracle Linux 7
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
# 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
Dimitri Nek
Dimitri is a Linux-wielding geek from Newport Beach and a server optimization guru with over 20 years of experience taming web hosting beasts. Equipped with an arsenal of programming languages and an insatiable thirst for knowledge, Dimitri conquers website challenges and scales hosting mountains with unmatched expertise. His vast knowledge of industry-leading hosting providers allows him to make well-informed recommendations tailored to each client’s unique needs.
How to set a static IP address on CentOS 8/ RHEL 8 / Oracle Linux 8
The entire ecosystem of the Red Hat Linux Enterprise family is used extensively on servers. Whether enterprise, small, or medium, RHEL-based distributions copy that segment along with Debian and Ubuntu. And in server management, it is common and frequent to use configurations over IP addresses. In this case, you will learn to establish a static IP address on CentOS 8, RHEL 8 and Oracle Linux 8.
How to set a static IP address on Centos 8 / RHEL 8 / Oracle Linux
Linux is a fairly flexible system and this results in several ways of doing the same process. In this case, it is the same, we will be able to establish a static IP address in several ways. To avoid unnecessarily lengthening the post, I will only show one single way.
It is advisable to read about static and dynamic IP addresses. This is because it is not always good to have them, although in an internal network it helps a lot to manage the services of that server. Even, at cluster level and related things, it is necessary to assign a specific address to a node.
Using the Network scripts to set a static IP address
I think this is the most basic way to set a static IP address in CentOS 8, RHEL 8 and Oracle Linux 8. Because this way we will not have to install or use third-party tools to do the configuration. On the other hand, it is a bit rough for newbies.
First of all, you have to know what the network interfaces you have active are called. Let us suppose that we are going to define a static IP address to the ethernet wired network.
So, open a terminal and run the following:
In the screen output of the command, you will notice that they open several interfaces. In my case, there are only two. The local and another one called enp0s3 . That is the one we want to change.
Now open the configuration file of that network interface. I will use nano for it, if you do not have it installed you can do it.
:~$ su :~# nano /etc/sysconfig/network-scripts/ifcfg-[network-interface]
The content of the file is quite explicit. However, to configure the static IP, it is enough to modify these elements:
TYPE="Ethernet" BOOTPROTO="none" NAME="eth0" IPADDR=192.168.250.105 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 BROADCAST=192.168.255.255 DEVICE="eth0" ONBOOT="yes"
Also, if you want to use DNS, add these two options.
DNS1=[DNS_SERVER] DNS2=[DNS_SERVER]
Next, save the changes and close the file.
It is now necessary to reload the networks profile so that the system knows that there have been changes.
Finally, restart the connection.
:~# nmcli con down [network_interface] :~# nmcli con up [network_interface]
Now, check the new IP address with this command:
Conclusion
In this post, you have learned to set a static IP address in CentOS 8, RHEL 8 and Oracle Linux 8. This way you will be able to manage some servers a little better and it is a very used network function. On the other hand, if you use any of these distributions as a personal system it is probably not useful.
Please share this post and join our Telegram channel.