Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
The quick answer
RHEL, Rocky, Alma (NetworkManager):
nmcli connection show
NAME UUID TYPE DEVICE
ens192 4c1f2a9e-7d1b-4b6e-9a51-0f3e5c2d8a10 ethernet ens192
nmcli connection modify ens192 ipv4.method manual ipv4.addresses 192.0.2.10/24 ipv4.gateway 192.0.2.1 ipv4.dns "192.0.2.53 192.0.2.54"
nmcli connection up ens192Ubuntu Server (netplan): write the file below, then netplan try.
Step by step
- Write down the facts first: interface name (
ip -br link), the new address with prefix (/24), gateway, DNS servers. Check that nobody else uses the address:
ip -br addr
lo UNKNOWN 127.0.0.1/8
ens192 UP 192.0.2.77/24
arping -D -c 3 -I ens192 192.0.2.10arping -D shows no reply when the address is free.
- RHEL: change the connection profile (the settings are saved and survive a reboot):
nmcli connection modify ens192 ipv4.method manual ipv4.addresses 192.0.2.10/24 ipv4.gateway 192.0.2.1 ipv4.dns "192.0.2.53 192.0.2.54" ipv4.dns-search example.com
nmcli connection modify ens192 connection.autoconnect yes
nmcli connection up ens192The profile file is /etc/NetworkManager/system-connections/ens192.nmconnection. A second address: nmcli connection modify ens192 +ipv4.addresses 192.0.2.11/24.
- Ubuntu: write the netplan file (YAML: spaces, no tabs):
network:
version: 2
ethernets:
ens192:
dhcp4: false
addresses:
- 192.0.2.10/24
routes:
- to: default
via: 192.0.2.1
nameservers:
addresses: [192.0.2.53, 192.0.2.54]
search: [example.com]chmod 600 /etc/netplan/60-static.yaml
netplan generate
netplan trynetplan try applies the change and rolls it back after 120 seconds if you do not press Enter — your safety net on a remote server. Remove or change the old file (often 50-cloud-init.yaml) so the two files do not fight.
- Stop cloud-init from writing the network again (cloud and VM images):
network: {config: disabled}- Remote server? Work from the VM or cloud console if you can. Over SSH, change the address in one step (
nmcli connection up,netplan try) and reconnect to the new IP.
Check that it worked
Common problems
| Problem | Cause | Fix |
|---|---|---|
| Old DHCP address still there next to the new one | ipv4.method is still auto, or the DHCP lease is active. | nmcli connection modify … ipv4.method manual, then nmcli connection up. |
| No internet, local network works | Gateway missing or wrong. | ip route; set ipv4.gateway / routes: to: default. |
| Names do not resolve | No DNS servers set. | ipv4.dns / nameservers; check with resolvectl status (Ubuntu) or /etc/resolv.conf. |
| After a reboot the change is gone (Ubuntu) | cloud-init or another netplan file overwrote it. | Disable cloud-init networking; keep one netplan file. |
Permissions for /etc/netplan/... are too open | The netplan file is readable by all. | chmod 600 the file. |
| SSH froze after the change | The address changed under your session. | Reconnect to the new IP; use the console; next time netplan try. |
Go further
- Command pages: nmcli, ip, hostnamectl, ping.
- Next how-tos: Check the DNS records of a domain, Test if a remote port is open, Open a port in the firewall, Add a network route, Create a bridge or VLAN with nmcli.
- Learn it: RHCSA — Set an IPv4 address, RH124 — Static IPv4, RHCSA — Name resolution.
- Many servers at once: cloud-init, Ansible.
- Practise: Lab: give server1 a fixed address, a name and a hosts entry.
1Which command makes a netplan change undo itself if you lose the connection?
netplan try — it rolls back after 120 seconds unless you confirm.
2Where does NetworkManager save the static address on RHEL 9 and 10?
In the connection profile /etc/NetworkManager/system-connections/NAME.nmconnection.