There are multiple ways to configure your network interface. In our article, we will describe how you can change your network configuration from DHCP (dynamic) IP address to Static IPv4 address in CentOS 8.
- Cloud VPS or Dedicated Server with CentOS 8 installed.
- You must be logged in via SSH as sudo or root user. This tutorial assumes that you are logged in as a sudo user.
Step 1: Log in using SSH
You must be logged in via SSH as sudo or root user. Please read this article for instructions if you don’t know how to connect.
Step 2: Find the active network interface
clear && echo $(ip -o -4 route get 22.214.171.124 | sed -nr 's/.*dev ([^\ ]+).*/\1/p')
Step 3: Configure the network interface
In our example, our network interface is ens18 with the following network details:
IPv4 = 126.96.36.199 Netmask = 255.255.255.0 Gateway = 188.8.131.52 DNS 184.108.40.206, 220.127.116.11
Our article will use network interface ens18 and the server details described above. Your server details will not be the same as our article and your network interface name can be different than ours. Use the network interface name from step 2.
Edit your network configuration file.
It should be similar to this configuration.
TYPE=Ethernet BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=yes IPV6_AUTOCONF=yes IPV6_DEFROUTE=yes IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=ens18 DEVICE=ens18 ONBOOT=yes NM_CONTROLLED=no
Replace the above lines with the lines below. This will disable DHCP and enable the static IPv4 address for your Operating System.
DEVICE="ens18" ONBOOT="yes" BOOTPROTO="none" TYPE="Ethernet" IPADDR="18.104.22.168" NETMASK="255.255.255.0" GATEWAY="22.214.171.124" DNS1="126.96.36.199" DNS2="188.8.131.52" NM_CONTROLLED="NO"
Apply the changes.
sudo systemctl restart network.service
Congratulations, you have now configured a static IPv4 address for your CentOS 8 Operating System. If you need to configure a static IPv6 address for your CentOS 8 please view this article.