Chapter 2. Configuring an Ethernet connection

Red Hat Enterprise Linux provides administrators different options to configure Ethernet connections. For example:

  • Use nmcli to configure connections on the command line.
  • Use nmtui to configure connections in a text-based user interface.
  • Use RHEL System Roles to automate the configuration of connections on one or multiple hosts.
  • Use the GNOME Settings menu or nm-connection-editor application to configure connections in a graphical interface.
  • Use nmstatectl to configure connections through the Nmstate API.
Note

If you want to manually configure Ethernet connections on hosts running in the Microsoft Azure cloud, disable the cloud-init service or configure it to ignore the network settings retrieved from the cloud environment. Otherwise, cloud-init will override on the next reboot the network settings that you have manually configured.

2.1. Configuring an Ethernet connection with a static IP address by using nmcli

To configure an Ethernet connection on the command line, use the nmcli utility.

For example, the procedure below creates a NetworkManager connection profile for the enp7s0 device with the following settings:

  • A static IPv4 address - 192.0.2.1 with a /24 subnet mask
  • A static IPv6 address - 2001:db8:1::1 with a /64 subnet mask
  • An IPv4 default gateway - 192.0.2.254
  • An IPv6 default gateway - 2001:db8:1::fffe
  • An IPv4 DNS server - 192.0.2.200
  • An IPv6 DNS server - 2001:db8:1::ffbb
  • A DNS search domain - example.com

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.

Procedure

  1. Add a new NetworkManager connection profile for the Ethernet connection:

    # nmcli connection add con-name Example-Connection ifname enp7s0 type ethernet

    The further steps modify the Example-Connection connection profile you created.

  2. Set the IPv4 address:

    # nmcli connection modify Example-Connection ipv4.addresses 192.0.2.1/24
  3. Set the IPv6 address:

    # nmcli connection modify Example-Connection ipv6.addresses 2001:db8:1::1/64
  4. Set the IPv4 and IPv6 connection method to manual:

    # nmcli connection modify Example-Connection ipv4.method manual
    # nmcli connection modify Example-Connection ipv6.method manual
  5. Set the IPv4 and IPv6 default gateways:

    # nmcli connection modify Example-Connection ipv4.gateway 192.0.2.254
    # nmcli connection modify Example-Connection ipv6.gateway 2001:db8:1::fffe
  6. Set the IPv4 and IPv6 DNS server addresses:

    # nmcli connection modify Example-Connection ipv4.dns "192.0.2.200"
    # nmcli connection modify Example-Connection ipv6.dns "2001:db8:1::ffbb"

    To set multiple DNS servers, specify them space-separated and enclosed in quotes.

  7. Set the DNS search domain for the IPv4 and IPv6 connection:

    # nmcli connection modify Example-Connection ipv4.dns-search example.com
    # nmcli connection modify Example-Connection ipv6.dns-search example.com
  8. Activate the connection profile:

    # nmcli connection up Example-Connection
    Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  Example-Connection
  2. Use the ping utility to verify that this host can send packets to other hosts:

    # ping host_name_or_IP_address

Troubleshooting

  • Verify that the network cable is plugged-in to the host and a switch.
  • Check whether the link failure exists only on this host or also on other hosts connected to the same switch.
  • Verify that the network cable and the network interface are working as expected. Perform hardware diagnosis steps and replace defect cables and network interface cards.
  • If the configuration on the disk does not match the configuration on the device, starting or restarting NetworkManager creates an in-memory connection that reflects the configuration of the device. For further details and how to avoid this problem, see NetworkManager duplicates a connection after restart of NetworkManager service.

Additional resources

2.2. Configuring an Ethernet connection with a static IP address by using the nmcli interactive editor

You can configure an Ethernet connection on the command line using the interactive mode of the nmcli utility.

For example, the procedure below creates a NetworkManager connection profile for the enp7s0 device with the following settings:

  • A static IPv4 address - 192.0.2.1 with a /24 subnet mask
  • A static IPv6 address - 2001:db8:1::1 with a /64 subnet mask
  • An IPv4 default gateway - 192.0.2.254
  • An IPv6 default gateway - 2001:db8:1::fffe
  • An IPv4 DNS server - 192.0.2.200
  • An IPv6 DNS server - 2001:db8:1::ffbb
  • A DNS search domain - example.com

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.

