Static networking.
nmcli, hostnamectl, and /etc/hosts.
server1 is moving to a new VLAN tomorrow and needs a static IP, gateway, DNS, a persistent hostname, and a local hosts entry, all set with nmcli and verified with ip and ss.
The network team is moving server1 into a new VLAN tomorrow morning and needs it pinned to a static address before the cutover: 192.168.50.100/24, gateway 192.168.50.1, DNS 192.168.50.10 with 1.1.1.1 behind it, the hostname staying server1 but set so it survives a reboot, and a db.internal entry so the box can reach the database without waiting on DNS. All of it through nmcli, because that is what the exam expects and what a change ticket can actually review afterward.
Two things sink people here. The settings do not take effect the moment you type them, they wait for the connection to go down and come back up. And if you leave off ipv4.method manual, DHCP wakes up on the next reconnect and quietly stamps over everything you just set.
The ticket
nmcli device status # find your interface name nmcli connection show ip a
Concept review. nmcli and the ip tools.
man nmcli man hostnamectl
nmcli device status lists interfaces, nmcli connection show lists the connection profiles. The ip commands are read-only views: ip a shows addresses, ip r shows routes. ss -tlnp shows listening TCP sockets. You configure with NetworkManager and confirm with these.
The pattern is modify then apply. Set a property, then bring the connection up to make it take effect.
nmcli connection modify NAME PROPERTY VALUE nmcli connection up NAME # the ipv4 properties you need: ipv4.addresses 192.168.1.100/24 # CIDR, not a separate netmask ipv4.gateway 192.168.1.1 ipv4.dns "8.8.8.8 1.1.1.1" # multiple servers, space separated, quoted ipv4.method manual # disables DHCP; without it DHCP can override
Identify the active connection
Get the exact connection name and interface first, and store them so the later commands are copy-paste safe. Adjust these to what your box actually shows.
nmcli device status nmcli connection show CONN="Wired connection 1" # your actual profile name IFACE="enp0s3" # your actual interface
Apply the static IP config
Set all four properties in one command, then bounce the connection to apply.
sudo nmcli connection modify "$CONN" \
ipv4.addresses 192.168.50.100/24 \
ipv4.gateway 192.168.50.1 \
ipv4.dns "192.168.50.10 1.1.1.1" \
ipv4.method manual
sudo nmcli connection down "$CONN"
sudo nmcli connection up "$CONN"
ip a show $IFACE
ip r
cat /etc/resolv.confSet a persistent hostname
hostnamectl set-hostname writes /etc/hostname so it survives a reboot, unlike the old hostname command which only changes the running value.
hostnamectl sudo hostnamectl set-hostname server1 hostnamectl cat /etc/hostname
A local /etc/hosts entry
/etc/hosts is read directly by the resolver on every lookup, so a new entry works immediately with no service restart.
sudo cp /etc/hosts /etc/hosts.bak echo "192.168.50.20 db.internal" | sudo tee -a /etc/hosts getent hosts db.internal # should return the mapping
Verify with ip and ss
Confirm every piece landed. The three you actually read are the address, the default route, and the local resolution.
ip -4 a show $IFACE # inet 192.168.50.100/24 brd 192.168.50.255 scope global noprefixroute enp0s3 ip r # default via 192.168.50.1 dev enp0s3 proto static metric 100 # 192.168.50.0/24 dev enp0s3 proto kernel scope link src 192.168.50.100 getent hosts db.internal # 192.168.50.20 db.internal
Exam questions
Write the command first.
Q1. Display all NetworkManager connection profiles.
Q2. Configure the primary profile with static IP 10.10.10.50/24, gateway 10.10.10.1, DNS 10.10.10.5, using nmcli only.
Q3. Add a permanent /etc/hosts entry mapping app.internal to 10.10.10.80 and verify resolution without restarting a service.
Answers.
# A1
nmcli connection show
# A2
CONN="Wired connection 1"
sudo nmcli connection modify "$CONN" ipv4.addresses 10.10.10.50/24 \
ipv4.gateway 10.10.10.1 ipv4.dns 10.10.10.5 ipv4.method manual
sudo nmcli connection down "$CONN"; sudo nmcli connection up "$CONN"
# A3
echo "10.10.10.80 app.internal" | sudo tee -a /etc/hosts
getent hosts app.internalFinal checklist: confirm everything works
If every check passes, the ticket is done.
# 1. static IP, gateway, DNS applied ip a; ip r; cat /etc/resolv.conf # 2. hostname persisted hostnamectl; cat /etc/hostname # 3. db.internal resolves locally getent hosts db.internal # 4. all three exam commands written from scratch # 5. tracker entry checked off
Reply to ops1: server1 is set to 192.168.50.100/24, gateway 192.168.50.1, DNS 192.168.50.10 plus 1.1.1.1. Hostname persisted with hostnamectl, and db.internal resolves via /etc/hosts. Ready for the VLAN cutover.