Configure Networking in Red Hat Enterprise Linux

Red Hat Enterprise LinuxBeginner
Practice Now

Introduction

In this lab, you will gain hands-on experience configuring network interfaces and hostname settings on a Red Hat Enterprise Linux system. You will learn essential command-line tools and techniques to manage your system's network connectivity and identification.

Throughout this lab, you will validate existing network interface status and IP addresses, add new network connections with static IP configurations, and practice activating and deactivating these connections. Furthermore, you will modify existing network settings, configure the system's hostname and name resolution, and finally, test network connectivity and name resolution to ensure all configurations are working as expected.

Validate Network Interface Status and IP Addresses

In this step, you will learn how to validate the network interface status and IP addresses on your Red Hat Enterprise Linux system using command-line tools. Understanding your network configuration is crucial for troubleshooting connectivity issues and managing network services.

First, let's explore the ip link command, which lists all available network interfaces on your system. This command provides a high-level overview of your network adapters, including their state (UP/DOWN), MAC addresses, and MTU (Maximum Transmission Unit).

Open your terminal. You should see a prompt similar to [labex@host ~]$.

ip link show

You will see output similar to this, showing interfaces like lo (loopback), eth0 and eth1 (Ethernet interfaces with alternative names):

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:16:3e:0f:9e:4e brd ff:ff:ff:ff:ff:ff
    altname enp0s6
    altname ens6
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:16:3e:0f:9e:51 brd ff:ff:ff:ff:ff:ff
    altname enp0s7
    altname ens7

Note that your system has two Ethernet interfaces (eth0 and eth1) with alternative names (enp0s6/ens6 and enp0s7/ens7 respectively). The qdisc mq indicates a multi-queue network scheduler is being used for better performance.

Next, we will use the ip addr command to view detailed device and address information for a specific network interface. This command provides information about assigned IP addresses (IPv4 and IPv6), broadcast addresses, and subnet masks.

Let's check the details for your eth0 interface:

ip addr show eth0

The output will show the IP addresses assigned to eth0, including both IPv4 and IPv6 addresses if configured:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:16:3e:0f:9e:4e brd ff:ff:ff:ff:ff:ff
    altname enp0s6
    altname ens6
    inet 172.16.50.116/24 brd 172.16.50.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fe0f:9e4e/64 scope link
       valid_lft forever preferred_lft forever

Notice that eth0 has the IP address 172.16.50.116/24 with the noprefixroute flag, which indicates that NetworkManager is managing the routing for this interface.

The ip -s link show command can also show statistics about network performance, such as the number of bytes and packets transmitted and received, as well as any errors or dropped packets. This is useful for a quick check of network traffic.

ip -s link show eth0

You will see statistics for the eth0 interface:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:16:3e:0f:9e:4e brd ff:ff:ff:ff:ff:ff
    RX:  bytes packets errors dropped  missed   mcast
         90512     884      0       0       0       0
    TX:  bytes packets errors dropped carrier collsns
       1430185    1069      0       0       0       0
    altname enp0s6
    altname ens6

Finally, let's verify the routing table using the ip route command. The routing table determines how network traffic is directed to its destination.

ip route

This command will display the IPv4 routing table, showing default routes and routes for specific networks. Since you have two network interfaces, you'll see multiple routes:

default via 172.16.50.253 dev eth0 proto dhcp src 172.16.50.116 metric 100
default via 172.16.50.253 dev eth1 proto dhcp src 172.16.50.117 metric 200
172.16.50.0/24 dev eth0 proto kernel scope link src 172.16.50.116 metric 100
172.16.50.0/24 dev eth1 proto kernel scope link src 172.16.50.117 metric 200

Notice there are two default routes with different metrics (100 and 200), meaning eth0 has priority due to its lower metric value. Both interfaces are connected to the same network segment (172.16.50.0/24) and use the same gateway (172.16.50.253). The eth0 interface has IP address 172.16.50.116/24 and eth1 has 172.16.50.117/24.

To view the IPv6 routing table, use the ip -6 route command:

ip -6 route

You will see the IPv6 routing entries for both interfaces:

::1 dev lo proto kernel metric 256 pref medium
fe80::/64 dev eth0 proto kernel metric 256 pref medium
fe80::/64 dev eth1 proto kernel metric 256 pref medium

Add a New Network Connection with Static IP

In this step, you will learn how to add a new network connection with a static IP address using the nmcli command-line tool. nmcli is a powerful utility for controlling NetworkManager, which manages network connections on Red Hat Enterprise Linux.

First, let's check the current network device status to identify available interfaces. This will help us choose an interface to configure.

nmcli dev status

You will see output similar to this, showing devices like eth0 and eth1 with their respective connection names:

DEVICE  TYPE      STATE                   CONNECTION
eth0    ethernet  connected               System eth0
eth1    ethernet  connected               System eth1
lo      loopback  connected (externally)  lo

For this lab, we will use the eth0 interface to create a new static connection. Note that your system already has active connections named System eth0 and System eth1 that are auto-generated by NetworkManager.

Now, let's add a new network connection named static-eth0 to the eth0 interface. We will configure it with a static IPv4 address, a subnet mask, and a gateway. Based on the current network environment (172.16.50.0/24), we will use the following details:

  • Connection Name: static-eth0
  • Interface Name: eth0
  • IPv4 Address: 172.16.50.200/24 (This means IP address 172.16.50.200 with a 24-bit subnet mask)
  • Gateway: 172.16.50.253 (Same as the current gateway)

Execute the following command to add the new connection. Remember to use sudo as network configuration changes require root privileges. You will not be prompted for a password.

Note: If you already created a static-eth0 connection with a different IP range (like 192.168.1.10/24), you should first delete it and recreate it with the correct IP range for this environment:

## Delete the existing connection if it exists with wrong IP range
sudo nmcli con delete static-eth0
## Add the new connection with correct IP range
sudo nmcli con add con-name static-eth0 type ethernet ifname eth0 ipv4.addresses 172.16.50.200/24 ipv4.gateway 172.16.50.253 ipv4.method manual

After executing the command, you should see a confirmation message indicating that the connection was successfully added:

Connection 'static-eth0' (d4c42169-4134-4d3a-9b31-e837d62601bd) successfully added.

Let's break down the command:

  • sudo nmcli con add: This is the base command to add a new NetworkManager connection.
  • con-name static-eth0: This assigns the name static-eth0 to our new connection profile.
  • type ethernet: Specifies that this is an Ethernet type connection.
  • ifname eth0: Binds this connection profile to the eth0 network interface.
  • ipv4.addresses 172.16.50.200/24: Sets the static IPv4 address and subnet mask.
  • ipv4.gateway 172.16.50.253: Sets the default gateway for this connection.
  • ipv4.method manual: Configures the IPv4 address assignment method to manual (static), preventing it from trying to obtain an IP address via DHCP.

Now, let's verify that the new connection profile has been created. We can use nmcli con show to list all available connections.

nmcli con show

You should see static-eth0 listed among your connections. Note that it is not active yet (no device assigned), while the system-generated connections are active:

NAME         UUID                                  TYPE      DEVICE
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0
System eth1  9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1
lo           9eac3150-dd39-47e6-a375-f7165442a8eb  loopback  lo
static-eth0  d4c42169-4134-4d3a-9b31-e837d62601bd  ethernet  --

In the next step, we will learn how to activate this newly created connection.

Activate and Deactivate Network Connections

In this step, you will learn how to activate and deactivate network connections using the nmcli command. Activating a connection brings the network interface up and applies the configuration defined in the connection profile. Deactivating a connection takes the interface down.

First, let's list all network connections to see their current status. This will help us identify which connection is active on eth0.

nmcli con show

You will see output similar to this. Notice that System eth0 is currently active on eth0, and static-eth0 is not active:

NAME         UUID                                  TYPE      DEVICE
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0
System eth1  9c92fad9-6ecb-3e6c-eb4d-8a47c6f50c04  ethernet  eth1
lo           8fe3e894-2a2e-446f-9abc-cdf612f0d973  loopback  lo
static-eth0  66094d3b-f21a-44f9-b1ef-3b2b2659e487  ethernet  --

Now, let's activate the static-eth0 connection that you created in the previous step.