Procedure

  1. To add a new NetworkManager connection profile for the Ethernet connection, and starting the interactive mode, enter:

    # nmcli connection edit type ethernet con-name Example-Connection
  2. Set the network interface:

    nmcli> set connection.interface-name enp7s0
  3. Set the IPv4 address:

    nmcli> set ipv4.addresses 192.0.2.1/24
  4. Set the IPv6 address:

    nmcli> set ipv6.addresses 2001:db8:1::1/64
  5. Set the IPv4 and IPv6 connection method to manual:

    nmcli> set ipv4.method manual
    nmcli> set ipv6.method manual
  6. Set the IPv4 and IPv6 default gateways:

    nmcli> set ipv4.gateway 192.0.2.254
    nmcli> set ipv6.gateway 2001:db8:1::fffe
  7. Set the IPv4 and IPv6 DNS server addresses:

    nmcli> set ipv4.dns 192.0.2.200
    nmcli> set ipv6.dns 2001:db8:1::ffbb

    To set multiple DNS servers, specify them space-separated and enclosed in quotation marks.

  8. Set the DNS search domain for the IPv4 and IPv6 connection:

    nmcli> set ipv4.dns-search example.com
    nmcli> set ipv6.dns-search example.com
  9. Save and activate the connection:

    nmcli> save persistent
    Saving the connection with 'autoconnect=yes'. That might result in an immediate activation of the connection.
    Do you still want to save? (yes/no) [yes] yes
  10. Leave the interactive mode:

    nmcli> quit

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  Example-Connection
  2. Use the ping utility to verify that this host can send packets to other hosts:

    # ping host_name_or_IP_address

Troubleshooting

  • Verify that the network cable is plugged-in to the host and a switch.
  • Check whether the link failure exists only on this host or also on other hosts connected to the same switch.
  • Verify that the network cable and the network interface are working as expected. Perform hardware diagnosis steps and replace defect cables and network interface cards.
  • If the configuration on the disk does not match the configuration on the device, starting or restarting NetworkManager creates an in-memory connection that reflects the configuration of the device. For further details and how to avoid this problem, see NetworkManager duplicates a connection after restart of NetworkManager service.

Additional resources

2.3. Configuring an Ethernet connection with a static IP address by using nmtui

The nmtui application provides a text-based user interface for NetworkManager. You can use nmtui to configure an Ethernet connection with a static IP address on a host without a graphical interface.

Note

In nmtui:

  • Navigate by using the cursor keys.
  • Press a button by selecting it and hitting Enter.
  • Select and deselect checkboxes by using Space.

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.

Procedure

  1. If you do not know the network device name you want to use in the connection, display the available devices:

    # nmcli device status
    DEVICE     TYPE      STATE                   CONNECTION
    enp7s0     ethernet  unavailable             --
    ...
  2. Start nmtui:

    # nmtui
  3. Select Edit a connection, and press Enter.
  4. Press the Add button.
  5. Select Ethernet from the list of network types, and press Enter.
  6. Optional: Enter a name for the NetworkManager profile to be created.
  7. Enter the network device name into the Device field.
  8. Configure the IPv4 and IPv6 address settings in the IPv4 configuration and IPv6 configuration areas:

    1. Press the Automatic button, and select Manual from the displayed list.
    2. Press the Show button next to the protocol you want to configure to display additional fields.
    3. Press the Add button next to Addresses, and enter the IP address and the subnet mask in Classless Inter-Domain Routing (CIDR) format.

      If you do not specify a subnet mask, NetworkManager sets a /32 subnet mask for IPv4 addresses and /64 for IPv6 addresses.

    4. Enter the address of the default gateway.
    5. Press the Add button next to DNS servers, and enter the DNS server address.
    6. Press the Add button next to Search domains, and enter the DNS search domain.

    Figure 2.1. Example of an Ethernet connection with static IP address settings

    nmtui ethernet static IP
  9. Press the OK button to create and automatically activate the new connection.
  10. Press the Back button to return to the main menu.
  11. Select Quit, and press Enter to close the nmtui application.

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  Example-Connection
  2. Use the ping utility to verify that this host can send packets to other hosts:

    # ping host_name_or_IP_address

Troubleshooting

  • Verify that the network cable is plugged-in to the host and a switch.
  • Check whether the link failure exists only on this host or also on other hosts connected to the same switch.
  • Verify that the network cable and the network interface are working as expected. Perform hardware diagnosis steps and replace defect cables and network interface cards.
  • If the configuration on the disk does not match the configuration on the device, starting or restarting NetworkManager creates an in-memory connection that reflects the configuration of the device. For further details and how to avoid this problem, see NetworkManager duplicates a connection after restart of NetworkManager service.

2.4. Configuring an Ethernet connection with a static IP address by using nmstatectl

To configure an Ethernet connection using the Nmstate API, use the nmstatectl utility.

