Computer NetworksNETWORKS

Redhat Linux 9: Thiết lập kết nối ethernet với nmcli



Playlist: https://www.youtube.com/playlist?list=PLIpLw6v7Z1qmE7G_eeuooLblPdsZS6yJd


Link playlist
Red Hat Enterprise Linux Administration

2024 01 16 13 38 47

1.2. Configuring an Ethernet connection by using nmcli

If you connect a host to the network over Ethernet, you can manage the connection’s settings on the command line by using the nmcli utility.

Prerequisites

A physical or virtual Ethernet Network Interface Controller (NIC) exists in the server’s configuration.

Procedure

List the NetworkManager connection profiles:

# nmcli connection show
NAME UUID TYPE DEVICE
Wired connection 1 a5eb6490-cc20-3668-81f8-0314a27f3f75 ethernet enp1s0

By default, NetworkManager creates a profile for each NIC in the host. If you plan to connect this NIC only to a specific network, adapt the automatically-created profile. If you plan to connect this NIC to networks with different settings, create individual profiles for each network.

If you want to create an additional connection profile, enter:

# nmcli connection add con-name connection-name ifname device-name type ethernet

Skip this step to modify an existing profile.

Optional: Rename the connection profile:

# nmcli connection modify “Wired connection 1” connection.id “Internal-LAN”

On hosts with multiple profiles, a meaningful name makes it easier to identify the purpose of a profile.

Display the current settings of the connection profile:

# nmcli connection show Internal-LAN

connection.interface-name: enp1s0
connection.autoconnect: yes
ipv4.method: auto
ipv6.method: auto

Configure the IPv4 settings:

To use DHCP, enter:

# nmcli connection modify Internal-LAN ipv4.method auto

Skip this step if ipv4.method is already set to auto (default).

To set a static IPv4 address, network mask, default gateway, DNS servers, and search domain, enter:

# nmcli connection modify Internal-LAN ipv4.method manual ipv4.addresses 192.0.2.1/24 ipv4.gateway 192.0.2.254 ipv4.dns 192.0.2.200 ipv4.dns-search example.com

Configure the IPv6 settings:

To use stateless address autoconfiguration (SLAAC), enter:

# nmcli connection modify Internal-LAN ipv6.method auto

Skip this step if ipv6.method is already set to auto (default).

To set a static IPv6 address, network mask, default gateway, DNS servers, and search domain, enter:

# nmcli connection modify Internal-LAN ipv6.method manual ipv6.addresses 2001:db8:1::fffe/64 ipv6.gateway 2001:db8:1::fffe ipv6.dns 2001:db8:1::ffbb ipv6.dns-search example.com

To customize other settings in the profile, use the following command:

# nmcli connection modify connection-name setting value

Enclose values with spaces or semicolons in quotes.

Activate the profile:

# nmcli connection up Internal-LAN

Verification

Display the IP settings of the NIC:

# ip address show enp1s0
2: enp1s0: BROADCAST,MULTICAST,UP,LOWER_UP mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 52:54:00:17:b8:b6 brd ff:ff:ff:ff:ff:ff
inet 192.0.2.1/24 brd 192.0.2.255 scope global noprefixroute enp1s0
valid_lft forever preferred_lft forever
inet6 2001:db8:1::fffe/64 scope global noprefixroute
valid_lft forever preferred_lft forever

Display the IPv4 default gateway:

# ip route show default
default via 192.0.2.254 dev enp1s0 proto static metric 102

Display the IPv6 default gateway:

# ip -6 route show default
default via 2001:db8:1::ffee dev enp1s0 proto static metric 102 pref medium

Display the DNS settings:

# cat /etc/resolv.conf

If multiple connection profiles are active at the same time, the order of nameserver entries depend on the DNS priority values in these profile and the connection types.

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.

source
ipv4

Alice AUSTIN

Alice AUSTIN is studying Cisco Systems Engineering. He has passion with both hardware and software and writes articles and reviews for many IT websites.