How to configure static IP address in CentOS 8 / RHEL 8

Dynamic IP can be used in home system or Local Area Network (LAN) because they are only used internally.

It can be assigned through DHCP (Dynamic Network Configuration Protocol) by either your ISP or your router.

But, you should assign a static IP address to the Linux servers that are accessible through internet.

Also, large organizations use static IP to avoid network issues due to the unavailability of DHCP servers.

In this article, we’ll demonstrate how to assign or configure Static IP address on RHEL 7/8 and CentOS 7/8 Server’s.

Static IP address can be configured on Red Hat system using below two methods:

  • Using nmcli command
  • Using Network Scripts files (ifcfg-*)

Method-1: Configure a static IP address using nmcli command on CentOS 7/8 and RHEL 7/8

The nmcli is a command line tool, which is used for controlling NetworkManager and reporting network status. It is used to create, display, edit, delete, activate, and deactivate network connections.

Identifying interfaces

Before proceeding to configure a static IP address, use the ip command to identify all the available Ethernet interfaces on your system.

# ip a

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
     link/ether 08:00:27:97:13:2e brd ff:ff:ff:ff:ff:ff
     inet 192.168.1.4/24 brd 192.168.1.255 scope global dynamic noprefixroute enp0s3
        valid_lft forever preferred_lft forever
     inet6 fe80::a00:27ff:fe97:132e/64 scope link
        valid_lft forever preferred_lft forever

As we can see from the above output, We have an interface named "enp0s3", which has a dynamic IP.

To view detailed DHCP configuration of enp0s3, run:

# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3

NAME="enp0s3"
DEVICE="enp0s3"
ONBOOT="yes"
NETBOOT="yes"
UUID="3grf34s0-9045-4312-e12t-567v90lk0e9t"
IPV6INIT="yes"
BOOTPROTO="dhcp"
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"

Let’s assume we want to assign the static IP address for “enp0s3” with the following details:

IP address = 192.168.1.50
Netmask = 255.255.255.0
Gateway= 192.168.1.1
DNS = 8.8.8.8

Configuring IP address

To do so, run the below nmcli commands one by one to configure static ip:

To assign a IP address:

# nmcli con mod enp0s3 ipv4.addresses 192.168.1.50/24

To add a gateway:

# nmcli con mod enp0s3 ipv4.gateway 192.168.1.1

To configure a static IP, run: This will change the “BOOTPROTO=dhcp” to “BOOTPROTO=none”.

This parameter is used to set the protocol to be used at startup to set the IP address of the interface. The options are as follows:

  • none : No boot-time protocol should be used.
  • dhcp : The DHCP protocol should be used.
  • bootp : The BOOTP protocol should be used.
# nmcli con mod enp0s3 ipv4.method manual

To add DNS entry, run:

# nmcli con mod enp0s3 ipv4.dns "8.8.8.8"

To save these changes and to reload the interface, run:

# nmcli con up enp0s3

You have successfully configured the interface “enp0s3” with static IP. All the new configuration has been saved permanently to the file “etc/sysconfig/network-scripts/ifcfg-enp0s3”. To view the details, run:

# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3

NAME="enp0s3"
DEVICE="enp0s3"
ONBOOT="yes"
NETBOOT="yes"
UUID="3grf34s0-9045-4312-e12t-567v90lk0e9t"
IPV6INIT="yes"
BOOTPROTO="none"
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPADDR=192.168.1.50
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8

You can double confirm, if the new IP address is banded with the interface “enp0s3” by using ip command.

# ip a show enp0s3

2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000      
    link/ether 08:00:27:97:13:2e brd ff:ff:ff:ff:ff:ff      
    inet 192.168.1.50/24 brd 192.168.1.255 scope global noprefixroute enp0s3
       valid_lft forever preferred_lft forever      
    inet6 fe80::a00:27ff:fe97:132e/64 scope link         
       valid_lft forever preferred_lft forever

Method-2: Assign a static IP address by editing network scripts files on CentOS 7/8 and RHEL 7/8

For each network interface, a configuration file is created under the ‘/etc/sysconfig/network-scripts’ directory, which controls the interfaces for individual network devices.

When the system boots, it uses these files to determine what interfaces to bring up and how to configure them.

These files are named with the "ifcfg-" prefix and the name of the interface.

For instance, to configure a static IP address for “enp0s3” with the following details, see the below steps:

IP address = 192.168.1.70
Netmask = 255.255.255.0
Gateway= 192.168.1.1
DNS = 8.8.8.8
BOOTPROTO="none"

To do so, add or modify the above lines in the following configuration file.

# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

NAME="enp0s3"
DEVICE="enp0s3"
ONBOOT="yes"
NETBOOT="yes"
UUID="3grf34s0-9045-4312-e12t-567v90lk0e9t"
IPV6INIT="yes"
BOOTPROTO="none"
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPADDR=192.168.1.70
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8

Once you modified, run the below command to shut down the interface and bring it back:

# ifdown enp0s3 && ifup enp0s3

Check if the new configurations are populated by using ip command:

# ip a show enp0s3

2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000      
    link/ether 08:00:27:97:13:2e brd ff:ff:ff:ff:ff:ff      
    inet 192.168.1.70/24 brd 192.168.1.255 scope global noprefixroute enp0s3
       valid_lft forever preferred_lft forever      
    inet6 fe80::a00:27ff:fe97:132e/64 scope link         
       valid_lft forever preferred_lft forever

Closing Notes

In this guide, we’ve shown you how to configure a static IP in RHEL 7/8 and CentOS 7/8 using two different methods.

If you have any questions or feedback, feel free to comment below.

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

One Comment on “How to configure static IP address in CentOS 8 / RHEL 8”

Leave a Reply

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