For example, the procedure below creates a NetworkManager connection profile for the enp7s0 device with the following settings:

  • A static IPv4 address - 192.0.2.1 with the /24 subnet mask
  • A static IPv6 address - 2001:db8:1::1 with the /64 subnet mask
  • An IPv4 default gateway - 192.0.2.254
  • An IPv6 default gateway - 2001:db8:1::fffe
  • An IPv4 DNS server - 192.0.2.200
  • An IPv6 DNS server - 2001:db8:1::ffbb
  • A DNS search domain - example.com

The nmstatectl utility ensures that, after setting the configuration, the result matches the configuration file. If anything fails, nmstatectl automatically rolls back the changes to avoid leaving the system in an incorrect state.

The procedure defines the interface configuration in YAML format. Alternatively, you can also specify the configuration in JSON format.

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.
  • The nmstate package is installed.

Procedure

  1. Create a YAML file, for example ~/create-ethernet-profile.yml, with the following contents:

    ---
    interfaces:
    - name: enp7s0
      type: ethernet
      state: up
      ipv4:
        enabled: true
        address:
        - ip: 192.0.2.1
          prefix-length: 24
        dhcp: false
      ipv6:
        enabled: true
        address:
        - ip: 2001:db8:1::1
          prefix-length: 64
        autoconf: false
        dhcp: false
    routes:
      config:
      - destination: 0.0.0.0/0
        next-hop-address: 192.0.2.254
        next-hop-interface: enp7s0
      - destination: ::/0
        next-hop-address: 2001:db8:1::fffe
        next-hop-interface: enp7s0
    dns-resolver:
      config:
        search:
        - example.com
        server:
        - 192.0.2.200
        - 2001:db8:1::ffbb
  2. Apply the settings to the system:

    # nmstatectl apply ~/create-ethernet-profile.yml

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  enp7s0
  2. Display all settings of the connection profile:

    # nmcli connection show enp7s0
    connection.id:              enp7s0
    connection.uuid:            b6cdfa1c-e4ad-46e5-af8b-a75f06b79f76
    connection.stable-id:       --
    connection.type:            802-3-ethernet
    connection.interface-name:  enp7s0
    ...
  3. Display the connection settings in YAML format:

    # nmstatectl show enp7s0

Additional resources

  • nmstatectl(8) man page
  • /usr/share/doc/nmstate/examples/ directory

2.5. Configuring an Ethernet connection with a static IP address by using the network RHEL System Role with an interface name

You can remotely configure an Ethernet connection using the network RHEL System Role.

For example, the procedure below creates a NetworkManager connection profile for the enp7s0 device with the following settings:

  • A static IPv4 address - 192.0.2.1 with a /24 subnet mask
  • A static IPv6 address - 2001:db8:1::1 with a /64 subnet mask
  • An IPv4 default gateway - 192.0.2.254
  • An IPv6 default gateway - 2001:db8:1::fffe
  • An IPv4 DNS server - 192.0.2.200
  • An IPv6 DNS server - 2001:db8:1::ffbb
  • A DNS search domain - example.com

Perform this procedure on the Ansible control node.

Prerequisites

  • You have prepared the control node and the managed nodes
  • You are logged in to the control node as a user who can run playbooks on the managed nodes.
  • The account you use to connect to the managed nodes has sudo permissions on them.
  • The managed nodes or groups of managed nodes on which you want to run this playbook are listed in the Ansible inventory file.
  • A physical or virtual Ethernet device exists in the server’s configuration.
  • The managed nodes use NetworkManager to configure the network.

Procedure

  1. Create a playbook file, for example ~/ethernet-static-IP.yml, with the following content:

    ---
    - name: Configure the network
      hosts: managed-node-01.example.com
      tasks:
      - name: Configure an Ethernet connection with static IP
        include_role:
          name: rhel-system-roles.network
    
        vars:
          network_connections:
            - name: enp7s0
              interface_name: enp7s0
              type: ethernet
              autoconnect: yes
              ip:
                address:
                  - 192.0.2.1/24
                  - 2001:db8:1::1/64
                gateway4: 192.0.2.254
                gateway6: 2001:db8:1::fffe
                dns:
                  - 192.0.2.200
                  - 2001:db8:1::ffbb
                dns_search:
                  - example.com
              state: up
  2. Run the playbook:

    # ansible-playbook ~/ethernet-static-IP.yml

Additional resources

  • /usr/share/ansible/roles/rhel-system-roles.network/README.md file

2.6. Configuring an Ethernet connection with a static IP address by using the network RHEL System Role with a device path

You can remotely configure an Ethernet connection using the network RHEL System Role.

You can identify the device path with the following command:

# udevadm info /sys/class/net/<device_name> | grep ID_PATH=

