Objective

Configure static IP addresses, default gateways, and DNS servers on Linux using ip commands and persistent configuration tools.

Tools & Technologies

  • ip
  • nmcli
  • netplan
  • ifconfig

Key Commands

ip addr add 192.168.1.10/24 dev eth0
ip route add default via 192.168.1.1
nmcli con mod eth0 ipv4.addresses 192.168.1.10/24
nmcli con up eth0

Architecture Overview

flowchart LR CONFIG[Static IP Config] --> IP[IP Address\n192.168.1.10/24] CONFIG --> GW[Default Gateway\n192.168.1.1] CONFIG --> DNS[DNS Servers\n1.1.1.1, 8.8.8.8] IP --> NIC[Network Interface\neth0] GW --> RT[Routing Table] DNS --> RES[Name Resolution] style CONFIG fill:#1a1a2e,stroke:#00d4ff,color:#e0e0e0 style NIC fill:#1a1a2e,stroke:#00ff88,color:#e0e0e0

Step-by-Step Process

01
Temporary Configuration with ip

ip commands take effect immediately but are lost on reboot.

# Add IP address
ip addr add 192.168.1.10/24 dev eth0
# Remove IP
ip addr del 192.168.1.10/24 dev eth0
# Add default route
ip route add default via 192.168.1.1
# Verify
ip addr show eth0
ip route show
02
Persistent via netplan (Ubuntu 18+)

Edit the YAML file in /etc/netplan/ for permanent configuration.

# /etc/netplan/01-netcfg.yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: no
      addresses: [192.168.1.10/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [1.1.1.1, 8.8.8.8]

sudo netplan apply
03
Persistent via nmcli (RHEL/CentOS/Fedora)

NetworkManager CLI for persistent configuration.

nmcli con mod eth0 ipv4.method manual \
  ipv4.addresses '192.168.1.10/24' \
  ipv4.gateway '192.168.1.1' \
  ipv4.dns '1.1.1.1'
nmcli con up eth0
04
Verify Connectivity

Test layer by layer after configuring.

ip addr show             # check IP assigned
ip route show            # check routes
ping -c4 192.168.1.1     # ping gateway
ping -c4 8.8.8.8         # ping internet
ping -c4 google.com      # test DNS resolution
traceroute google.com    # trace path

Challenges & Solutions

  • ip commands are not persistent — use netplan/nmcli for permanent config
  • netplan apply with syntax errors kills network — test with netplan try first

Key Takeaways

  • Use netplan try — it auto-reverts if you don't confirm within 120 seconds
  • Always test DNS resolution (ping hostname) separately from IP connectivity