Linux

Network Configuration in Linux: Complete Guide to ip, nmcli, and netplan

This guide will help you master modern network configuration methods in Linux: from basic ip commands to declarative netplan configurations. You'll learn to assign IP addresses, configure gateways and DNS, and diagnose failures.

Updated at February 16, 2026
15-30 min
Medium
FixPedia Team
Применимо к:Ubuntu 20.04+Debian 11+CentOS 8+/RHEL 8+Fedora 35+

Introduction / Why This Matters

Proper network configuration is the foundation of any Linux server or workstation. Without a correctly assigned IP address, gateway, and DNS servers, the system will be unable to communicate with other devices on the local network or the internet. This guide covers the practical aspects of configuration for both temporary changes (for testing) and permanent setup on major modern distributions.

After completing this guide, you will be able to:

  • Manually assign IP addresses and routes.
  • Understand which tool (ip, nmcli, netplan) to use in your specific case.
  • Diagnose common network connectivity issues.

Prerequisites / Preparation

  1. Terminal access with sudo (administrator) privileges.
  2. Basic understanding of networking concepts: IP address, subnet mask, gateway, DNS.
  3. Knowledge of your network interface name. You can find it with the command:
    ip link show
    
    Look for an entry without LOOPBACK (usually lo). Example names: eth0, ens33, enp0s3, wlan0.
  4. Network information from your administrator or router:
    • Desired IP address (or use DHCP).
    • Subnet mask (e.g., 255.255.255.0 or /24).
    • Gateway address.
    • DNS server addresses (e.g., 8.8.8.8, 1.1.1.1).

Step 1: Temporary Network Configuration with the ip Command

This method works instantly, but all changes will disappear after a reboot. Ideal for testing.

  1. Clear any existing address from the interface (e.g., eth0):
    sudo ip addr flush dev eth0
    
  2. Assign a new IP address and subnet mask:
    sudo ip addr add 192.168.1.100/24 dev eth0
    
    Here, /24 is the mask, equivalent to 255.255.255.0.
  3. Bring the interface up:
    sudo ip link set eth0 up
    
  4. Add the default route (gateway):
    sudo ip route add default via 192.168.1.1
    
  5. Configure DNS temporarily by writing the servers to /etc/resolv.conf (the file may be overwritten):
    echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
    echo "nameserver 1.1.1.1" | sudo tee -a /etc/resolv.conf
    

⚠️ Important: For permanent configuration, you must use your distribution's configuration files (see the following steps).

Step 2: Permanent Configuration in Ubuntu/Debian (Netplan)

Starting with Ubuntu 17.10, Netplan is the default declarative configurator, which generates settings for systemd-networkd or NetworkManager.

  1. Locate the configuration file in /etc/netplan/. It typically has a name like 00-installer-config.yaml or 01-netcfg.yaml.
  2. Edit the file (e.g., sudo nano /etc/netplan/00-installer-config.yaml). Example configuration for a static IP:
    network:
      version: 2
      renderer: networkd # or 'NetworkManager' for desktops
      ethernets:
        eth0:
          addresses:
            - 192.168.1.100/24
          gateway4: 192.168.1.1
          nameservers:
            addresses:
              - 8.8.8.8
              - 1.1.1.1
    
    • ethernets — the section for wired interfaces. For Wi-Fi, use wifis.
    • Ensure YAML indentation uses spaces, not tabs.
  3. Apply the configuration:
    sudo netplan apply
    
    If you have a syntax error, the command will report it.

Step 3: Permanent Configuration via NetworkManager (nmcli)

NetworkManager is a popular daemon often used in desktop systems (Ubuntu, Fedora, RHEL). You can manage it via the nmcli CLI utility.

  1. Check the name of an existing connection (if any):
    nmcli connection show
    
  2. Create a new connection (or modify an existing one). To create:
    sudo nmcli connection add type ethernet con-name static-eth ifname eth0 ip4 192.168.1.100/24 gw4 192.168.1.1
    
  3. Add DNS servers to this connection:
    sudo nmcli connection modify static-eth ipv4.dns "8.8.8.8 1.1.1.1"
    
  4. Apply the settings and activate the connection:
    sudo nmcli connection up static-eth
    
  5. To make the connection auto-connect at boot, ensure the connection.autoconnect flag is set to yes (this is the default).

💡 Tip: For Wi-Fi, use type wifi and add parameters wifi-sec.key-mgmt wpa-psk and wifi-sec.psk "password".

Step 4: Configuration in RHEL/CentOS 8+ (systemd-networkd)

Minimal installations of the RHEL family often use systemd-networkd.

  1. Create or edit the interface configuration file in /etc/systemd/network/. The filename must end with .network (e.g., 20-wired.network).
    [Match]
    Name=eth0
    
    [Network]
    Address=192.168.1.100/24
    Gateway=192.168.1.1
    DNS=8.8.8.8
    DNS=1.1.1.1
    
  2. Restart the service and reload the network:
    sudo systemctl restart systemd-networkd
    sudo systemctl restart systemd-resolved # for DNS
    
  3. Enable the services to start at boot (usually already enabled):
    sudo systemctl enable systemd-networkd
    

Verifying the Result

  1. Ensure the interface has the correct IP:
    ip addr show eth0
    
    The output should include a line with your address inet 192.168.1.100/24.
  2. Check the routing table:
    ip route show
    
    There should be an entry default via 192.168.1.1 dev eth0.
  3. Test internet connectivity:
    ping -c 4 8.8.8.8
    
    If pings succeed, network connectivity is working.
  4. Test DNS name resolution:
    nslookup google.com
    
    or
    dig google.com
    
    An IP address should be returned.

Common Issues

  • Operation not permitted or Permission denied: You forgot to use sudo.
  • RTNETLINK answers: File exists: Attempting to add a duplicate IP address. Flush the interface (ip addr flush) or use a different address.
  • Interface does not come up after configuration (state DOWN):
    • Check if the cable is physically connected (for wired) or if Wi-Fi is enabled (laptop button/switch, rfkill list).
    • Verify YAML syntax in netplan (sudo netplan try).
    • Check logs: journalctl -u systemd-networkd or journalctl -u NetworkManager.
  • No internet access, but ping 8.8.8.8 works: DNS issue. Check /etc/resolv.conf contents and DNS settings in your configuration file (netplan/nmcli).
  • IP address conflict: Ensure the chosen address is not already in use by another device on the network. Use arp-scan or check the DHCP lease table on your router.

F.A.Q.

Which utility is currently recommended instead of ifconfig?
How to make network settings persistent so they survive reboots?
What to do if the interface does not come up after configuration (state DOWN)?
How to temporarily (until reboot) change the IP address?

Hints

Identifying network interfaces
Choosing the configuration method
Configuring a static IP (universal method via ip)
Permanent configuration with Netplan (Ubuntu/Debian)
Permanent configuration via nmcli (NetworkManager)
Verifying the configuration

Did this article help you solve the problem?

FixPedia

Free encyclopedia for fixing errors. Step-by-step guides for Windows, Linux, macOS and more.

© 2026 FixPedia. All materials are available for free.

Made with for the community