For example, the procedure below creates a NetworkManager connection profile with the following settings for the device that matches the PCI ID 0000:00:0[1-3].0 expression, but not 0000:00:02.0:

  • A static IPv4 address - 192.0.2.1 with a /24 subnet mask
  • A static IPv6 address - 2001:db8:1::1 with a /64 subnet mask
  • An IPv4 default gateway - 192.0.2.254
  • An IPv6 default gateway - 2001:db8:1::fffe
  • An IPv4 DNS server - 192.0.2.200
  • An IPv6 DNS server - 2001:db8:1::ffbb
  • A DNS search domain - example.com

Perform this procedure on the Ansible control node.

Prerequisites

  • You have prepared the control node and the managed nodes
  • You are logged in to the control node as a user who can run playbooks on the managed nodes.
  • The account you use to connect to the managed nodes has sudo permissions on them.
  • The managed nodes or groups of managed nodes on which you want to run this playbook are listed in the Ansible inventory file.
  • A physical or virtual Ethernet device exists in the server’s configuration.
  • The managed nodes use NetworkManager to configure the network.

Procedure

  1. Create a playbook file, for example ~/ethernet-static-IP.yml, with the following content:

    ---
    - name: Configure the network
      hosts: managed-node-01.example.com
      tasks:
      - name: Configure an Ethernet connection with static IP
        include_role:
          name: rhel-system-roles.network
    
        vars:
          network_connections:
            - name: example
              match:
                path:
                  - pci-0000:00:0[1-3].0
                  - &!pci-0000:00:02.0
              type: ethernet
              autoconnect: yes
              ip:
                address:
                  - 192.0.2.1/24
                  - 2001:db8:1::1/64
                gateway4: 192.0.2.254
                gateway6: 2001:db8:1::fffe
                dns:
                  - 192.0.2.200
                  - 2001:db8:1::ffbb
                dns_search:
                  - example.com
              state: up

    The match parameter in this example defines that Ansible applies the play to devices that match PCI ID 0000:00:0[1-3].0, but not 0000:00:02.0. For further details about special modifiers and wild cards you can use, see the match parameter description in the /usr/share/ansible/roles/rhel-system-roles.network/README.md file.

  2. Run the playbook:

    # ansible-playbook ~/ethernet-static-IP.yml

Additional resources

  • /usr/share/ansible/roles/rhel-system-roles.network/README.md file

2.7. Configuring an Ethernet connection with a dynamic IP address by using nmcli

To configure an Ethernet connection on the command line, use the nmcli utility. For connections with dynamic IP address settings, NetworkManager requests the IP settings for the connection from a DHCP server.

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.
  • A DHCP server is available in the network.

Procedure

  1. Add a new NetworkManager connection profile for the Ethernet connection:

    # nmcli connection add con-name Example-Connection ifname enp7s0 type ethernet
  2. Optionally, change the host name NetworkManager sends to the DHCP server when using the Example-Connection profile:

    # nmcli connection modify Example-Connection ipv4.dhcp-hostname Example ipv6.dhcp-hostname Example
  3. Optionally, change the client ID NetworkManager sends to an IPv4 DHCP server when using the Example-Connection profile:

    # nmcli connection modify Example-Connection ipv4.dhcp-client-id client-ID

    Note that there is no dhcp-client-id parameter for IPv6. To create an identifier for IPv6, configure the dhclient service.

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  Example-Connection
  2. Use the ping utility to verify that this host can send packets to other hosts:

    # ping host_name_or_IP_address

Troubleshooting

  • Verify that the network cable is plugged-in to the host and a switch.
  • Check whether the link failure exists only on this host or also on other hosts connected to the same switch.
  • Verify that the network cable and the network interface are working as expected. Perform hardware diagnosis steps and replace defect cables and network interface cards.
  • If the configuration on the disk does not match the configuration on the device, starting or restarting NetworkManager creates an in-memory connection that reflects the configuration of the device. For further details and how to avoid this problem, see NetworkManager duplicates a connection after restart of NetworkManager service.

Additional resources

2.8. Configuring an Ethernet connection with a dynamic IP address by using the nmcli interactive editor

You can configure an Ethernet connection on the command line using the interactive mode of the nmcli utility. For connections with dynamic IP address settings, NetworkManager requests the IP settings for the connection from a DHCP server.

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.
  • A DHCP server is available in the network.

