Network ConfigurationLesson 2 of 3
Static IPv4 and IPv6 with nmcli
Give a connection a fixed address, gateway and DNS for IPv4 and IPv6, make it persistent, and read the keyfile NetworkManager writes.
nmcli connection modifynmcli connection addnmcli connection upnmcli connection reloadnmtui/etc/NetworkManager/system-connectionsipv4.method manualipv6.addresses
After this lesson you can
- Set a static IPv4 address, gateway, DNS server and search domain on an existing connection and apply it.
- Add a static IPv6 address, a second address on the same interface, and a new connection for a second NIC.
- Locate the keyfile that stores a connection, check its permissions, and return a connection to DHCP.
The idea
On RHEL 10 the persistent way to configure networking is NetworkManager, driven by nmcli (command line), nmtui (text menus) or the web console. Settings are stored per connection in keyfiles: /etc/NetworkManager/system-connections/NAME.nmconnection. The old ifcfg-* files under /etc/sysconfig/network-scripts/ are no longer how RHEL 10 works, so do not edit them.
Changing the configuration is always the same two moves:
nmcli connection modify NAME property value ...: edit the saved settings (written to the keyfile at once).nmcli connection up NAME: apply the settings to the live device.
modify alone changes the file and not the running network; up without modify re-applies the old one. The settings are persistent because they are in the file, and they apply at boot because connection.autoconnect is yes.
The properties you need
| Property | Example | Meaning |
|---|---|---|
ipv4.method | manual / auto / disabled | Static / DHCP / off |
ipv4.addresses | 192.168.122.50/24 | Address and prefix length, comma-separated list |
ipv4.gateway | 192.168.122.1 | Default gateway |
ipv4.dns | 192.168.122.1 | DNS servers (comma-separated) |
ipv4.dns-search | lab.example | Domain appended to short names |
ipv6.* | ipv6.addresses fd00:122::50/64 | The same properties for IPv6 |
connection.autoconnect | yes | Bring up at boot |
Notes:
- With
ipv4.method manualyou must supply an address;nmclirefuses a method change without one. +ipv4.addresses ADDRappends and-ipv4.addresses ADDRremoves one entry; plainipv4.addresses ADDRreplaces the list.- Quote connection names with spaces:
"System eth0". - The same thing for IPv6 uses
ipv6.method manual; leave it atautoto keep SLAAC/DHCPv6, ordisabledto turn it off.
Try it
sudo nmcli connection modify "System eth0" \
ipv4.method manual \
ipv4.addresses 192.168.122.50/24 \
ipv4.gateway 192.168.122.1 \
ipv4.dns 192.168.122.1 \
ipv4.dns-search lab.example \
connection.autoconnect yes
sudo nmcli connection up "System eth0"
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
ip -br addr show eth0
ip route | head -2
cat /etc/resolv.conf
eth0 UP 192.168.122.50/24
default via 192.168.122.1 dev eth0 proto static metric 100
192.168.122.0/24 dev eth0 proto kernel scope link src 192.168.122.50 metric 100
# Generated by NetworkManager
search lab.example
nameserver 192.168.122.1
/etc/resolv.conf is generated by NetworkManager from the connection. Edit the connection, not the file, or your change is overwritten the next time the connection comes up.
IPv6 and a second address
sudo nmcli connection modify "System eth0" \
ipv6.method manual \
ipv6.addresses fd00:122::50/64 \
ipv6.gateway fd00:122::1 \
ipv6.dns fd00:122::1
sudo nmcli connection up "System eth0"
ip -6 addr show dev eth0 scope global
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
inet6 fd00:122::50/64 scope global noprefixroute
valid_lft forever preferred_lft forever
sudo nmcli connection modify "System eth0" +ipv4.addresses 192.168.122.51/24
sudo nmcli connection up "System eth0"
ip -4 -br addr show eth0
eth0 UP 192.168.122.50/24 192.168.122.51/24
A new connection for another NIC
sudo nmcli connection add type ethernet con-name storage-net ifname eth1 \
ipv4.method manual ipv4.addresses 10.10.10.50/24 \
ipv6.method disabled connection.autoconnect yes
sudo nmcli connection up storage-net
Connection 'storage-net' (b1c0f1b6-6b2a-4a7e-8d8a-1d4fb5c6f9a7) successfully added.
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5)
The file behind it
sudo ls -l /etc/NetworkManager/system-connections/
sudo cat /etc/NetworkManager/system-connections/storage-net.nmconnection
-rw-------. 1 root root 288 Nov 3 13:20 storage-net.nmconnection
[connection]
id=storage-net
uuid=b1c0f1b6-6b2a-4a7e-8d8a-1d4fb5c6f9a7
type=ethernet
interface-name=eth1
[ethernet]
[ipv4]
address1=10.10.10.50/24
method=manual
[ipv6]
addr-gen-mode=default
method=disabled
[proxy]
The mode is 600 because keyfiles can hold Wi-Fi passwords and VPN secrets; NetworkManager ignores keyfiles that other users can read. If you edit a keyfile by hand, apply it with sudo nmcli connection reload, then nmcli connection up NAME.
Back to DHCP, and cleanup
sudo nmcli connection modify storage-net ipv4.method auto ipv4.addresses "" ipv4.gateway ""
sudo nmcli connection delete storage-net
For DHCP, clear the static values as well as setting auto; otherwise the old address remains in the file. nmtui offers the same edits through menus, handy when you forget a property name, but practise nmcli because it is quicker and can be pasted into notes.
Going further
nmcli device reapply eth0 applies changes without a full reconnect. nmcli connection modify NAME ipv4.routes "10.20.0.0/16 192.168.122.254" adds a static route and ipv4.ignore-auto-dns yes keeps DHCP from overwriting your DNS. nmcli general status gives an overview, nmcli connection monitor prints events as they happen, and journalctl -u NetworkManager shows why a connection failed. Bonds, bridges and VLANs are further connection types in the same tool: nmcli connection add type bond .... Changing a connection’s MTU or MAC address uses 802-3-ethernet.mtu and 802-3-ethernet.cloned-mac-address.
Practice
0 of 6 done
Do these on your own system. They get harder. Check each result, then tick it off.
- Warm-up
Read the connection before changing it
Before you edit anything, record the current IPv4 method, address, gateway and DNS of your main connection, and the name of its keyfile. Write down how you would undo your change.
Check your result
nmcli connection show NAMEprints theipv4.*values;ls /etc/NetworkManager/system-connectionsshows the keyfile. You have a copy of the values to restore.Hint
nmcli -f ipv4 connection show NAMElimits the output to IPv4 settings.sudo cp -athe keyfile as a backup.Solution
nmcli -f ipv4 connection show "System eth0" sudo ls -l /etc/NetworkManager/system-connections/ sudo cp -a /etc/NetworkManager/system-connections /root/nm-backup - Practice
A fixed IPv4 configuration
Using the connection that serves your main interface, configure: address
192.168.122.50/24, gateway192.168.122.1, DNS192.168.122.1, search domainlab.example, static method, auto-connect at boot. Apply it and verify addresses, route and DNS. (Adapt the addresses to your own lab network and take care: a wrong address over SSH locks you out. Use the VM console.)Check your result
ip -br addrshows192.168.122.50/24.ip routeshowsdefault via 192.168.122.1.nmcli -g ipv4.method connection show NAMEprintsmanual.grep search /etc/resolv.confshowslab.example.Hint
nmcli connection modify NAME ipv4.method manual ipv4.addresses ... ipv4.gateway ... ipv4.dns ... ipv4.dns-search ..., thennmcli connection up NAME.Solution
nmcli device status sudo nmcli connection modify "System eth0" \ ipv4.method manual \ ipv4.addresses 192.168.122.50/24 \ ipv4.gateway 192.168.122.1 \ ipv4.dns 192.168.122.1 \ ipv4.dns-search lab.example \ connection.autoconnect yes sudo nmcli connection up "System eth0" ip -br addr ip route cat /etc/resolv.conf - Practice
Add an IPv6 address
On the same connection set a static IPv6 address
fd00:122::50/64with gatewayfd00:122::1and DNSfd00:122::1, keeping IPv4 unchanged. Apply and verify withip -6. Then ping your own IPv6 address.Check your result
ip -6 addr show dev eth0listsfd00:122::50/64.ping -6 -c1 fd00:122::50succeeds. The IPv4 settings are unchanged.Hint
ipv6.method manual ipv6.addresses fd00:122::50/64 ipv6.gateway fd00:122::1 ipv6.dns fd00:122::1. The gateway need not answer for the address to appear.Solution
sudo nmcli connection modify "System eth0" \ ipv6.method manual \ ipv6.addresses fd00:122::50/64 \ ipv6.gateway fd00:122::1 \ ipv6.dns fd00:122::1 sudo nmcli connection up "System eth0" ip -6 addr show dev eth0 ping -6 -c1 fd00:122::50 - Practice
Two addresses on one interface
Add a secondary IPv4 address
192.168.122.51/24to the same connection without removing the first. Verify both exist. Then remove only the secondary one.Check your result
ip -4 addr show eth0lists both addresses. After removal only.50remains.Hint
A plus sign before the property appends:
+ipv4.addresses. A minus sign removes:-ipv4.addresses.Solution
sudo nmcli connection modify "System eth0" +ipv4.addresses 192.168.122.51/24 sudo nmcli connection up "System eth0" ip -4 addr show eth0 sudo nmcli connection modify "System eth0" -ipv4.addresses 192.168.122.51/24 sudo nmcli connection up "System eth0" ip -4 addr show eth0 - Practice
Configure a second network card
The VM has a second NIC
eth1, unconfigured. Create a new connection namedstorage-netfor it with static address10.10.10.50/24, no gateway, starting automatically at boot. Verify it is up, and persists after a reboot.Check your result
nmcli connection showlistsstorage-neton deviceeth1andip -br addr show eth1shows10.10.10.50/24. Afterrebootit is still up.Hint
nmcli connection add type ethernet con-name storage-net ifname eth1 ipv4.method manual ipv4.addresses 10.10.10.50/24 connection.autoconnect yes.Solution
sudo nmcli connection add type ethernet con-name storage-net ifname eth1 \ ipv4.method manual ipv4.addresses 10.10.10.50/24 \ ipv6.method disabled connection.autoconnect yes sudo nmcli connection up storage-net ip -br addr show eth1 sudo reboot - Challenge
Look at the stored file; go back to DHCP
Find the file on disk where
storage-netis stored, show its permissions and contents, and explain why the mode matters. Then return the connection to DHCP: clear the static addresses and set the automatic method. Finally delete the connection.Check your result
/etc/NetworkManager/system-connections/storage-net.nmconnectionexists with mode600. After the changeipv4.methodisautoandipv4.addressesis empty.nmcli con showno longer lists it afterdelete.Hint
nmcli connection modify NAME ipv4.method auto ipv4.addresses "" ipv4.gateway "". NetworkManager refuses keyfiles that others can read, because they can contain secrets.Solution
sudo ls -l /etc/NetworkManager/system-connections/ sudo cat /etc/NetworkManager/system-connections/storage-net.nmconnection sudo nmcli connection modify storage-net ipv4.method auto ipv4.addresses "" ipv4.gateway "" nmcli -g ipv4.method,ipv4.addresses connection show storage-net sudo nmcli connection delete storage-net nmcli connection show