How to configure a static CentOS 8 network address from the command line

Every CentOS admin should know how to configure a static IP address using nothing but the terminal.

How to configure a static CentOS 8 network address from the command line

CentOS 8 is here and it's chock full of new features and improvements. One feature that has not changed all that much is the configuration of a static network address. Although Ubuntu migrated to the much more user-friendly netplan tool, CentOS is still using the old-school method. 

If you don't happen to know how to manually configure a network address, switching it from DHCP to static, I'm going to show you how.

SEE: CentOS: A how-to guide (free PDF) (TechRepublic)

What You'll Need

All you'll need to make this work is the following:

  • A running instance of CentOS 8
  • An available IP address
  • A user with sudo privileges

How to locate the device name

The first thing we must do is locate the device name to be configured. Do this with the command:

ip a

This should reveal the name of your network interface (Figure A).

Figure A


My interface name is enp0s3.

How to backup your configuration file

Next, we're going to backup the original configuration file with the command:

sudo mv /etc/sysconfig/network-scripts/ifcfg-NAME /etc/sysconfig/network-scripts/ifcfg-NAME.bak

Where NAME is the name of your network interface.

How to create a new configuration

Now we create a new configuration file with the following command:

sudo nano /etc/sysconfig/network-scripts/ifcfg-NAME

Where NAME is the name of your network interface.

In that file, paste the following:



  • NAME is the name of the network interface
  • IP_ADDRESS is the static IP address you want to apply to the interface
  • GATEWAY is the gateway address for your network

Save and close the file.

Restart the network manager with the command:

sudo systemctl restart NetworkManager

Your static IP address has been applied

How to configure DNS servers

Because we're using a static IP address, we might also want to use static addresses for DNS resolution (which is why we added PEERDNS=no to the configuration file). To configure DNS servers, issue the command:

sudo nano /etc/resolv.conf

In that file, add your static DNS addresses below the last line like so:


Save and close the file.

And that's all there is to configuring a static IP address in CentOS 8. 

Also see


Image: CentOS

By Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic, The New Stack, and Linux New Media. He's covered a variety of topics for over twenty years and is an avid promoter of open source. For more news about Jack Wallen, visit his website jackwallen....