Procedure

  1. To add a new NetworkManager connection profile for the Ethernet connection, and starting the interactive mode, enter:

    # nmcli connection edit type ethernet con-name Example-Connection
  2. Set the network interface:

    nmcli> set connection.interface-name enp7s0
  3. Optionally, change the host name NetworkManager sends to the DHCP server when using the Example-Connection profile:

    nmcli> set ipv4.dhcp-hostname Example
    nmcli> set ipv6.dhcp-hostname Example
  4. Optionally, change the client ID NetworkManager sends to an IPv4 DHCP server when using the Example-Connection profile:

    nmcli> set ipv4.dhcp-client-id client-ID

    Note that there is no dhcp-client-id parameter for IPv6. To create an identifier for IPv6, configure the dhclient service.

  5. Save and activate the connection:

    nmcli> save persistent
    Saving the connection with 'autoconnect=yes'. That might result in an immediate activation of the connection.
    Do you still want to save? (yes/no) [yes] yes
  6. Leave the interactive mode:

    nmcli> quit

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  Example-Connection
  2. Use the ping utility to verify that this host can send packets to other hosts:

    # ping host_name_or_IP_address

Troubleshooting

  • Verify that the network cable is plugged-in to the host and a switch.
  • Check whether the link failure exists only on this host or also on other hosts connected to the same switch.
  • Verify that the network cable and the network interface are working as expected. Perform hardware diagnosis steps and replace defect cables and network interface cards.
  • If the configuration on the disk does not match the configuration on the device, starting or restarting NetworkManager creates an in-memory connection that reflects the configuration of the device. For further details and how to avoid this problem, see NetworkManager duplicates a connection after restart of NetworkManager service.

Additional resources

2.9. Configuring an Ethernet connection with a dynamic IP address by using nmtui

The nmtui application provides a text-based user interface for NetworkManager. You can use nmtui to configure an Ethernet connection with a dynamic IP address on a host without a graphical interface.

Note

In nmtui:

  • Navigate by using the cursor keys.
  • Press a button by selecting it and hitting Enter.
  • Select and deselect checkboxes by using Space.

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.
  • A DHCP server is available in the network.

Procedure

  1. If you do not know the network device name you want to use in the connection, display the available devices:

    # nmcli device status
    DEVICE     TYPE      STATE                   CONNECTION
    enp7s0     ethernet  unavailable             --
    ...
  2. Start nmtui:

    # nmtui
  3. Select Edit a connection, and press Enter.
  4. Press the Add button.
  5. Select Ethernet from the list of network types, and press Enter.
  6. Optional: Enter a name for the NetworkManager profile to be created.
  7. Enter the network device name into the Device field.
  8. Press the OK button to create and automatically activate the new connection.

    nmtui ethernet dynamic IP
  9. Press the Back button to return to the main menu.
  10. Select Quit, and press Enter to close the nmtui application.

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  Example-Connection
  2. Use the ping utility to verify that this host can send packets to other hosts:

    # ping host_name_or_IP_address

Troubleshooting

  • Verify that the network cable is plugged-in to the host and a switch.
  • Check whether the link failure exists only on this host or also on other hosts connected to the same switch.
  • Verify that the network cable and the network interface are working as expected. Perform hardware diagnosis steps and replace defect cables and network interface cards.
  • If the configuration on the disk does not match the configuration on the device, starting or restarting NetworkManager creates an in-memory connection that reflects the configuration of the device. For further details and how to avoid this problem, see NetworkManager duplicates a connection after restart of NetworkManager service.

2.10. Configuring an Ethernet connection with a dynamic IP address by using nmstatectl

To configure an Ethernet connection using the Nmstate API, use the nmstatectl utility. For connections with dynamic IP address settings, NetworkManager requests the IP settings for the connection from a DHCP server.

The nmstatectl utility ensures that, after setting the configuration, the result matches the configuration file. If anything fails, nmstatectl automatically rolls back the changes to avoid leaving the system in an incorrect state.

The procedure defines the interface configuration in YAML format. Alternatively, you can also specify the configuration in JSON format.

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.
  • A DHCP server is available in the network.
  • The nmstate package is installed.

Procedure

  1. Create a YAML file, for example ~/create-ethernet-profile.yml, with the following contents:

    ---
    interfaces:
    - name: enp7s0
      type: ethernet
      state: up
      ipv4:
        enabled: true
        auto-dns: true
        auto-gateway: true
        auto-routes: true
        dhcp: true
      ipv6:
        enabled: true
        auto-dns: true
        auto-gateway: true
        auto-routes: true
        autoconf: true
        dhcp: true
  2. Apply the settings to the system:

    # nmstatectl apply ~/create-ethernet-profile.yml

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  enp7s0
  2. Display all settings of the connection profile:

    # nmcli connection show enp7s0
    connection.id:              enp7s0
    connection.uuid:            b6cdfa1c-e4ad-46e5-af8b-a75f06b79f76
    connection.stable-id:       --
    connection.type:            802-3-ethernet
    connection.interface-name:  enp7s0
    ...
  3. Display the connection settings in YAML format:

    # nmstatectl show enp7s0

