How to Configure Static IPv4 address on CentOS 8

Estimated reading time: 1 min

Introduction

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.

Prerequisites

  • 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 8.8.8.8 | 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 = 185.62.56.31
Netmask = 255.255.255.0 
Gateway = 185.62.56.1
DNS 89.207.128.252, 89.207.130.252

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.

nano /etc/sysconfig/network-scripts/ifcfg-ens18

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="185.62.56.31"
NETMASK="255.255.255.0"
GATEWAY="185.62.56.1"
DNS1="89.207.128.252"
DNS2="89.207.130.252"
NM_CONTROLLED="NO"

Apply the changes.

sudo systemctl restart network.service

Conclusion

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.

Was this article helpful?
Dislike 0
Views: 6104

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *