Linux Network Configuration: ip, nmcli, and Netplan Guide

Linux Network Configuration: ip, nmcli, and Netplan Guide

✅ Tested on Ubuntu 26.04 LTS, Debian 12, and RHEL 9 — Last updated: June 2026

Linux network configuration spans a wide range of tools depending on your distribution and whether you're on a desktop or server. ip is the modern command for viewing and managing interfaces, routes, and addresses. nmcli (NetworkManager CLI) handles persistent network connections on most modern desktops and servers. Netplan is Ubuntu's declarative network configuration layer that sits on top of NetworkManager or systemd-networkd. This guide covers all three, plus DNS configuration, static IPs, VLANs, network bonding, and troubleshooting tools.

Contents
  1. ip Command Basics
  2. View IP Addresses and Interfaces
  3. Routing Table
  4. NetworkManager with nmcli
  5. Set a Static IP
  6. Netplan (Ubuntu)
  7. systemd-networkd
  8. DNS Configuration
  9. Diagnostic Tools
  10. Firewall: ufw and firewalld
  11. Network Bonding
  12. VLANs
  13. Wi-Fi from the Command Line
  14. Troubleshooting
  15. Frequently Asked Questions
    1. What's the difference between ip and ifconfig?
    2. Changes with ip command don't survive reboot — how do I make them permanent?
    3. Further Reading

ip Command Basics

The ip command from the iproute2 package replaced the old ifconfig, route, and arp commands. It's installed by default on every modern Linux distribution.

# ip syntax: ip [OPTIONS] OBJECT COMMAND
# Objects: link, addr, route, neigh, rule, tunnel, maddr

# Common options:
# -c      colorize output
# -s      statistics
# -4      IPv4 only
# -6      IPv6 only
# -br     brief output (table format)
# -j      JSON output

# Quick overview of all interfaces:
ip -br link show
# lo               UNKNOWN        00:00:00:00:00:00 
# eth0             UP             52:54:00:12:34:56 
# wlan0            DOWN           aa:bb:cc:dd:ee:ff 

View IP Addresses and Interfaces

# Show all addresses:
ip addr show
ip a    # short form

# Show specific interface:
ip addr show eth0
ip addr show dev eth0

# Brief format (all interfaces with their IPs):
ip -br addr show
# lo               UNKNOWN        127.0.0.1/8 ::1/128
# eth0             UP             192.168.1.10/24 fe80::5054:ff:fe12:3456/64

# Add a temporary IP address (lost on reboot):
sudo ip addr add 192.168.1.20/24 dev eth0

# Remove an IP address:
sudo ip addr del 192.168.1.20/24 dev eth0

# Bring interface up/down:
sudo ip link set eth0 up
sudo ip link set eth0 down

# Flush all addresses from an interface:
sudo ip addr flush dev eth0

Routing Table

# Show routing table:
ip route show
ip r    # short form
# default via 192.168.1.1 dev eth0 proto dhcp
# 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10

# Show route for a specific destination:
ip route get 8.8.8.8
# 8.8.8.8 via 192.168.1.1 dev eth0 src 192.168.1.10

# Add a static route:
sudo ip route add 10.0.0.0/8 via 192.168.1.254 dev eth0

# Delete a route:
sudo ip route del 10.0.0.0/8

# Add/change default gateway:
sudo ip route add default via 192.168.1.1
sudo ip route change default via 192.168.1.254

# Show neighbor table (ARP):
ip neigh show

NetworkManager with nmcli

NetworkManager manages persistent connections and runs on most distributions. Changes made with nmcli survive reboots.

# Check NetworkManager status:
systemctl status NetworkManager

# List all connections:
nmcli connection show
# NAME           UUID                                  TYPE      DEVICE
# Wired 1        a1b2c3d4-...                          ethernet  eth0
# MyWifi         e5f6g7h8-...                          wifi      wlan0

# Show active connections:
nmcli connection show --active

# Show device status:
nmcli device status
nmcli dev status    # short form

# Show details of a connection:
nmcli connection show "Wired 1"

# Bring connection up/down:
nmcli connection up "Wired 1"
nmcli connection down "Wired 1"

# Reload all connections (after manual file edits):
nmcli connection reload

Set a Static IP

This is the most common network task for server administration. Both nmcli and Netplan methods are shown.

# METHOD 1: nmcli (for systems using NetworkManager)

# Modify existing connection to use static IP:
nmcli connection modify "Wired 1" 
  ipv4.method manual 
  ipv4.addresses 192.168.1.50/24 
  ipv4.gateway 192.168.1.1 
  ipv4.dns "8.8.8.8,1.1.1.1"

# Apply the changes:
nmcli connection down "Wired 1" && nmcli connection up "Wired 1"

# Or create a new connection with static IP:
nmcli connection add 
  type ethernet 
  con-name "static-eth0" 
  ifname eth0 
  ipv4.method manual 
  ipv4.addresses 192.168.1.50/24 
  ipv4.gateway 192.168.1.1 
  ipv4.dns "8.8.8.8,1.1.1.1"

nmcli connection up "static-eth0"

# Revert to DHCP:
nmcli connection modify "Wired 1" ipv4.method auto ipv4.addresses "" ipv4.gateway "" ipv4.dns ""
nmcli connection up "Wired 1"

Netplan (Ubuntu)

Ubuntu uses Netplan as a declarative configuration layer. Config files live in /etc/netplan/ and are YAML format. Netplan generates configuration for either NetworkManager (desktop) or systemd-networkd (server).

# Show current Netplan config:
cat /etc/netplan/*.yaml

# Typical Netplan file (Ubuntu Server 24.04):
sudo nano /etc/netplan/00-installer-config.yaml

# Static IP example:
network:
  version: 2
  renderer: networkd  # or: networkmanager
  ethernets:
    eth0:
      dhcp4: no
      addresses:
        - 192.168.1.50/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 1.1.1.1]
        search: [example.com]

# DHCP example:
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: yes

# Apply config (test first):
sudo netplan try    # apply temporarily, auto-reverts in 120s if not confirmed
sudo netplan apply  # apply permanently

# Generate config files (without applying):
sudo netplan generate

# Debug:
sudo netplan --debug apply

systemd-networkd

systemd-networkd is a lightweight alternative to NetworkManager, common on servers and minimal installations.

# Enable systemd-networkd:
sudo systemctl enable --now systemd-networkd
sudo systemctl enable --now systemd-resolved

# Create a network configuration file:
sudo nano /etc/systemd/network/10-eth0.network

# Static IP configuration:
[Match]
Name=eth0

[Network]
Address=192.168.1.50/24
Gateway=192.168.1.1
DNS=8.8.8.8
DNS=1.1.1.1

# DHCP configuration:
[Match]
Name=eth0

[Network]
DHCP=yes

# Restart to apply:
sudo systemctl restart systemd-networkd

# Check status:
networkctl status eth0
networkctl list

DNS Configuration

# Check current DNS servers:
resolvectl status
cat /etc/resolv.conf

# Test DNS resolution:
resolvectl query example.com
nslookup example.com
dig example.com

# Check which DNS server is being used:
resolvectl dns eth0

# Set DNS per connection (nmcli):
nmcli connection modify "Wired 1" ipv4.dns "1.1.1.1,8.8.8.8"
nmcli connection up "Wired 1"

# Set DNS in /etc/resolv.conf (manual, often overwritten by NetworkManager):
sudo nano /etc/resolv.conf
# nameserver 1.1.1.1
# nameserver 8.8.8.8
# search localdomain

# Prevent NetworkManager from overwriting resolv.conf:
sudo nano /etc/NetworkManager/NetworkManager.conf
# [main]
# dns=none

# Test DNS speed (compare servers):
dig @8.8.8.8 example.com | grep "Query time"
dig @1.1.1.1 example.com | grep "Query time"
dig @9.9.9.9 example.com | grep "Query time"

Diagnostic Tools

# Install common tools:
sudo apt install net-tools iproute2 iputils-ping traceroute dnsutils nmap curl wget -y

# Test connectivity:
ping -c 4 8.8.8.8        # test to IP (bypass DNS)
ping -c 4 example.com    # test DNS + connectivity

# Trace route to destination:
traceroute 8.8.8.8
mtr 8.8.8.8    # real-time traceroute (install: sudo apt install mtr)

# Check open ports:
ss -tlnp    # TCP listening ports with process names
ss -tulnp   # TCP + UDP
# Columns: State, Recv-Q, Send-Q, Local Address:Port, Peer Address:Port, Process

# Scan ports on remote host:
nmap -p 22,80,443 192.168.1.1
nmap -sV 192.168.1.1    # service version detection

# Bandwidth test:
sudo apt install iperf3
# Server side:  iperf3 -s
# Client side:  iperf3 -c 192.168.1.1

# Check network interface statistics:
ip -s link show eth0
cat /proc/net/dev
ethtool eth0    # detailed hardware info

# Monitor network traffic:
sudo apt install iftop nethogs
sudo iftop -i eth0    # per-connection bandwidth
sudo nethogs eth0     # bandwidth per process

Firewall: ufw and firewalld

# ufw (Ubuntu/Debian):
sudo ufw status
sudo ufw enable
sudo ufw allow ssh
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw deny 23/tcp
sudo ufw status numbered
sudo ufw delete 3    # delete rule #3

# Common service rules:
sudo ufw allow http     # port 80
sudo ufw allow https    # port 443
sudo ufw allow 'Nginx Full'
sudo ufw allow from 192.168.1.0/24 to any port 22

# firewalld (Fedora/RHEL/CentOS):
sudo systemctl enable --now firewalld
sudo firewall-cmd --state
sudo firewall-cmd --list-all
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --add-service=https --permanent
sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --reload

Network Bonding

Network bonding (also called link aggregation or teaming) combines multiple NICs for redundancy or increased throughput.

# Create a bond interface using nmcli:
# mode 1 = active-backup (failover)
# mode 4 = 802.3ad LACP (requires switch support)

# Create bond master:
nmcli connection add 
  type bond 
  con-name bond0 
  ifname bond0 
  bond.options "mode=active-backup,miimon=100"

# Add slave interfaces:
nmcli connection add 
  type ethernet 
  slave-type bond 
  con-name bond0-slave1 
  ifname eth0 
  master bond0

nmcli connection add 
  type ethernet 
  slave-type bond 
  con-name bond0-slave2 
  ifname eth1 
  master bond0

# Set IP on bond:
nmcli connection modify bond0 ipv4.method manual ipv4.addresses 192.168.1.50/24 ipv4.gateway 192.168.1.1

# Bring up bond:
nmcli connection up bond0

# Check bond status:
cat /proc/net/bonding/bond0

VLANs

# Create VLAN interface (VLAN 100 on eth0):
sudo ip link add link eth0 name eth0.100 type vlan id 100
sudo ip link set eth0.100 up
sudo ip addr add 10.0.100.10/24 dev eth0.100

# Persistent VLAN with nmcli:
nmcli connection add 
  type vlan 
  con-name "vlan100" 
  ifname eth0.100 
  vlan.parent eth0 
  vlan.id 100 
  ipv4.method manual 
  ipv4.addresses 10.0.100.10/24

nmcli connection up vlan100

# Netplan VLAN configuration:
network:
  version: 2
  vlans:
    eth0.100:
      id: 100
      link: eth0
      addresses:
        - 10.0.100.10/24

Wi-Fi from the Command Line

# List available Wi-Fi networks:
nmcli device wifi list

# Connect to a Wi-Fi network:
nmcli device wifi connect "NetworkName" password "yourpassword"

# Connect to hidden network:
nmcli device wifi connect "HiddenNetwork" password "yourpassword" hidden yes

# Show saved Wi-Fi connections:
nmcli connection show | grep wifi

# Check Wi-Fi device details:
nmcli device show wlan0

# Scan for networks manually:
nmcli device wifi rescan
nmcli device wifi list

Troubleshooting

ProblemDiagnostic commandCommon fix
No IP addressip addr showsudo dhclient eth0 or check DHCP service
No default routeip route showsudo ip route add default via GATEWAY
DNS not resolvingdig @8.8.8.8 example.comSet DNS manually in nmcli or /etc/resolv.conf
Can't reach gatewayping GATEWAY_IPCheck physical link, switch config
Interface downip link show eth0sudo ip link set eth0 up
Firewall blockingsudo ufw statusAdd specific allow rule
High latencymtr 8.8.8.8Check for packet loss at each hop
Wrong DNSresolvectl statusSet per-connection DNS with nmcli
# Common diagnostic sequence:
# 1. Is the interface up?
ip link show eth0

# 2. Does it have an IP?
ip addr show eth0

# 3. Is there a default route?
ip route show

# 4. Can we reach the gateway?
ping -c 3 $(ip route | grep default | awk '{print $3}')

# 5. Can we reach the internet?
ping -c 3 8.8.8.8

# 6. Does DNS work?
ping -c 3 google.com

# 7. Any firewall issues?
sudo ufw status verbose

# 8. Check NetworkManager logs:
journalctl -u NetworkManager -n 50 --no-pager

Frequently Asked Questions

What's the difference between ip and ifconfig?

ifconfig is from the older net-tools package and is deprecated on most distributions. ip from iproute2 is the modern replacement and supports features ifconfig doesn't — namespaces, policy routing, multiple addresses per interface. Use ip for all new scripts and configs. If ifconfig isn't installed, install net-tools for legacy compatibility: sudo apt install net-tools.

Changes with ip command don't survive reboot — how do I make them permanent?

Changes made directly with ip are temporary (in-memory). For permanent changes, use nmcli to create or modify connections (Ubuntu/Debian desktop and server), edit Netplan files in /etc/netplan/ (Ubuntu Server), or create systemd-networkd files in /etc/systemd/network/ (minimal servers). The right tool depends on which network management stack your distribution uses — check with systemctl status NetworkManager and systemctl status systemd-networkd.

For VPS servers, network configuration is closely tied to setting up firewalls and SSH security. Our SSH guide covers SSH hardening and our Fail2ban guide covers blocking brute-force attacks. If you're configuring a new VPS, the DigitalOcean and Hetzner guides walk through initial server setup including networking from scratch.


Go up

This site uses cookies for analytics and advertising (Google AdSense). By continuing to browse, you accept our use of cookies. Learn more