Additional resources

  • nmstatectl(8) man page
  • /usr/share/doc/nmstate/examples/ directory

2.11. Configuring an Ethernet connection with a dynamic IP address by using the network RHEL System Role with an interface name

You can remotely configure an Ethernet connection using the network RHEL System Role. For connections with dynamic IP address settings, NetworkManager requests the IP settings for the connection from a DHCP server.

Perform this procedure on the Ansible control node.

Prerequisites

  • You have prepared the control node and the managed nodes
  • You are logged in to the control node as a user who can run playbooks on the managed nodes.
  • The account you use to connect to the managed nodes has sudo permissions on them.
  • The managed nodes or groups of managed nodes on which you want to run this playbook are listed in the Ansible inventory file.
  • A physical or virtual Ethernet device exists in the server’s configuration.
  • A DHCP server is available in the network
  • The managed nodes use NetworkManager to configure the network.

Procedure

  1. Create a playbook file, for example ~/ethernet-dynamic-IP.yml, with the following content:

    ---
    - name: Configure the network
      hosts: managed-node-01.example.com
      tasks:
      - name: Configure an Ethernet connection with dynamic IP
        include_role:
          name: rhel-system-roles.network
    
        vars:
          network_connections:
            - name: enp7s0
              interface_name: enp7s0
              type: ethernet
              autoconnect: yes
              ip:
                dhcp4: yes
                auto6: yes
              state: up
  2. Run the playbook:

    # ansible-playbook ~/ethernet-dynamic-IP.yml

Additional resources

  • /usr/share/ansible/roles/rhel-system-roles.network/README.md file

2.12. Configuring an Ethernet connection with a dynamic IP address by using the network RHEL System Role with a device path

You can remotely configure an Ethernet connection using the network RHEL System Role. For connections with dynamic IP address settings, NetworkManager requests the IP settings for the connection from a DHCP server.

You can identify the device path with the following command:

# udevadm info /sys/class/net/<device_name> | grep ID_PATH=

Perform this procedure on the Ansible control node.

Prerequisites

  • You have prepared the control node and the managed nodes
  • You are logged in to the control node as a user who can run playbooks on the managed nodes.
  • The account you use to connect to the managed nodes has sudo permissions on them.
  • The managed nodes or groups of managed nodes on which you want to run this playbook are listed in the Ansible inventory file.
  • A physical or virtual Ethernet device exists in the server’s configuration.
  • A DHCP server is available in the network.
  • The managed hosts use NetworkManager to configure the network.

Procedure

  1. Create a playbook file, for example ~/ethernet-dynamic-IP.yml, with the following content:

    ---
    - name: Configure the network
      hosts: managed-node-01.example.com
      tasks:
      - name: Configure an Ethernet connection with dynamic IP
        include_role:
          name: rhel-system-roles.network
    
        vars:
          network_connections:
            - name: example
              match:
                path:
                  - pci-0000:00:0[1-3].0
                  - &!pci-0000:00:02.0
              type: ethernet
              autoconnect: yes
              ip:
                dhcp4: yes
                auto6: yes
              state: up

    The match parameter in this example defines that Ansible applies the play to devices that match PCI ID 0000:00:0[1-3].0, but not 0000:00:02.0. For further details about special modifiers and wild cards you can use, see the match parameter description in the /usr/share/ansible/roles/rhel-system-roles.network/README.md file.

  2. Run the playbook:

    # ansible-playbook ~/ethernet-dynamic-IP.yml

Additional resources

  • /usr/share/ansible/roles/rhel-system-roles.network/README.md file

2.13. Configuring an Ethernet connection by using control-center

Ethernet connections are the most frequently used connections types in physical or virtual machines. If you use Red Hat Enterprise Linux with a graphical interface, you can configure this connection type in the GNOME control-center.

Note that control-center does not support as many configuration options as the nm-connection-editor application or the nmcli utility.

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.
  • GNOME is installed.

Procedure

  1. Press the Super key, enter Settings, and press Enter.
  2. Select Network in the navigation on the left.
  3. Click the + button next to the Wired entry to create a new profile.
  4. Optional: Set a name for the connection on the Identity tab.
  5. On the IPv4 tab, configure the IPv4 settings. For example, select method Manual, set a static IPv4 address, network mask, default gateway, and DNS server:

    IPv4 settings control center RHEL9
  6. On the IPv6 tab, configure the IPv6 settings. For example, select method Manual, set a static IPv6 address, network mask, default gateway, and DNS server:

    IPv6 settings control center RHEL9
  7. Click the Add button to save the connection. The GNOME control-center automatically activates the connection.

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  Example-Connection
  2. Use the ping utility to verify that this host can send packets to other hosts:

    # ping host_name_or_IP_address

