Linux Networking Configuration
Configuring Linux networking has two layers: temporary changes with the ip command (gone after reboot) and persistent config via netplan (Ubuntu) or nmcli (RHEL/Fedora). Here are both, plus DNS — with copy-paste examples.
Temporary: the ip command
sudo ip addr add 192.168.1.50/24 dev eth0 # add an IP sudo ip addr del 192.168.1.50/24 dev eth0 # remove it sudo ip link set eth0 up # bring interface up sudo ip route add default via 192.168.1.1 # default gateway sudo ip route add 10.10.0.0/16 via 192.168.1.254 # static route
Perfect for testing and troubleshooting — but everything here vanishes on reboot. Verify with ip addr and ip route (full list in Linux commands for network engineers).
Persistent on Ubuntu: netplan
Ubuntu reads YAML from /etc/netplan/. A static-IP example:
network:
version: 2
ethernets:
eth0:
addresses: [192.168.1.50/24]
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [1.1.1.1, 8.8.8.8]Apply with sudo netplan apply. YAML is indentation-sensitive — two spaces, never tabs (see YAML explained).
Persistent on RHEL/Fedora: nmcli
sudo nmcli con mod eth0 ipv4.addresses 192.168.1.50/24 \ ipv4.gateway 192.168.1.1 ipv4.dns "1.1.1.1 8.8.8.8" ipv4.method manual sudo nmcli con up eth0
NetworkManager owns the config; nmcli con show lists connections.
DNS: where it actually lives now
/etc/resolv.conf is often a symlink managed by systemd-resolved — editing it directly gets overwritten. Set DNS in netplan/nmcli as above, and check what is really in use with resolvectl status. Test resolution with dig.
The verification habit
After any change, run the same ladder you would on any host: ip addr → ip route → ping gateway → ping 8.8.8.8 → dig google.com. It is the layered method in five commands.
Frequently asked questions
How do I set a static IP on Linux?
Temporarily: sudo ip addr add 192.168.1.50/24 dev eth0. Persistently: a netplan YAML file on Ubuntu (then netplan apply) or nmcli con mod on RHEL/Fedora.
Why does my IP change back after reboot?
The ip command makes runtime-only changes. Persistence requires the distro's config system — netplan on Ubuntu, NetworkManager (nmcli) on RHEL/Fedora.
How do I change DNS servers on Linux?
Set nameservers in netplan or via nmcli (ipv4.dns). Editing /etc/resolv.conf directly usually gets overwritten by systemd-resolved; check the live config with resolvectl status.
How do I add a static route on Linux?
Temporarily: sudo ip route add 10.10.0.0/16 via 192.168.1.254. Persistently: add it under routes: in netplan, or with nmcli ipv4.routes.
Related articles
Want hands-on training?
Learn this on real Cisco lab devices with placement support at Attila Technologies, Ahmedabad.