...

How to configure a static IP address on RHEL 8 nixCraft

how-to-configure-a-static-ip-address-on-rhel-8-nixcraft

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=192.168.2.203
  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

Starting Stopping Restating NetworkManager on RHEL 8

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 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: 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 192.168.122.229/24 brd 192.168.122.255 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

RHEL 8 find out network interface names
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
NAME="ens3" DEVICE="ens3" ONBOOT="yes" NETBOOT="yes" UUID="6fdb13a0-1592-4992-a09e-632c23fb0d0f" 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"

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 192.168.122.20/24:
sudo nmcli con mod ens3 ipv4.addresses 192.168.122.20/24
sudo nmcli con mod ens3 ipv4.gateway 192.168.122.1
sudo nmcli con mod ens3 ipv4.method manual
sudo nmcli con mod ens3 ipv4.dns "192.168.2.254"
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
NAME=ens3 DEVICE=ens3 ONBOOT=yes NETBOOT="yes" UUID=6fdb13a0-1592-4992-a09e-632c23fb0d0f 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.122.20 PREFIX=24 GATEWAY=192.168.122.1 DNS1=192.168.2.254

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 mcli 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 192.168.2.254
$ host cyberciti.biz

Verify static IP config on RHEL 8

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

Static IP address on RHEL 8 config using nmtui command

Conclusion

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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Discover more from WIREDGORILLA

Subscribe now to keep reading and get access to the full archive.

Continue reading