Online admissions open for the SEO, web development and networking & cybersecurity courses. Enquire for the next batch.

Linux Networking: ip, nmcli, Netplan, DNS Resolution and ufw

5 min read Updated By the SkillNewton team

How do you configure networking on Linux?

Linux networking is configured at two levels. The ip command reads and changes interfaces, addresses and routes immediately, but those changes are lost at reboot. Persistent settings are stored by a network manager: NetworkManager, controlled with nmcli, on most desktops and Red Hat family servers, or Netplan on Ubuntu, which writes configuration for systemd-networkd or NetworkManager.

ip from the iproute2 package is the standard tool. It has sub-commands for each object: addr, link, route and neigh. Read-only commands work as a normal user; changes need sudo.

ip addr show                                  # addresses on every interface
ip -br addr                                   # brief one-line-per-interface view
ip link show                                  # state, MTU and MAC address
sudo ip link set dev enp0s3 down              # disable an interface
sudo ip link set dev enp0s3 up

sudo ip addr add 192.168.1.50/24 dev enp0s3   # add an address
sudo ip addr del 192.168.1.50/24 dev enp0s3   # remove it

ip route                                      # routing table
sudo ip route add 10.20.0.0/16 via 192.168.1.254   # static route
sudo ip route replace default via 192.168.1.1      # set the default gateway
ip neigh                                      # ARP / neighbour cache

Interface names such as enp0s3 or ens18 are predictable names based on hardware position; older systems used eth0. Use ip for testing and diagnosis, then save the working settings in the network manager.

The same commands handle IPv6: add -6, as in ip -6 addr and ip -6 route. Every IPv6-enabled interface shows a link-local address starting with fe80::, and global addresses usually come from router advertisements (SLAAC) or DHCPv6. Interface counters from ip -s link show received and transmitted packets, errors and drops, which helps when a link is up but traffic is unreliable. The addressing behind these commands is covered in the IP addressing guide.

NetworkManager and nmcli

NetworkManager stores each configuration as a connection profile attached to a device. It is the default on Fedora, RHEL, Rocky Linux, AlmaLinux and Ubuntu Desktop.

nmcli device status                    # devices and their active connections
nmcli connection show                  # all saved profiles

# Static IPv4 on an existing profile
sudo nmcli connection modify "Wired connection 1" \
    ipv4.method manual \
    ipv4.addresses 192.168.1.50/24 \
    ipv4.gateway 192.168.1.1 \
    ipv4.dns "1.1.1.1 9.9.9.9"
sudo nmcli connection up "Wired connection 1"     # apply the change

# Back to DHCP
sudo nmcli connection modify "Wired connection 1" ipv4.method auto \
    ipv4.addresses "" ipv4.gateway "" ipv4.dns ""

Profile names vary, so check them with nmcli connection show first. Changes are written to disk and survive reboots. nmtui offers a text menu for the same tasks.

Netplan on Ubuntu Server

Ubuntu uses Netplan: you describe the network in YAML files under /etc/netplan/, and Netplan generates configuration for a renderer, usually systemd-networkd on servers. Indentation matters in YAML, so use spaces only.

# /etc/netplan/50-static.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: false
      addresses:
        - 192.168.1.50/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [1.1.1.1, 9.9.9.9]
sudo chmod 600 /etc/netplan/50-static.yaml
sudo netplan try        # applies and rolls back unless you confirm
sudo netplan apply      # applies permanently

Name resolution: /etc/hosts, resolv.conf and systemd-resolved

The order in which Linux looks up names is set by the hosts: line in /etc/nsswitch.conf, typically checking files (the hosts file) before dns.

# /etc/hosts
127.0.0.1      localhost
192.168.1.20   fileserver.lab.local fileserver

$ cat /etc/resolv.conf
nameserver 127.0.0.53
options edns0 trust-ad

$ resolvectl status          # real upstream DNS servers per interface
$ resolvectl query example.com
$ sudo resolvectl flush-caches

On systems running systemd-resolved, including Ubuntu, /etc/resolv.conf points to a local stub resolver at 127.0.0.53 and is managed automatically. Editing it by hand does not last; set DNS servers in Netplan or nmcli instead, and use resolvectl status to see the servers actually in use. DNS concepts are explained in how DNS works.

Checking services and the host firewall: ss and ufw

sudo ss -tulpn                   # listening TCP and UDP ports with processes
ss -tn state established         # active TCP sessions
sudo ufw status verbose          # firewall state and default policies
sudo ufw allow from 192.168.1.0/24 to any port 22 proto tcp

Compare the ports in ss with the firewall policy: every listening service should either be needed and allowed, or be stopped. Rule order and default deny are explained in the firewalls guide.

Configuring a server address, step by step

  1. Find the interface name with ip -br link.
  2. Record the current address, gateway and DNS servers in case you need to roll back.
  3. Write the new settings in Netplan or with nmcli.
  4. Apply with netplan try or nmcli connection up.
  5. Verify with ip addr, ip route, resolvectl status and a ping to the gateway.
  6. Set the host name with sudo hostnamectl set-hostname and update /etc/hosts if needed.

Practical exercise: move a VM from DHCP to a static address

Use an Ubuntu Server or Rocky Linux virtual machine you own, with console access in case the network drops.

  1. Note the DHCP-assigned address, gateway and DNS servers.
  2. Choose a free static address on the same subnet, outside the DHCP pool.
  3. Configure it with Netplan on Ubuntu or nmcli on Rocky Linux, including two DNS servers.
  4. Reboot and confirm the address, default route and DNS servers persist.
  5. Add a hosts file entry for another lab machine and ping it by name.
  6. Allow SSH from your subnet only with ufw or firewalld, and test it from another machine.

You are done when the server keeps its settings after a reboot and you can explain which file or profile holds each one. Linux server labs are part of the Networking Foundation course, and the diagnostic tools are collected in network commands for Windows and Linux.

Common mistakes

  • Configuring an address with ip addr add and expecting it to survive a reboot.
  • Editing /etc/resolv.conf by hand on a system where systemd-resolved manages it.
  • Using tabs or wrong indentation in a Netplan YAML file.
  • Running netplan apply on a remote server without testing first with netplan try.
  • Choosing a static address inside the DHCP pool, which causes address conflicts later.

Frequently asked questions

Should I use NetworkManager or systemd-networkd?

Follow the distribution default. Desktops and Red Hat family servers use NetworkManager; Ubuntu Server uses Netplan with systemd-networkd. Mixing two managers on the same interface causes settings to be overwritten.

Where is the old /etc/network/interfaces file?

It belongs to the ifupdown system, which Debian still supports. Ubuntu replaced it with Netplan, so on current Ubuntu releases the file is normally absent or unused.

How do I make a static route permanent?

Add it to the routes list in Netplan, or with nmcli connection modify NAME +ipv4.routes "10.20.0.0/16 192.168.1.254". Routes added with ip route add disappear at reboot; see routing and switching for how routes are chosen.

Why does my server have an address I did not configure?

It is usually an IPv6 link-local or SLAAC address created automatically, or an address from a container or virtual bridge such as docker0. Check the interface name in ip -br addr before removing anything.

Want to Learn This Properly?

The Networking & Cybersecurity: Foundation & Practical Implementation (Online) turns guides like this into practised skills, with projects on real websites.

WhatsApp Call Us Now

Free counselling

Send an Enquiry

Tell us which course you are interested in. We reply by email or phone with the next batch and how to enrol.

Protected by reCAPTCHA. Google Privacy and Terms apply.

We reply by email or phone within working hours. No spam.