Troubleshooting steps

  • Verify that the network cable is plugged-in to the host and a switch.
  • Check whether the link failure exists only on this host or also on other hosts connected to the same switch.
  • Verify that the network cable and the network interface are working as expected. Perform hardware diagnosis steps and replace defect cables and network interface cards.
  • If the configuration on the disk does not match the configuration on the device, starting or restarting NetworkManager creates an in-memory connection that reflects the configuration of the device. For further details and how to avoid this problem, see NetworkManager duplicates a connection after restart of NetworkManager service.

2.14. Configuring an Ethernet connection by using nm-connection-editor

Ethernet connections are the most frequently used connection types in physical or virtual servers. If you use Red Hat Enterprise Linux with a graphical interface, you can configure this connection type using the nm-connection-editor application.

Prerequisites

  • A physical or virtual Ethernet device exists in the server’s configuration.
  • GNOME is installed.

Procedure

  1. Open a terminal, and enter:

    $ nm-connection-editor
  2. Click the + button to add a new connection.
  3. Select the Ethernet connection type, and click Create.
  4. On the General tab:

    1. To automatically enable this connection when the system boots or when you restart the NetworkManager service:

      1. Select Connect automatically with priority.
      2. Optional: Change the priority value next to Connect automatically with priority.

        If multiple connection profiles exist for the same device, NetworkManager enables only one profile. By default, NetworkManager activates the last-used profile that has auto-connect enabled. However, if you set priority values in the profiles, NetworkManager activates the profile with the highest priority.

    2. Clear the All users may connect to this network check box if the profile should be available only to the user that created the connection profile.

    ethernet connection general tab

  5. On the Ethernet tab, select a device and, optionally, further Ethernet-related settings.

    ethernet connection settings

  6. On the IPv4 Settings tab, configure the IPv4 settings. For example, set a static IPv4 address, network mask, default gateway, and DNS server:

    IPv4 settings nm connection editor

  7. On the IPv6 Settings tab, configure the IPv6 settings. For example, set a static IPv6 address, network mask, default gateway, and DNS server:

    IPv6 settings nm connection editor

  8. Save the connection.
  9. Close nm-connection-editor.

Verification

  1. Display the status of the devices and connections:

    # nmcli device status
    DEVICE      TYPE      STATE      CONNECTION
    enp7s0      ethernet  connected  Example-Connection
  2. Use the ping utility to verify that this host can send packets to other hosts:

    # ping host_name_or_IP_address

2.15. Changing the DHCP client of NetworkManager

By default, NetworkManager uses its internal DHCP client. However, if you require a DHCP client with features that the built-in client does not provide, you can alternatively configure NetworkManager to use dhclient.

Note that RHEL does not provide dhcpcd and, therefore, NetworkManager can not use this client.

Procedure

  1. Create the /etc/NetworkManager/conf.d/dhcp-client.conf file with the following content:

    [main]
    dhcp=dhclient

    You can set the dhcp parameter to internal (default) or dhclient.

  2. If you set the dhcp parameter to dhclient, install the dhcp-client package:

    # dnf install dhcp-client
  3. Restart NetworkManager:

    # systemctl restart NetworkManager

    Note that the restart temporarily interrupts all network connections.

Verification

  • Search in the /var/log/messages log file for an entry similar to the following:

    Apr 26 09:54:19 server NetworkManager[27748]: <info>  [1650959659.8483] dhcp-init: Using DHCP client 'dhclient'

    This log entry confirms that NetworkManager uses dhclient as DHCP client.

Additional resources

  • NetworkManager.conf(5) man page

2.16. Configuring the DHCP behavior of a NetworkManager connection

A Dynamic Host Configuration Protocol (DHCP) client requests the dynamic IP address and corresponding configuration information from a DHCP server each time a client connects to the network.

When you configured a connection to retrieve an IP address from a DHCP server, the NetworkManager requests an IP address from a DHCP server. By default, the client waits 45 seconds for this request to be completed. When a DHCP connection is started, a dhcp client requests an IP address from a DHCP server.

Prerequisites

  • A connection that uses DHCP is configured on the host.

