How to configure a static IP address on RHEL 8

I am a new sysadmin and RHEL 8 user. My system is configured to use DHCP. How can I switch from DHCP to a static IP address on RHEL 8 system? How do I setup a static TCP/IP address on my Red Hat Enterprise Linux 8 server using command line option?

Introduction: Network scripts deprecated in RHEL 8. You need to use NetworkManager via the nmcli command. The default RHEL 8 comes with a new version of the ifup and ifdown scripts which calls nmcli. The procedure to configure a static IP address on RHEL 8:
  1. Create a file named /etc/sysconfig/network-scripts/ifcfg-eth0 as follows:
  2. DEVICE=eth0
  3. BOOTPROTO=none
  4. ONBOOT=yes
  5. PREFIX=24
  6. IPADDR=
  7. Restart network service on RHEL 8: systemctl restart NetworkManager OR sudo nmcli connection reload

Let us see all commands in details.

How do I start / stop / restart NetworkManager?

sudo systemctl start NetworkManager
sudo systemctl stop NetworkManager
sudo systemctl restart NetworkManager
systemctl status NetworkManager

How do I list network interfaces in RHEL 8?

One can use ip command as follows:
$ ip a show
Sample outputs:

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 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:ef:59:b8 brd ff:ff:ff:ff:ff:ff
    inet brd scope global dynamic noprefixroute ens3
       valid_lft 2275sec preferred_lft 2275sec
    inet6 fe80::5054:ff:feef:59b8/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Another option is to run:
$ nmcli device status
$ nmcli device show ens3

To see the NetworkManager connections, run:
$ nmcli connection
Here is a typical DHCP configration for ens3 (stored in /etc/sysconfig/network-scripts/ifcfg-ens3 file):
$ cat /etc/sysconfig/network-scripts/ifcfg-ens3
Sample outputs:

# Generated by dracut initrd

How do I configure an ens3 interface with static network settings (method # 1)?

One can run the following nmcli commands. Let us set static IPv4 IP address to
sudo nmcli con mod ens3 ipv4.addresses
sudo nmcli con mod ens3 ipv4.gateway
sudo nmcli con mod ens3 ipv4.method manual
sudo nmcli con mod ens3 ipv4.dns ""
sudo nmcli con up ens3

Viewing updated config file

Just run the following cat command:
$ cat /etc/sysconfig/network-scripts/ifcfg-ens3
Sample outputs:

# Generated by dracut initrd

If you edit /etc/sysconfig/network-scripts/ifcfg-ens3 file using a text editor, you must reload changes using any one of the following command:
$ sudo nmcli connection reload ## reload all connections ##
$ sudo nmcli con load /etc/sysconfig/network-scripts/ifcfg-ens3 ## reload only ens3 by config file ##
$ sudo nmcli con up ens3 ## reload by connection name

Verify connectivity with ping command and host command/dig command:
$ ip r
$ ip a show ens3
$ ping -c4
$ host

How do I configure an ens3 interface with static network settings using nmtui on Red Hat Enterprise Linux 8 (method # 2)?

One can use the nmtui command. It is a curses based TUI application for interacting with NetworkManager. To show a connection editor that supports adding, modifying, viewing and deleting connections. To view or setup a static IP using this tool for ens0, enter:
$ sudo nmtui
$ sudo nmtui edit ens3


With RHEl 8 you must use NetworkManager tools and applications to configure networking. nmcli is a command-line tool which enables users and scripts to interact with NetworkManager. It must be used on servers where GUI not installed by default. Another option for server users is to use TUI tool called nmtui.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum