Bookmark this page

Guided Exercise: Configure Networking from the Command Line

In this exercise, you use the nmcli command to configure network settings.

Outcomes

  • Update a network connection setting from DHCP to static.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

This command prepares your environment and ensures that all required resources are available.

[student@workstation ~]$ lab start net-configure

Instructions

  1. Use the ssh command to log in to the servera machine as the student user.

    [student@workstation ~]$ ssh student@servera
    ...output omitted...
    [student@servera ~]$ sudo -i
    [sudo] password for student: student
    [root@servera ~]#
  2. Display the network interface information.

    Important

    Network interface names are determined by their bus type and the detection order of devices during boot. Your network interface names might vary according to the course platform and hardware in use.

    On your system, locate the interface name (such as eth1, ens06, or enp0p2) that is associated with the Ethernet address 52:54:00:00:fa:0a. Use this interface name to replace the eth0 placeholder throughout this exercise if different.

    Locate the network interface name that is associated with the 52:54:00:00:fa:0a Ethernet address. Record or remember this name, and use it to replace the eth0 placeholder in subsequent commands.

    [root@servera ~]# ip link
    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 fq_codel state UP mode DEFAULT group default qlen 1000
        link/ether 52:54:00:00:fa:0a brd ff:ff:ff:ff:ff:ff
        altname enp0s3
        altname ens3
  3. Use the nmcli command to view network settings.

    1. Use the nmcli con show --active command to display only the active connections.

      Your network interface name should appear under the DEVICE column of the output, and the name of the active connection for that device is listed under the NAME column. This exercise assumes that the active connection is called Wired connection 1. If the name of the active connection is different, then use that name instead of Wired connection 1 for the rest of this exercise.

      [root@servera ~]# nmcli con show --active
      NAME                UUID                                  TYPE       DEVICE
      Wired connection 1  ec3a15fb-2e26-3254-9433-90c66981e924  ethernet  eth0
    2. Display all configuration settings for the active connection.

      [root@servera ~]# nmcli con show "Wired connection 1"
      connection.id:                          Wired connection 1
      connection.uuid:                        ec3a15fb-2e26-3254-9433-90c66981e924
      connection.stable-id:                   --
      connection.type:                        802-3-ethernet
      connection.interface-name:              eth0
      connection.autoconnect:                 yes
      ...output omitted...
      ipv4.method:                            manual
      ipv4.dns:                               172.25.250.220
      ipv4.dns-search:                        lab.example.com,example.com
      ipv4.dns-options:                       --
      ipv4.dns-priority:                      0
      ipv4.addresses:                         172.25.250.10/24
      ipv4.gateway:                           172.25.250.254
      ...output omitted...
      ipv6.method:                            auto
      ipv6.dns:                               --
      ipv6.dns-search:                        --
      ipv6.dns-options:                       --
      ipv6.dns-priority:                      0
      ipv6.addresses:                         --
      ipv6.gateway:                           --
      ipv6.routes:                            --
      ...output omitted...
      GENERAL.NAME:                           Wired connection 1
      GENERAL.UUID:                           ec3a15fb-2e26-3254-9433-90c66981e924
      GENERAL.DEVICES:                        eth0
      GENERAL.IP-IFACE:                       eth0
      GENERAL.STATE:                          activated
      GENERAL.DEFAULT:                        yes
      ...output omitted...
    3. Show the device status.

      [root@servera ~]# nmcli dev status
      DEVICE     TYPE         STATE         CONNECTION
      eth0       ethernet     connected     Wired connection 1
      lo         loopback     unmanaged     --
    4. Display the settings for the eth0 device.

      [root@servera ~]# nmcli dev show eth0
      GENERAL.DEVICE:                 eth0
      GENERAL.TYPE:                   ethernet
      GENERAL.HWADDR:                 52:54:00:00:FA:0A
      GENERAL.MTU:                    1500
      GENERAL.STATE:                  100 (connected)
      GENERAL.CONNECTION:             Wired connection 1
      GENERAL.CON-PATH:               /org/freedesktop/NetworkManager/ActiveConnection/1
      WIRED-PROPERTIES.CARRIER:       on
      IP4.ADDRESS[1]:                 172.25.250.10/24
      IP4.GATEWAY:                    172.25.250.254
      IP4.ROUTE[1]:                   dst = 172.25.250.0/24, nh = 0.0.0.0, mt = 100
      IP4.ROUTE[2]:                   dst = 0.0.0.0/0, nh = 172.25.250.254, mt = 100
      IP4.DNS[1]:                     172.25.250.220
      IP4.SEARCHES[1]:                lab.example.com
      IP4.SEARCHES[2]:                example.com
      IP6.ADDRESS[1]:                 fe80::c38a:ac39:36a1:a43c/64
      IP6.GATEWAY:                    --
      IP6.ROUTE[1]:                   dst = fe80::/64, nh = ::, mt = 1024
  4. Create a static connection with the same IPv4 address, network prefix, and default gateway as the active connection. Name the new connection static-addr.

    Warning

    Because access to your machine is provided over the primary network connection, setting incorrect values during network configuration might make your machine unreachable. If you machine is unreachable, then use the Reset button above what used to be your machine's graphical display and try again.

    [root@servera ~]# nmcli con add con-name static-addr \
    ifname eth0 type ethernet ipv4.method manual ipv4.dns 172.25.250.220 \
    ipv4.addresses 172.25.250.10/24 ipv4.gateway 172.25.250.254
    Connection 'static-addr' (dc519805-48c4-4b31-b9e9-d3631cf9082c) successfully added.
  5. Display and activate the new connection.

    1. View all connections.

      [root@servera ~]# nmcli con show
      NAME                UUID                                  TYPE      DEVICE
      Wired connection 1  ec3a15fb-2e26-3254-9433-90c66981e924  ethernet  eth0
      static-addr         dc519805-48c4-4b31-b9e9-d3631cf9082c  ethernet  --
    2. View the active connections.

      [root@servera ~]# nmcli con show --active
      NAME                UUID                                  TYPE      DEVICE
      Wired connection 1  ec3a15fb-2e26-3254-9433-90c66981e924  ethernet  eth0
    3. Activate the new static-addr connection.

      [root@servera ~]# nmcli con up static-addr
      Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
    4. Verify the new active connection.

      [root@servera ~]# nmcli con show --active
      NAME         UUID                                  TYPE      DEVICE
      static-addr  dc519805-48c4-4b31-b9e9-d3631cf9082c  ethernet  eth0
  6. Update the previous connection so that it does not start at boot. Verify that the static-addr connection is used when the system reboots.

    1. Disable the original connection so that it does not start automatically at boot.

      [root@servera ~]# nmcli con mod "Wired connection 1" \
      connection.autoconnect no
    2. Reboot the system.

      [root@servera ~]# systemctl reboot
      Connection to servera closed by remote host.
      Connection to servera closed.
      [student@workstation ~]$
    3. Log in to the servera machine and verify that the static-addr connection is the active connection.

      [student@workstation ~]$ ssh student@servera
      ...output omitted...
      [student@servera ~]$ nmcli con show --active
      NAME         UUID                                  TYPE      DEVICE
      static-addr  dc519805-48c4-4b31-b9e9-d3631cf9082c  ethernet  eth0
  7. Test connectivity by using the new network addresses.

    1. Verify the IP address.

      [student@servera ~]$ ip -br addr show eth0
      eth0             UP             172.25.250.10/24 fe80::eb21:9a:24de:e8fe/64
    2. Verify the default gateway.

      [student@servera ~]$ ip route
      default via 172.25.250.254 dev eth0 proto static metric 100
      172.25.250.0/24 dev eth0 proto kernel scope link src 172.25.250.10 metric 100
    3. Ping the DNS address.

      [student@servera ~]$ ping -c3 172.25.250.220
      PING 172.25.250.220 (172.25.250.220) 56(84) bytes of data.
      64 bytes from 172.25.250.220: icmp_seq=1 ttl=64 time=0.777 ms
      64 bytes from 172.25.250.220: icmp_seq=2 ttl=64 time=0.431 ms
      64 bytes from 172.25.250.220: icmp_seq=3 ttl=64 time=0.272 ms
      
      --- 172.25.250.220 ping statistics ---
      3 packets transmitted, 3 received, 0% packet loss, time 2045ms
      rtt min/avg/max/mdev = 0.272/0.493/0.777/0.210 ms
    4. Return to the workstation system as the student user.

      [student@servera ~]$ exit
      logout
      Connection to servera closed.
      [student@workstation ~]$

Finish

On the workstation machine, change to the student user home directory and use the lab command to complete this exercise. This step is important to ensure that resources from previous exercises do not impact upcoming exercises.

[student@workstation ~]$ lab finish net-configure

This concludes the section.

Revision: rh124-9.0-398f302