Procedure

  1. Set the ipv4.dhcp-timeout and ipv6.dhcp-timeout properties. For example, to set both options to 30 seconds, enter:

    # nmcli connection modify connection_name ipv4.dhcp-timeout 30 ipv6.dhcp-timeout 30

    Alternatively, set the parameters to infinity to configure that NetworkManager does not stop trying to request and renew an IP address until it is successful.

  2. Optional: Configure the behavior if NetworkManager does not receive an IPv4 address before the timeout:

    # nmcli connection modify connection_name ipv4.may-fail value

    If you set the ipv4.may-fail option to:

    • yes, the status of the connection depends on the IPv6 configuration:

      • If the IPv6 configuration is enabled and successful, NetworkManager activates the IPv6 connection and no longer tries to activate the IPv4 connection.
      • If the IPv6 configuration is disabled or not configured, the connection fails.
    • no, the connection is deactivated. In this case:

      • If the autoconnect property of the connection is enabled, NetworkManager retries to activate the connection as many times as set in the autoconnect-retries property. The default is 4.
      • If the connection still cannot acquire a DHCP address, auto-activation fails. Note that after 5 minutes, the auto-connection process starts again to acquire an IP address from the DHCP server.
  3. Optional: Configure the behavior if NetworkManager does not receive an IPv6 address before the timeout:

    # nmcli connection modify connection_name ipv6.may-fail value

Additional resources

  • nm-settings(5) man page

2.17. Configuring multiple Ethernet interfaces by using a single connection profile by interface name

In most cases, one connection profile contains the settings of one network device. However, NetworkManager also supports wildcards when you set the interface name in connection profiles. If a host roams between Ethernet networks with dynamic IP address assignment, you can use this feature to create a single connection profile that you can use for multiple Ethernet interfaces.

Prerequisites

  • Multiple physical or virtual Ethernet devices exist in the server’s configuration.
  • A DHCP server is available in the network.
  • No connection profile exists on the host.

Procedure

  1. Add a connection profile that applies to all interface names starting with enp:

    # nmcli connection add con-name Example connection.multi-connect multiple match.interface-name enp* type ethernet

Verification

  1. Display all settings of the single connection profile:

    # nmcli connection show Example
    connection.id:                      Example
    ...
    connection.multi-connect:           3 (multiple)
    match.interface-name:               enp*
    ...

    3 indicates the number of interfaces active on the connection profile at the same time, and not the number of network interfaces in the connection profile. The connection profile uses all devices that match the pattern in the match.interface-name parameter and, therefore, the connection profiles have the same Universally Unique Identifier (UUID).

  2. Display the status of the connections:

    # nmcli connection show
    NAME                    UUID                    TYPE     DEVICE
    ...
    Example  6f22402e-c0cc-49cf-b702-eaf0cd5ea7d1  ethernet  enp7s0
    Example  6f22402e-c0cc-49cf-b702-eaf0cd5ea7d1  ethernet  enp8s0
    Example  6f22402e-c0cc-49cf-b702-eaf0cd5ea7d1  ethernet  enp9s0

Additional resources

  • nmcli(1) man page
  • nm-settings(5) man page

2.18. Configuring a single connection profile for multiple Ethernet interfaces using PCI IDs

The PCI ID is a unique identifier of the devices connected to the system. The connection profile adds multiple devices by matching interfaces based on a list of PCI IDs. You can use this procedure to connect multiple device PCI IDs to the single connection profile.

Prerequisites

  • Multiple physical or virtual Ethernet devices exist in the server’s configuration.
  • A DHCP server is available in the network.
  • No connection profile exists on the host.

Procedure

  1. Identify the device path. For example, to display the device paths of all interfaces starting with enp, enter :

    # udevadm info /sys/class/net/enp* | grep ID_PATH=
    ...
    E: ID_PATH=pci-0000:07:00.0
    E: ID_PATH=pci-0000:08:00.0
  2. Add a connection profile that applies to all PCI IDs matching the 0000:00:0[7-8].0 expression:

    # nmcli connection add type ethernet connection.multi-connect multiple match.path "pci-0000:07:00.0 pci-0000:08:00.0" con-name Example

Verification

  1. Display the status of the connection:

    # nmcli connection show
    NAME   UUID     TYPE        DEVICE
    Example      9cee0958-512f-4203-9d3d-b57af1d88466  ethernet  enp7s0
    Example      9cee0958-512f-4203-9d3d-b57af1d88466  ethernet  enp8s0
    ...
  2. To display all settings of the connection profile:

    # nmcli connection show Example
    connection.id:               Example
    ...
    connection.multi-connect:    3 (multiple)
    match.path:                  pci-0000:07:00.0,pci-0000:08:00.0
    ...

    This connection profile uses all devices with a PCI ID which match the pattern in the match.path parameter and, therefore, the connection profiles have the same Universally Unique Identifier (UUID).

Additional resources

  • nmcli(1) man page
  • nm-settings(5) man page