Linux

How to configure a static IP address on RHEL 8

[ad_1]

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:

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:

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:

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.

[ad_2]

Facebook Comments

Show More

Related Articles

Leave a Reply

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

Back to top button