RED HAT ENTERPRISE LINUX
Configure IPv4
and IPv6 Addresses
Configure IPv4 and IPv6 addresses
CIS126RH | RHEL System Administration 1
Mesa Community College
Network configuration is among the most tested skills on the RHCSA exam. RHEL 9
manages network connections with NetworkManager and its command-line
tool nmcli. Every persistent network setting — IP address, subnet mask,
gateway, DNS — is stored in a connection profile that survives reboots.
This module covers assigning static IPv4 and IPv6 addresses, configuring DNS and
gateways, and verifying connectivity — all using nmcli as the primary tool.
Learning Objectives
-
Explain the NetworkManager and nmcli model —
Describe how NetworkManager manages connection profiles and why
nmcliis the correct tool for persistent configuration -
Configure a static IPv4 address —
Use
nmclito assign a static IPv4 address, subnet mask, default gateway, and DNS servers to a network interface -
Configure a static IPv6 address —
Use
nmclito assign a static IPv6 address with prefix length, IPv6 gateway, and IPv6 DNS servers -
Verify and troubleshoot network configuration —
Use
ip addr,ip route,nmcli, andpingto confirm settings and diagnose problems
NetworkManager and nmcli
On RHEL 9, NetworkManager is the service that manages all
network connections. nmcli is its command-line interface.
- NetworkManager stores network settings in connection profiles
(files in
/etc/NetworkManager/system-connections/) - A connection profile defines all settings for one network connection: address, gateway, DNS, method (DHCP or static)
- A profile is applied to a specific device (e.g.
ens3) - Changes made with
nmcliare persistent — they survive reboots - Changes made with
ip addr addare temporary — lost at reboot
The ip addr add and ip route add commands modify the
live kernel network state only. After a reboot the configuration reverts to what
is stored in the NetworkManager profile. For persistent configuration, always
use nmcli.
Viewing Current Network State
# Show all interfaces with their IP addresses
$ ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 ...
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic ens3
inet6 fe80::1/64 scope link
# Show routing table
$ ip route show
default via 192.168.1.1 dev ens3 proto dhcp metric 100
192.168.1.0/24 dev ens3 proto kernel scope link src 192.168.1.100
# Show NetworkManager connection profiles
$ nmcli connection show
NAME UUID TYPE DEVICE
ens3 abc123de-4567-89ab-cdef-012345678901 ethernet ens3
# Show all details of a specific connection
$ nmcli connection show ens3
# Show network device status
$ nmcli device status
Configuring a Static IPv4 Address
The complete static IPv4 configuration requires setting four properties: address/prefix, gateway, DNS, and switching the method from DHCP to manual.
# Set the connection method to manual (static)
$ sudo nmcli connection modify ens3 \
ipv4.method manual
# Set the IPv4 address and subnet mask (CIDR notation)
$ sudo nmcli connection modify ens3 \
ipv4.addresses 192.168.1.200/24
# Set the default gateway
$ sudo nmcli connection modify ens3 \
ipv4.gateway 192.168.1.1
# Set DNS servers (comma-separated for multiple)
$ sudo nmcli connection modify ens3 \
ipv4.dns "8.8.8.8,8.8.4.4"
# All four in a single command (most efficient)
$ sudo nmcli connection modify ens3 \
ipv4.method manual \
ipv4.addresses 192.168.1.200/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8,8.8.4.4"
Activating the Connection
After modifying a connection profile, the changes must be applied to the live network interface by reactivating the connection.
# Reactivate the connection to apply changes
$ sudo nmcli connection up ens3
Connection successfully activated (D-Bus active path: ...)
# Alternative: reload all connections without disconnecting
$ sudo nmcli connection reload
# Verify the new address is active
$ ip addr show ens3
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
inet 192.168.1.200/24 brd 192.168.1.255 scope global noprefixroute ens3
# Verify the gateway is in the routing table
$ ip route show
default via 192.168.1.1 dev ens3 proto static metric 100
192.168.1.0/24 dev ens3 proto kernel scope link src 192.168.1.200
# Verify DNS is configured
$ cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
This three-step pattern is the complete exam workflow. Modify the profile, activate it,
then verify with ip addr show and ip route show.
Configuring a Static IPv6 Address
IPv6 configuration uses the same nmcli connection modify pattern
with ipv6.* properties instead of ipv4.*.
# Set static IPv6 — all properties in one command
$ sudo nmcli connection modify ens3 \
ipv6.method manual \
ipv6.addresses "2001:db8:1::200/64" \
ipv6.gateway "2001:db8:1::1" \
ipv6.dns "2001:4860:4860::8888"
# Activate and verify
$ sudo nmcli connection up ens3
$ ip addr show ens3
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> ...
inet 192.168.1.200/24 ... ens3
inet6 2001:db8:1::200/64 scope global noprefixroute
# Dual-stack: IPv4 and IPv6 can both be configured on the same interface
# Both method settings are independent
$ sudo nmcli connection modify ens3 \
ipv4.method manual \
ipv4.addresses 192.168.1.200/24 \
ipv4.gateway 192.168.1.1 \
ipv6.method manual \
ipv6.addresses "2001:db8:1::200/64" \
ipv6.gateway "2001:db8:1::1"
IPv4 vs IPv6 Address Formats
| Feature | IPv4 | IPv6 |
|---|---|---|
| Address length | 32 bits — 4 decimal octets | 128 bits — 8 groups of 4 hex digits |
| Example address | 192.168.1.200 | 2001:db8:1::200 |
| Subnet notation | 192.168.1.0/24 (CIDR) | 2001:db8:1::/64 (prefix length) |
| Loopback | 127.0.0.1 | ::1 |
| Link-local | 169.254.x.x (APIPA) | fe80::/10 (always present) |
| Abbreviation rules | No abbreviation | Leading zeros dropped; consecutive zero groups → :: |
| Typical host prefix | /24 (254 hosts), /32 (single host) | /64 (network), /128 (single host) |
| nmcli property | ipv4.addresses | ipv6.addresses |
Leading zeros in each group can be dropped: 2001:0db8:0001:0000:0000:0000:0000:0200
becomes 2001:db8:1::200. The :: replaces one contiguous sequence
of all-zero groups — it can only appear once in an address.
Creating a New Connection Profile
When no profile exists for an interface, create one with
nmcli connection add.
# Create a new static IPv4 connection profile
$ sudo nmcli connection add \
type ethernet \
con-name "static-ens3" \
ifname ens3 \
ipv4.method manual \
ipv4.addresses 192.168.1.200/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8" \
ipv6.method disabled
Connection 'static-ens3' (uuid) successfully added.
# Activate the new profile
$ sudo nmcli connection up static-ens3
# Deactivate an old DHCP connection if present
$ sudo nmcli connection down ens3
# Delete a connection profile
$ sudo nmcli connection delete old-connection
On the exam, the interface typically already has a DHCP connection profile.
It is usually simpler to nmcli connection modify the existing
profile to static rather than creating a new one.
nmcli Interactive Mode
nmcli connection edit opens an interactive shell for modifying
a connection with tab completion — useful when learning property names.
# Open the interactive editor for a connection
$ sudo nmcli connection edit ens3
===| nmcli interactive connection editor |===
Editing existing '802-3-ethernet' connection: 'ens3'
Type 'help' or '?' for available commands.
Type 'print' to show all the connection properties.
Type 'describe [<setting>.<prop>]' for detailed property description.
There are 3 optional settings for 802-3-ethernet.
nmcli> set ipv4.addresses 192.168.1.200/24
nmcli> set ipv4.method manual
nmcli> set ipv4.gateway 192.168.1.1
nmcli> save
nmcli> quit
# Activate after saving
$ sudo nmcli connection up ens3
Configuring the Hostname
The system hostname is set with hostnamectl — a related network
configuration task often tested alongside IP configuration.
# View the current hostname
$ hostnamectl
Static hostname: servera.example.com
Icon name: computer-vm
Chassis: vm
Machine ID: abc123...
Boot ID: def456...
Operating System: Red Hat Enterprise Linux 9.3
CPE OS Name: cpe:/o:redhat:enterprise_linux:9
Kernel: Linux 5.14.0-362.24.1.el9_3.x86_64
Architecture: x86-64
# Set a new static hostname
$ sudo hostnamectl set-hostname servera.example.com
# Verify
$ hostname
servera.example.com
# Hostname is stored in /etc/hostname
$ cat /etc/hostname
servera.example.com
Static — set by administrator, stored in /etc/hostname,
survives reboots. Transient — assigned by DHCP or NetworkManager at
runtime, not persistent. Pretty — free-form label for display only.
The exam always asks for the static hostname.
Verifying Network Configuration
# Verify assigned IP addresses
$ ip addr show ens3
2: ens3: ... UP ...
inet 192.168.1.200/24 brd 192.168.1.255 scope global noprefixroute ens3
inet6 2001:db8:1::200/64 scope global noprefixroute
# Verify routing table (includes default gateway)
$ ip route show
default via 192.168.1.1 dev ens3 proto static metric 100
# Verify IPv6 routing
$ ip -6 route show
# Verify DNS configuration
$ cat /etc/resolv.conf
# Test connectivity to gateway
$ ping -c 4 192.168.1.1
# Test DNS resolution
$ ping -c 2 www.example.com
# Show full connection profile details
$ nmcli connection show ens3 | grep ipv4
nmcli connection show ens3 shows what is saved in the profile.
ip addr show ens3 shows what is currently active on the interface.
After nmcli connection up, both should match.
Connection Profile Files
NetworkManager stores connection profiles as key-value files in
/etc/NetworkManager/system-connections/.
# List connection profile files
$ ls /etc/NetworkManager/system-connections/
ens3.nmconnection
# View a connection profile file (read-only for reference)
$ sudo cat /etc/NetworkManager/system-connections/ens3.nmconnection
[connection]
id=ens3
uuid=abc123-de45-fg67-hi89-jk0123456789
type=ethernet
interface-name=ens3
[ethernet]
[ipv4]
address1=192.168.1.200/24,192.168.1.1
dns=8.8.8.8;8.8.4.4;
method=manual
[ipv6]
addr-gen-mode=eui64
method=auto
[proxy]
While the profile files are human-readable, editing them directly requires
running sudo nmcli connection reload afterward and may cause
parsing errors. Always use nmcli connection modify instead.
Network Configuration Quick Reference
| Task | Command |
|---|---|
| Show all interfaces and IPs | ip addr show |
| Show routing table | ip route show |
| Show connection profiles | nmcli connection show |
| Show profile details | nmcli connection show CONNAME |
| Set static IPv4 address | sudo nmcli con mod CONNAME ipv4.addresses ADDR/PREFIX |
| Set IPv4 gateway | sudo nmcli con mod CONNAME ipv4.gateway GW |
| Set IPv4 DNS | sudo nmcli con mod CONNAME ipv4.dns "DNS1,DNS2" |
| Set to static (not DHCP) | sudo nmcli con mod CONNAME ipv4.method manual |
| Set static IPv6 address | sudo nmcli con mod CONNAME ipv6.addresses ADDR/PREFIX |
| Set IPv6 gateway | sudo nmcli con mod CONNAME ipv6.gateway GW6 |
| Activate a connection | sudo nmcli connection up CONNAME |
| Deactivate a connection | sudo nmcli connection down CONNAME |
| Set the hostname | sudo hostnamectl set-hostname HOSTNAME |
| Test gateway connectivity | ping -c 4 GATEWAY |
Common Mistakes
| Mistake | What goes wrong | Correct approach |
|---|---|---|
Using ip addr add instead of nmcli |
Address is active now but disappears after reboot — task fails grading | Always use nmcli connection modify for persistent configuration |
Forgetting ipv4.method manual |
DHCP overrides the static address — the configured address is never used | Always set ipv4.method manual when assigning a static address |
Forgetting nmcli connection up after modifying |
Profile is updated but the interface still uses the old configuration | Always run sudo nmcli connection up CONNAME to apply changes |
| Not including the prefix length (/24) | NetworkManager uses /32 by default — no subnet routing, connectivity fails | Always specify the full CIDR notation: 192.168.1.200/24 |
| Referencing the wrong connection name | "Error: unknown connection 'eth0'" — the profile name may differ from the device name | Run nmcli connection show first to get the exact profile NAME |
| IPv6 method left as auto when a static address is required | IPv6 auto-configuration assigns additional addresses alongside the static one | Set ipv6.method manual when assigning a static IPv6 address |
Complete Static Configuration Workflow
The exam scenario: configure ens3 with a static IPv4 address
192.168.1.200/24, gateway 192.168.1.1, and
DNS 8.8.8.8.
# Step 1: Identify the connection name
$ nmcli connection show
NAME UUID TYPE DEVICE
ens3 ... ethernet ens3
# Step 2: Set all IPv4 properties at once
$ sudo nmcli connection modify ens3 \
ipv4.method manual \
ipv4.addresses 192.168.1.200/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8"
# Step 3: Activate the connection
$ sudo nmcli connection up ens3
# Step 4: Verify — all three checks
$ ip addr show ens3 # confirms IP address
$ ip route show # confirms gateway
$ cat /etc/resolv.conf # confirms DNS
# Optional: test connectivity
$ ping -c 2 192.168.1.1 # gateway reachable?
Knowledge Check
Answer these before moving to the next slide.
- Why must you use
nmcliinstead ofip addr addto configure a static IP address on RHEL 9? - Write the single
nmclicommand to configure the connectionens3with static IPv4 address10.0.0.50/24, gateway10.0.0.1, and DNS10.0.0.53. - After modifying the connection profile, what command applies the changes to the live interface?
- Write the command to verify that the static IP address
10.0.0.50is currently active onens3. - Write the nmcli command to configure a static IPv6 address
2001:db8::50/64with gateway2001:db8::1on connectionens3. - What is the difference between what
nmcli connection show ens3displays and whatip addr show ens3displays?
Knowledge Check — Answers
ip addr addmodifies only the kernel's live network state — the address is lost at the next reboot because it is not saved anywhere persistent.nmcliwrites to the NetworkManager connection profile file, which is read at every boot, making the configuration persistent across reboots.sudo nmcli connection modify ens3 ipv4.method manual ipv4.addresses 10.0.0.50/24 ipv4.gateway 10.0.0.1 ipv4.dns "10.0.0.53"sudo nmcli connection up ens3— this reactivates the connection using the updated profile, applying the new static IP, gateway, and DNS to the live network interface.ip addr show ens3— examine theinetline in the output and confirm10.0.0.50/24is listed as the address.sudo nmcli connection modify ens3 ipv6.method manual ipv6.addresses "2001:db8::50/64" ipv6.gateway "2001:db8::1"
Then activate:sudo nmcli connection up ens3nmcli connection show ens3displays what is saved in the NetworkManager profile file — the intended configuration.ip addr show ens3displays what is currently active in the kernel — the running configuration. Afternmcli connection up, both should match. If they differ, the profile has been modified but not yet activated.
Key Takeaways
-
Use
nmclifor persistent configuration — notip.ip addr addis temporary and lost at reboot.nmcli connection modifywrites to the NetworkManager profile, which is read at every boot. Identify the connection name withnmcli connection showfirst. -
Static IPv4 requires four properties: method, address, gateway, DNS.
ipv4.method manualdisables DHCP.ipv4.addresses ADDR/PREFIXsets the address.ipv4.gateway GWsets the default route.ipv4.dns "DNS"sets the resolver. All four in onenmcli con modcommand. -
Activate with
nmcli connection up CONNAMEafter every modify. Profile changes do not take effect until the connection is reactivated. Verify withip addr show(address),ip route show(gateway), andcat /etc/resolv.conf(DNS). -
IPv6 uses the same pattern with
ipv6.*properties.ipv6.method manual,ipv6.addresses ADDR/PREFIX,ipv6.gateway GW6. IPv4 and IPv6 can both be configured on the same interface simultaneously (dual-stack). Both require their ownmethod manual.
Graded Lab
- Run
nmcli connection showto identify the connection name for your primary network interface. Runip addr showandip route showto record the baseline IP address and gateway. - Configure a static IPv4 address using
nmcli connection modifywith all four required properties (method manual, address, gateway, dns). Use an address appropriate for your lab network (provided by the instructor). - Activate the connection with
nmcli connection up. Verify withip addr show(confirm the static address),ip route show(confirm the gateway), andcat /etc/resolv.conf(confirm DNS). - Add a static IPv6 address to the same connection using
ipv6.method manual,ipv6.addresses, andipv6.gateway. Activate and verify withip addr show— confirm both the IPv4 and IPv6 addresses appear. - Set the system hostname to
labserver.example.comusinghostnamectl set-hostname. Verify withhostnameandcat /etc/hostname. - Reboot the system. After reboot, run
ip addr show,ip route show, andhostnameto confirm all settings persisted. This confirms that nmcli — not ip — was used correctly.
"Configure IPv4 and IPv6 addresses."
Use nmcli con mod CONNAME ipv4.method manual ipv4.addresses A/P ipv4.gateway G
ipv4.dns D then nmcli con up CONNAME then verify.