How to configure a static IP address on RHEL 8

ADVERTISEMENTS



Create a file named /etc/sysconfig/network-scripts/ifcfg-eth0 as follows: DEVICE=eth0 BOOTPROTO=none ONBOOT=yes PREFIX=24 IPADDR=192.168.2.203 Restart network service on RHEL 8: systemctl restart NetworkManager OR sudo nmcli connection reload

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:

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



$ nmcli connection

$ cat /etc/sysconfig/network-scripts/ifcfg-ens3

# 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" # 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 )?

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

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 # 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 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 192.168.2.254

$ host cyberciti.biz



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



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.