Important Note: Since we're working in a remote environment, activating a connection with a different IP address on the primary interface (eth0) may cause your remote connection to be interrupted. In a production environment, you would typically:

  1. Use a secondary interface for testing
  2. Have console access to the machine
  3. Configure the connection to use the same IP range as your current connection

For this lab, we'll use eth1 instead of eth0 to avoid connection interruption. Let's first create a static connection for eth1:

sudo nmcli con add con-name static-eth1 type ethernet ifname eth1 ipv4.addresses 172.16.50.201/24 ipv4.gateway 172.16.50.253 ipv4.method manual

Now activate the static-eth1 connection:

sudo nmcli con up static-eth1

You should see a confirmation message indicating that the connection was successfully activated:

Connection 'static-eth1' successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/X)

After activating static-eth1, the original System eth1 connection will automatically deactivate since only one connection can be active per device. Let's verify the status of your network devices and connections again.

nmcli dev status

You should now see eth1 associated with the static-eth1 connection, while eth0 remains with its original connection:

DEVICE  TYPE      STATE      CONNECTION
eth0    ethernet  connected  System eth0
eth1    ethernet  connected  static-eth1
lo      loopback  connected  lo

And let's check the connection list again to confirm static-eth1 is active:

nmcli con show --active

You should see static-eth1 listed as an active connection, along with the other active connections:

NAME         UUID                                  TYPE      DEVICE
System eth0  5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03  ethernet  eth0
lo           9eac3150-dd39-47e6-a375-f7165442a8eb  loopback  lo
static-eth1  xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  ethernet  eth1

Now, let's verify that the eth1 interface has the static IP address you configured.

ip addr show eth1

The output should now show 172.16.50.201/24 as the IPv4 address for eth1:

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:16:3e:0f:9e:51 brd ff:ff:ff:ff:ff:ff
    altname enp0s7
    altname ens7
    inet 172.16.50.201/24 brd 172.16.50.255 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fe0f:9e51/64 scope link
       valid_lft forever preferred_lft forever

Finally, let's learn how to deactivate a network connection. You can disconnect a device, which will bring down the active connection on that device.

sudo nmcli dev disconnect eth1

You should see a confirmation message:

Device 'eth1' successfully disconnected.

Verify the device status again. eth1 should now be in a disconnected state.

nmcli dev status
DEVICE  TYPE      STATE         CONNECTION
eth0    ethernet  connected     System eth0
eth1    ethernet  disconnected  --
lo      loopback  connected     lo

Note that disconnecting the device will also deactivate the connection that was previously active on it. If you want to bring the original System eth1 connection back up, you would activate it again using sudo nmcli con up "System eth1" (note the quotes around the connection name due to the space). For this lab, we will leave eth1 disconnected for now.

Modify Existing Network Connection Settings

In this step, you will learn how to modify the settings of an existing network connection using the nmcli command. This is a common task when you need to update IP addresses, DNS servers, or other network parameters.

First, let's ensure our static-eth1 connection is active, as we will be modifying its settings. If it's not active, activate it now.

sudo nmcli con up static-eth1

You should see a confirmation message if it was activated, or a message indicating it's already active.

Connection 'static-eth1' successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/X)

Now, let's view the current settings for the static-eth1 connection. This command will show all configured properties for the connection.

nmcli con show static-eth1

You will see a detailed output of the connection's properties. Pay attention to the ipv4.addresses and ipv4.gateway lines.

connection.id:                          static-eth1
connection.uuid:                        xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
connection.interface-name:              eth1
...
ipv4.addresses:                         { ip = 172.16.50.201/24, gw = 172.16.50.253 }
ipv4.gateway:                           172.16.50.253
...

Let's modify the IPv4 address of static-eth1 to 172.16.50.221/24 and keep the same gateway 172.16.50.253.

sudo nmcli con mod static-eth1 ipv4.addresses 172.16.50.221/24 ipv4.gateway 172.16.50.253

This command will modify the connection profile. However, for the changes to take effect, you need to deactivate and then reactivate the connection.

First, deactivate the eth1 device:

sudo nmcli dev disconnect eth1

You should see:

Device 'eth1' successfully disconnected.

Then, reactivate the static-eth1 connection:

sudo nmcli con up static-eth1

You should see:

Connection 'static-eth1' successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/X)

Now, let's verify that the IP address and gateway have been updated.

ip addr show eth1

The output should now reflect the new IP address 172.16.50.221/24. Note that you may also see a secondary IP address from the previous configuration:

3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:16:3e:0f:a2:70 brd ff:ff:ff:ff:ff:ff
    altname enp0s7
    altname ens7
    inet 172.16.50.221/24 brd 172.16.50.255 scope global noprefixroute eth1
       valid_lft forever preferred_lft forever
    inet 172.16.50.122/24 brd 172.16.50.255 scope global secondary noprefixroute eth1
       valid_lft forever preferred_lft forever

And check the routing table to confirm the gateway:

ip route

You should see routes for both interfaces, with eth1 having the new IP address. Note that you may see additional routes if there are secondary IP addresses:

default via 172.16.50.253 dev eth0 proto dhcp src 172.16.50.121 metric 100
default via 172.16.50.253 dev eth1 proto static metric 101
172.16.50.0/24 dev eth0 proto kernel scope link src 172.16.50.121 metric 100
172.16.50.0/24 dev eth1 proto kernel scope link src 172.16.50.221 metric 101
172.16.50.0/24 dev eth1 proto kernel scope link src 172.16.50.122 metric 101

You can also add or remove specific values from multi-valued settings, like DNS servers. Let's add a DNS server 8.8.8.8 to our static-eth1 connection.

sudo nmcli con mod static-eth1 +ipv4.dns 8.8.8.8

To apply this change, you need to deactivate and reactivate the connection again. You can run these commands on separate lines or combine them:

sudo nmcli dev disconnect eth1
sudo nmcli con up static-eth1

Verify the DNS settings:

nmcli con show static-eth1 | grep ipv4.dns

You should see 8.8.8.8 listed as a DNS server:

ipv4.dns:                               8.8.8.8

Configure System Hostname and Name Resolution

In this step, you will learn how to configure your system's hostname and manage name resolution settings. The hostname is a unique name that identifies your system on a network, and name resolution is the process of translating hostnames into IP addresses and vice versa.

First, let's check the current hostname of your system using the hostname command.

hostname

You will see the current hostname, which might be a default value like host or localhost.localdomain.

host

To set a static hostname, we use the hostnamectl command. This command modifies the /etc/hostname file, which persists the hostname across reboots. Let's set the hostname to server.labex.example.com.

sudo hostnamectl set-hostname server.labex.example.com

After setting the hostname, you can verify it using hostnamectl status.

hostnamectl status

You should see the new static hostname listed:

 Static hostname: server.labex.example.com
       Icon name: computer-vm
         Chassis: vm 🖴
      Machine ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
         Boot ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  Virtualization: kvm
Operating System: Red Hat Enterprise Linux 9.6 (Plow)
     CPE OS Name: cpe:/o:redhat:enterprise_linux:9::baseos
          Kernel: Linux 5.14.0-xxx.el9.x86_64
    Architecture: x86-64
 Hardware Vendor: Alibaba Cloud
  Hardware Model: Alibaba Cloud ECS

You can also directly check the content of the /etc/hostname file:

cat /etc/hostname

This will show your new hostname:

server.labex.example.com

Next, let's configure name resolution. Linux systems typically use the /etc/hosts file for local hostname-to-IP address mappings before querying DNS servers. Let's add an entry to /etc/hosts for a fictitious server webserver.labex.example.com with IP address 192.168.1.100.

We will use sudo nano to edit the /etc/hosts file.

sudo nano /etc/hosts

Add the following line at the end of the file:

192.168.1.100   webserver.labex.example.com

Press Ctrl+X, then Y to save, and Enter to confirm the filename.

Now, let's verify that the entry is present in /etc/hosts:

cat /etc/hosts

You should see your added entry:

127.0.0.1       localhost localhost.localdomain localhost4 localhost4.localdomain4
::1             localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.100   webserver.labex.example.com

To test hostname resolution using the /etc/hosts file, you can use the getent hosts command. This command queries the Name Service Switch (NSS) configuration, which includes /etc/hosts.

getent hosts webserver.labex.example.com

You should see the IP address resolved from your /etc/hosts file:

192.168.1.100   webserver.labex.example.com

Finally, let's look at the /etc/resolv.conf file, which controls how DNS queries are performed. NetworkManager typically manages this file. In the previous step, you added 8.8.8.8 as a DNS server to your static-eth1 connection. Let's verify that it appears in /etc/resolv.conf.

cat /etc/resolv.conf

You should see nameserver 8.8.8.8 listed along with other system nameservers:

## Generated by NetworkManager
search labex.example.com
nameserver 100.100.2.136
nameserver 100.100.2.138
nameserver 8.8.8.8

Note: The search directive and system nameservers may vary based on your environment. The important thing is that 8.8.8.8 appears in the list.

Test Network Connectivity and Name Resolution

In this final step, you will test network connectivity and name resolution using various command-line tools. This will help you confirm that your network configurations are working as expected.

First, let's use the ping command to test basic network connectivity to a known IP address. We will ping the gateway 172.16.50.253 that we configured in the previous step. The -c3 option sends only 3 packets.

ping -c3 172.16.50.253

You should see successful replies, indicating connectivity to your gateway:

PING 172.16.50.253 (172.16.50.253) 56(84) bytes of data.
64 bytes from 172.16.50.253: icmp_seq=1 ttl=64 time=0.052 ms
64 bytes from 172.16.50.253: icmp_seq=2 ttl=64 time=0.049 ms
64 bytes from 172.16.50.253: icmp_seq=3 ttl=64 time=0.045 ms

--- 172.16.50.253 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.045/0.049/0.052/0.003 ms

Note: You can interrupt the ping command at any time by pressing Ctrl+C if needed.

Next, let's test name resolution for the webserver.labex.example.com entry you added to /etc/hosts. We'll use getent hosts again, as it consults /etc/hosts first.

getent hosts webserver.labex.example.com

You should see the IP address 192.168.1.100 returned:

192.168.1.100   webserver.labex.example.com

Now, let's test DNS resolution for an external hostname, like google.com, using the host command. This command queries your configured DNS servers (which should include 8.8.8.8 from your static-eth0 connection).

host google.com

You should see the IP addresses for google.com:

google.com has address 142.251.46.174
google.com has IPv6 address 2607:f8b0:4005:802::200e
google.com mail is handled by 10 smtp.google.com.

The dig command is another powerful tool for querying DNS name servers. It provides more detailed information about the DNS query.

dig google.com

You will see a more verbose output, including the DNS server that responded and the query details:

; <<>> DiG 9.16.23-RH <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 21983
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             1       IN      A       142.251.46.174

;; Query time: 1 msec
;; SERVER: 100.100.2.136#53(100.100.2.136)
;; WHEN: Mon Jun 16 10:18:26 CST 2025
;; MSG SIZE  rcvd: 44

Finally, let's use the ss command to display socket statistics and confirm active network connections. We'll use -t for TCP sockets and -a for all (listening and established) sockets.

ss -ta

You will see a list of TCP connections and listening ports on your system:

State                                Recv-Q                                Send-Q                                                               Local Address:Port                                                                      Peer Address:Port
LISTEN                               0                                     128                                                                        0.0.0.0:exlm-agent                                                                     0.0.0.0:*
LISTEN                               0                                     128                                                                        0.0.0.0:ssh                                                                            0.0.0.0:*
ESTAB                                0                                     0                                                                    172.16.50.121:exlm-agent                                                               172.16.50.251:36354
LISTEN                               0                                     128                                                                           [::]:ssh                                                                               [::]:*

This concludes the lab on managing networking. You have successfully validated network configurations, added and modified connections, configured hostname and name resolution, and tested connectivity.

Summary

In this lab, we gained practical experience in managing network interfaces and hostname configurations on a Red Hat Enterprise Linux system. We began by validating network interface status and IP addresses using ip link and ip addr commands, understanding how to interpret their output for network diagnostics.

Subsequently, we learned to add new network connections with static IP addresses, activate and deactivate these connections, and modify existing network settings, demonstrating proficiency in nmcli for network management. Finally, we configured the system hostname and name resolution, and verified network connectivity and name resolution, solidifying our understanding of essential Linux networking concepts.