How To Configure a Static IP on RHEL 8

[root@atiq ~]# nmcli connection show NAME UUID TYPE DEVICE ens160 e7d8560a-4538-406f-b3d2-c03a4996f6c1 ethernet ens160
[root@atiq ~]# nmcli connection modify ens160 ipv4.addresses 192.168.191.39/24 ipv4.gateway 192.168.191.1 ipv4.dns 8.8.8.8 ipv4.method manual connection.autoconnect yes
[root@atiq ~]# nmcli connection up ens160

 

Nmcli is a NetworkManager command line interface that can be used for obtaining information or configuring a network interface.

How to Configure Static IP Address Using Nmcli Tool

If you want to set a static IP address, you can use the following options:

Set the IPv4 address for interface enp0s3 on RHEL 8.

# nmcli con mod enp0s3 ipv4.addresses 192.168.20.170/24

Set the gateway IP:

# nmcli con mod enp0s3 ipv4.gateway 192.168.20.1

Inform the interface that it is using manual configuration (not DHCP etc.).

# nmcli con mod enp0s3 ipv4.method manual

Set the DNS Server IP:

# nmcli con mod enp0s3 ipv4.dns "8.8.8.8"

Reload the interface configuration:

# nmcli con up enp0s3 

Your changes will be saved in /etc/sysconfig/network-scripts/ifcfg-.

Here is the configuration file that has been generated for me:

# cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
ifcfg-enp0s3 Configuration
TYPE="Ethernet"
BOOTPROTO="none"
NAME="enp0s3"
IPADDR="192.168.20.170"
NETMASK="255.255.255.0"
GATEWAY="192.168.20.1"
DEVICE="enp0s3"
ONBOOT="yes"
PROXY_METHOD="none"
BROWSER_ONLY="no"
PREFIX="24"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="no"
UUID="3c36b8c2-334b-57c7-91b6-4401f3489c69"