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.
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
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.Set the IPv4 address:
# nmcli connection modify Example-Connection ipv4.addresses 192.0.2.1/24
Set the IPv6 address:
# nmcli connection modify Example-Connection ipv6.addresses 2001:db8:1::1/64
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
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
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.
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
Activate the connection profile:
# nmcli connection up Example-Connection Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/13)
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected Example-Connection
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
-
nm-settings(5)
man page -
nmcli(1)
man page - Configuring NetworkManager to avoid using a specific profile to provide a default gateway
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
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
Set the network interface:
nmcli> set connection.interface-name enp7s0
Set the IPv4 address:
nmcli> set ipv4.addresses 192.0.2.1/24
Set the IPv6 address:
nmcli> set ipv6.addresses 2001:db8:1::1/64
Set the IPv4 and IPv6 connection method to
manual
:nmcli> set ipv4.method manual nmcli> set ipv6.method manual
Set the IPv4 and IPv6 default gateways:
nmcli> set ipv4.gateway 192.0.2.254 nmcli> set ipv6.gateway 2001:db8:1::fffe
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.
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
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
Leave the interactive mode:
nmcli> quit
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected Example-Connection
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
-
nm-settings(5)
man page -
nmcli(1)
man page - Configuring NetworkManager to avoid using a specific profile to provide a default gateway
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.
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
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 -- ...
Start
nmtui
:# nmtui
-
Select
Edit a connection
, and press Enter. -
Press the
Add
button. -
Select
Ethernet
from the list of network types, and press Enter. - Optional: Enter a name for the NetworkManager profile to be created.
-
Enter the network device name into the
Device
field. Configure the IPv4 and IPv6 address settings in the
IPv4 configuration
andIPv6 configuration
areas:-
Press the
Automatic
button, and selectManual
from the displayed list. -
Press the
Show
button next to the protocol you want to configure to display additional fields. Press the
Add
button next toAddresses
, 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.- Enter the address of the default gateway.
-
Press the
Add
button next toDNS servers
, and enter the DNS server address. -
Press the
Add
button next toSearch domains
, and enter the DNS search domain.
Figure 2.1. Example of an Ethernet connection with static IP address settings
-
Press the
-
Press the
OK
button to create and automatically activate the new connection. -
Press the
Back
button to return to the main menu. -
Select
Quit
, and press Enter to close thenmtui
application.
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected Example-Connection
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
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
Apply the settings to the system:
# nmstatectl apply ~/create-ethernet-profile.yml
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected enp7s0
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 ...
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
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
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
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 ID0000:00:0[1-3].0
, but not0000:00:02.0
. For further details about special modifiers and wild cards you can use, see thematch
parameter description in the/usr/share/ansible/roles/rhel-system-roles.network/README.md
file.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
Add a new NetworkManager connection profile for the Ethernet connection:
# nmcli connection add con-name Example-Connection ifname enp7s0 type ethernet
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
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 thedhclient
service.
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected Example-Connection
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
-
dhclient(8)
man page -
nm-settings(5)
-
nmcli(1)
man page - Configuring NetworkManager to avoid using a specific profile to provide a default gateway
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
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
Set the network interface:
nmcli> set connection.interface-name enp7s0
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
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 thedhclient
service.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
Leave the interactive mode:
nmcli> quit
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected Example-Connection
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
-
nm-settings(5)
man page -
nmcli(1)
man page - Configuring NetworkManager to avoid using a specific profile to provide a default gateway
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.
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
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 -- ...
Start
nmtui
:# nmtui
-
Select
Edit a connection
, and press Enter. -
Press the
Add
button. -
Select
Ethernet
from the list of network types, and press Enter. - Optional: Enter a name for the NetworkManager profile to be created.
-
Enter the network device name into the
Device
field. Press the
OK
button to create and automatically activate the new connection.-
Press the
Back
button to return to the main menu. -
Select
Quit
, and press Enter to close thenmtui
application.
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected Example-Connection
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
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
Apply the settings to the system:
# nmstatectl apply ~/create-ethernet-profile.yml
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected enp7s0
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 ...
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
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
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
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 ID0000:00:0[1-3].0
, but not0000:00:02.0
. For further details about special modifiers and wild cards you can use, see thematch
parameter description in the/usr/share/ansible/roles/rhel-system-roles.network/README.md
file.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
-
Press the Super key, enter
Settings
, and press Enter. -
Select
Network
in the navigation on the left. -
Click the + button next to the
Wired
entry to create a new profile. -
Optional: Set a name for the connection on the
Identity
tab. On the
IPv4
tab, configure the IPv4 settings. For example, select methodManual
, set a static IPv4 address, network mask, default gateway, and DNS server:On the
IPv6
tab, configure the IPv6 settings. For example, select methodManual
, set a static IPv6 address, network mask, default gateway, and DNS server:-
Click the Add button to save the connection. The GNOME
control-center
automatically activates the connection.
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected Example-Connection
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
Open a terminal, and enter:
$ nm-connection-editor
- Click the + button to add a new connection.
-
Select the
Ethernet
connection type, and click Create. On the
General
tab:To automatically enable this connection when the system boots or when you restart the
NetworkManager
service:-
Select
Connect automatically with priority
. 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.
-
Select
-
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.
On the
Ethernet
tab, select a device and, optionally, further Ethernet-related settings.On the
IPv4 Settings
tab, configure the IPv4 settings. For example, set a static IPv4 address, network mask, default gateway, and DNS server:On the
IPv6 Settings
tab, configure the IPv6 settings. For example, set a static IPv6 address, network mask, default gateway, and DNS server:- Save the connection.
-
Close
nm-connection-editor
.
Verification
Display the status of the devices and connections:
# nmcli device status DEVICE TYPE STATE CONNECTION enp7s0 ethernet connected Example-Connection
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
Create the
/etc/NetworkManager/conf.d/dhcp-client.conf
file with the following content:[main] dhcp=dhclient
You can set the
dhcp
parameter tointernal
(default) ordhclient
.If you set the
dhcp
parameter todhclient
, install thedhcp-client
package:# dnf install dhcp-client
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
Set the
ipv4.dhcp-timeout
andipv6.dhcp-timeout
properties. For example, to set both options to30
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.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 theautoconnect-retries
property. The default is4
. - 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.
-
If the
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
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
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 thematch.interface-name
parameter and, therefore, the connection profiles have the same Universally Unique Identifier (UUID).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
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
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
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 ...
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