Network Configuration

Comprehensive guide to configuring network interfaces, IP addresses, routing, and DNS in Linux

Network configuration in Linux involves setting up and managing network interfaces, IP addresses, routing tables, and DNS settings. It’s fundamental for system connectivity, server administration, and troubleshooting network issues.

Key Concepts

  • Network Interface: Physical or virtual network connection (eth0, wlan0, lo)
  • IP Address: Unique identifier for network communication
  • Subnet Mask: Defines network and host portions of IP
  • Gateway: Router that connects to other networks
  • DNS: Domain Name System for hostname resolution
  • DHCP: Dynamic Host Configuration Protocol for automatic IP assignment

Command Syntax

ip [OPTIONS] OBJECT COMMAND

  • Modern replacement for older net-tools commands
  • Objects: link, addr, route, neigh
  • More consistent and feature-rich interface

Common Options

ip addr show - Display all network interfaces ip route show - Show routing table ip link set - Configure interface properties -4 - IPv4 only -6 - IPv6 only

Practical Examples

Example 1: View network interfaces

1
2
3
4
5
ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>
    inet 192.168.1.100/24 brd 192.168.1.255

Shows all interfaces with IP addresses and status

Example 2: Configure static IP

1
2
sudo ip addr add 192.168.1.150/24 dev eth0
sudo ip link set eth0 up

Assigns static IP to ethernet interface

Example 3: Add default gateway

1
sudo ip route add default via 192.168.1.1

Sets default route through gateway

Example 4: View routing table

1
2
3
ip route show
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 scope link

Displays current routing configuration

Example 5: Configure DNS

1
2
3
cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4

Shows DNS server configuration

Use Cases

  • Setting up servers with static IP addresses
  • Configuring network interfaces after installation
  • Troubleshooting connectivity issues
  • Managing multiple network interfaces
  • Setting up routing between networks
  • Configuring wireless connections

ping - Test network connectivity netstat - Display network connections (deprecated) ss - Modern socket statistics tool nmcli - NetworkManager command-line tool systemctl - Manage network services dhclient - DHCP client for automatic configuration

Tips & Troubleshooting

  • Use ip addr instead of deprecated ifconfig
  • Check interface status with ip link show
  • Verify routing with ip route get <destination>
  • Test DNS resolution with nslookup or dig
  • NetworkManager may override manual configurations
  • Restart networking: sudo systemctl restart networking
  • Persistent config files: /etc/network/interfaces (Debian) or /etc/netplan/ (Ubuntu 18+)
  • Use nmtui for text-based network configuration GUI
  • Check firewall rules if connectivity fails despite correct config