July 19, 2022

RHEL 9.0 Configure Networking from the Command Line

Show

$ sudo nmcli device status 
DEVICE  TYPE      STATE      CONNECTION 
enp1s0  ethernet  connected  enp1s0     
lo      loopback  unmanaged  --       

$ sudo nmcli connection show 
NAME    UUID                                  TYPE      DEVICE 
enp1s0  05b0507e-85d1-330e-836f-40dec2d378c6  ethernet  enp1s0 

$ sudo nmcli connection show --active

$ sudo nmcli connection show enp1s0

Add Static IPv4 Connection

$ sudo nmcli connection add con-name enp1s0-stat ifname enp1s0 type ethernet ipv4.method manual ipv4.addresses 192.168.122.100/24 ipv4.gateway 192.168.122.1 ipv4.dns 192.168.122.1

$ sudo nmcli connection up enp1s0-stat

Add Dynamic IPv4 Connection

$ sudo nmcli connection add con-name enp1s0-dyn ifname enp1s0 type ethernet ipv4.method auto

$ sudo nmcli connection up enp1s0-dyn

Miscellaneous

Starting in Red Hat Enterprise Linux 8, ifcfg format configuration files and the /etc/sysconfig/network-scripts/ directory are deprecated. NetworkManager now uses an INI-style key file format, which is a key-value pair structure to organize properties. NetworkManager stores network profiles in the /etc/NetworkManager/system-connections/ directory. For compatibility with earlier versions, ifcfg format connections in the /etc/sysconfig/network-scripts/ directory are still recognized and loaded.

The /etc/NetworkManager/system-connections/ directory stores any changes with the nmcli con mod name command.

$ sudo man 5 NetworkManager.conf

$ sudo hostnamectl set-hostname host.example.com

$ sudo hostnamectl status

$ sudo nmcli connection mod ID +ipv4.dns IP

$ sudo cat /etc/resolv.conf

Modify the new connection so that it also uses the IP address 10.0.1.1/24.

$ sudo nmcli connection mod "lab" +ipv4.addresses 10.0.1.1/24

Configure the hosts file so that you can reference the 10.0.1.1 IP address with the private name.

$ sudo echo "10.0.1.1 private" >> /etc/hosts

No comments: