Network Configuration#

Concepts#

The ip Command#

The ip command is the modern way to view and configure network interfaces. It replaces the deprecated ifconfig.

Viewing Configuration#

# Show all interfaces with IP addresses
ip addr show
# or shorthand:
ip a

# Show a specific interface
ip addr show enp0s3

# Show only IPv4
ip -4 addr show

# Show link status (up/down, MAC addresses)
ip link show

# Show routing table
ip route show
# or:
ip r

Understanding ip addr Output#

2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP
    link/ether 08:00:27:ab:cd:ef brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic enp0s3
    inet6 fe80::a00:27ff:feab:cdef/64 scope link
Field Meaning
enp0s3 Interface name (en=ethernet, p0s3=PCI bus location)
UP Interface is active
mtu 1500 Maximum Transmission Unit (packet size)
link/ether MAC address
inet 192.168.1.100/24 IPv4 address and subnet
dynamic Obtained via DHCP
inet6 fe80::... IPv6 link-local address

Interface Naming#

Old Style New Style Type
eth0 enp0s3, ens33 Ethernet
wlan0 wlp2s0 Wi-Fi
lo lo Loopback (always 127.0.0.1)

Temporary Configuration (Lost on Reboot)#

# Add an IP address
sudo ip addr add 192.168.1.200/24 dev enp0s3

# Remove an IP address
sudo ip addr del 192.168.1.200/24 dev enp0s3

# Bring an interface up or down
sudo ip link set enp0s3 up
sudo ip link set enp0s3 down

# Add a default route
sudo ip route add default via 192.168.1.1

# Add a static route
sudo ip route add 10.0.0.0/8 via 192.168.1.1

These changes are temporary — they are lost on reboot. For persistent configuration, use Netplan (Ubuntu) or /etc/network/interfaces (Debian).

Persistent Configuration — Ubuntu (Netplan)#

For Debian see the /etc/network/interfaces section below.

Ubuntu 24.04 uses Netplan, which generates configuration for the underlying network manager (NetworkManager or systemd-networkd).

Configuration files: /etc/netplan/*.yaml

DHCP Configuration (Default)#

# /etc/netplan/01-netcfg.yaml
network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: true

Static IP Configuration#

# /etc/netplan/01-netcfg.yaml
network:
  version: 2
  ethernets:
    enp0s3:
      dhcp4: false
      addresses:
        - 192.168.1.100/24
      routes:
        - to: default
          via: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4

Apply Netplan changes:

# Test (reverts after 120 seconds if you don't confirm)
sudo netplan try

# Apply permanently
sudo netplan apply

# Generate config without applying
sudo netplan generate

Persistent Configuration — Debian (/etc/network/interfaces)#

Debian 12 uses the traditional /etc/network/interfaces file.

DHCP Configuration#

# /etc/network/interfaces
auto lo
iface lo inet loopback

auto enp0s3
iface enp0s3 inet dhcp

Static IP Configuration#

# /etc/network/interfaces
auto lo
iface lo inet loopback

auto enp0s3
iface enp0s3 inet static
    address 192.168.1.100/24
    gateway 192.168.1.1
    dns-nameservers 8.8.8.8 8.8.4.4

Apply changes:

sudo systemctl restart networking
# or
sudo ifdown enp0s3 && sudo ifup enp0s3

NetworkManager (nmcli)#

Both distros can use NetworkManager, especially on desktop installations. The CLI tool is nmcli.

# Show all connections
nmcli connection show

# Show active connections
nmcli connection show --active

# Show device status
nmcli device status

# Show interface details
nmcli device show enp0s3

# Set static IP via nmcli
nmcli connection modify "Wired connection 1" \
  ipv4.method manual \
  ipv4.addresses 192.168.1.100/24 \
  ipv4.gateway 192.168.1.1 \
  ipv4.dns "8.8.8.8,8.8.4.4"

# Switch back to DHCP
nmcli connection modify "Wired connection 1" ipv4.method auto

# Apply changes
nmcli connection up "Wired connection 1"

DNS Configuration#

DNS resolvers are configured in /etc/resolv.conf:

cat /etc/resolv.conf
# nameserver 127.0.0.53    ← systemd-resolved (Ubuntu)
# nameserver 192.168.1.1   ← router (Debian)

Ubuntu: Uses systemd-resolved. The file /etc/resolv.conf is a symlink managed by the system. Check actual DNS with resolvectl status.

Debian: DNS is typically configured directly in /etc/resolv.conf or via the dns-nameservers directive in /etc/network/interfaces.

Static hostname-to-IP mappings go in /etc/hosts:

sudo nano /etc/hosts
# Add:
# 192.168.1.50  myserver

Hostname#

# View hostname
hostname
hostnamectl

# Change hostname
sudo hostnamectl set-hostname newname
# Also update /etc/hosts if your hostname appears there

Lab#

Exercise 1: View Your Network#

ip addr show
ip route show
cat /etc/resolv.conf
hostname

Exercise 2: Examine Netplan (Ubuntu) or interfaces (Debian)#

# Ubuntu
ls /etc/netplan/
cat /etc/netplan/*.yaml 2>/dev/null

# Debian
cat /etc/network/interfaces 2>/dev/null

Exercise 3: NetworkManager#

nmcli device status
nmcli connection show
nmcli device show enp0s3 2>/dev/null || nmcli device show eth0 2>/dev/null

Exercise 4: DNS Resolution Details#

# Ubuntu: check systemd-resolved
resolvectl status 2>/dev/null | head -20

# Test resolution
host google.com
dig google.com +short

# Check /etc/hosts
cat /etc/hosts

Exercise 5: Add a Local Host Entry#

# Add a test entry (harmless)
echo "127.0.0.1  mytest.local" | sudo tee -a /etc/hosts

# Verify
ping -c 1 mytest.local

# Clean up
sudo sed -i '/mytest.local/d' /etc/hosts

Review#

1. What command replaced `ifconfig`?

ip. Use ip addr show instead of ifconfig, ip route instead of route, and ip link instead of ifconfig for link status.

2. How does Ubuntu configure persistent network settings?

Through Netplan — YAML files in /etc/netplan/. Apply with sudo netplan apply or test with sudo netplan try.

3. How does Debian configure persistent network settings?

Through /etc/network/interfaces. Apply with sudo systemctl restart networking or sudo ifdown/ifup.

4. What is the difference between `ip addr add` and editing Netplan/interfaces?

ip addr add is temporary — changes are lost on reboot. Editing Netplan or /etc/network/interfaces creates persistent configuration that survives reboots.

5. What does `nmcli` do?

nmcli is the CLI for NetworkManager. It can view, create, modify, and activate network connections. Common on desktop installations.

6. Where is DNS configured on Ubuntu vs Debian?

Ubuntu uses systemd-resolved (check with resolvectl status). Debian configures DNS in /etc/resolv.conf or via dns-nameservers in /etc/network/interfaces.


Previous: Networking Concepts | Next: Network Diagnostics