How to Configure Static IP on CentOS 8 (CLI)

Method 1 – Using nmtui Tool

Execute the following command to get access to an interactive way of network interface configuration.

sudo nmtui

Now, edit the default existing connection. In case no connection is available, use Activate a connection.

Setup networking centos 8

You will see the list of Ethernet interfaces, Select the interface you want to configure, Then select Edit option on the right side of the interface.

Configure static IP centOS 8

Keep the profile name and device name unchanged. Set the IP address, gateway and DNS servers under the IPv4 configuration option. You can add multiple addresses by selection option just below IP address box.

Use nmtui network configuration on centos 8

Save the configuration and restart the NetworkManager service using the following command.

sudo systemctl restart NetworkManager.service

Method 2 – Using Configuration Files

The default netework interfaces configuration file exists in /etc/sysconfig/network-scripts/ directory. The file name may vary as per your installation type like Physical machine or Virtual machine. The configuration file shoul be like ifcfg-XXXX (eg: ifcfg-eth0, ifcfg-eth1, ifcfg-enp0s3 etc)

sudo vim /etc/sysconfig/network-scripts/ifcfg-enp0s3

Use the following configuration to configure a static IP address for your CentOS 8 network interface.

Static IP Configuration:

TYPE=Ethernet
BOOTPROTO=static
NAME=enp0s3
DEVICE=enp0s3
ONBOOT=yes
IPADDR=192.168.1.237
PREFIX=24
GATEWAY=192.168.1.2
DNS1=8.8.8.8
DNS2=192.168.1.2
USRCTL=no

Alternatively, if you want to assign IP address via the DHCP server use the following settings.

DHCP Configuration

TYPE = Ethernet
DEVICE = enp0s3
BOOTPROTO = dhcp
ONBOOT = yes

Details of configuration parameters:

  • DEVICE: Ethernet device name
  • BOOTPROTO: dhcp or static
  • ONBOOT: yes/no , it tells that interface will automatically up or not on boot.
  • Type: Type of interface.
  • USRCTL: yes/no , it tells that a non root user can bring this device up or down.

Save the configuration and restart the NetworkManager service using the following command.

sudo systemctl restart NetworkManager.service

All done.

Was this answer helpful?

Related Articles

How to Enable CSF Firewall Web UI

Step 1 – Install Required Perl Modules: CSF UI required some of Perl modules to be installed...

How to Install and Configure CSF Firewall on Linux

Step 1: Download CSF Source Archive Download latest CSF archive source code from its official...

How To Install mod_cloudflare for Apache on Ubuntu

Install mod_cloudflare for Apache First of all, enable the PPA of Cloudflare module to your...

How To Install Wine 4.0 on CentOS 8 & Fedora 30/29

Step 1 – Prerequisite First of all, become root user on your CentOS 8 system. Then continue to...

How to Install Fail2Ban on CentOS 8 & Fedora 30/29

Step 1 – Install Fail2ban on CentOS 8 First of all, install epel-release package to configure...