Ubuntu Network Configuration Guide: Complete 2025 Tutorial

By Hafiz Ali | Linux System Administrator with 8+ years experience managing Ubuntu servers and VPN infrastructure. Certified RHCE and Ubuntu Server Specialist.

🌐 Ubuntu Network Configuration Guide: Complete 2025 Tutorial

🕒 Last updated: December 2024 | Tested on Ubuntu 22.04 LTS and 24.04 LTS

`

Proper network configuration is essential for Ubuntu server administration. This comprehensive guide covers everything from basic Netplan setup to advanced networking scenarios, helping you master Ubuntu’s modern networking stack.

🚀 Quick Configuration Methods

MethodBest ForDifficultyUbuntu Version
🌐 Netplan (YAML)Modern serversđŸŸĸ Easy18.04+
âš™ī¸ NetworkManagerDesktops/laptopsđŸŸĸ EasyAll versions
🔧 Systemd-networkdAdvanced users🟡 Medium16.04+
📜 Legacy ifupdownOlder systems🟡 Medium14.04 and earlier

🔍 Current Network Status Check

Before making changes, check your current network configuration:

# View all network interfaces
ip addr show

# Check routing table
ip route show

# Test DNS resolution
nslookup google.com

# Check network manager status
systemctl status NetworkManager

# View Netplan configuration
ls -la /etc/netplan/

🌐 Method 1: Netplan Configuration (Recommended)

Netplan is Ubuntu’s default network configuration tool since 18.04, using YAML files for declarative network setup.

📁 Netplan File Locations

# Main Netplan directory
/etc/netplan/

# Common configuration files
/etc/netplan/01-netcfg.yaml
/etc/netplan/50-cloud-init.yaml
/etc/netplan/99-config.yaml

đŸ› ī¸ Basic Static IP Configuration

# Create or edit Netplan configuration
sudo nano /etc/netplan/01-netcfg.yaml

Add this configuration for a static IP address:

network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
          addresses: [8.8.8.8, 8.8.4.4]
      optional: true

🚀 Apply Netplan Configuration

# Test configuration (dry run)
sudo netplan try

# Apply configuration immediately
sudo netplan apply

# Generate backend configuration
sudo netplan generate

# Debug Netplan issues
sudo netplan --debug apply

🔧 Method 2: NetworkManager (Desktop/Server)

NetworkManager provides dynamic network control and is ideal for systems with changing network environments.

đŸ–Ĩī¸ GUI Configuration (Ubuntu Desktop)

  • īŋŊī¸ Click network icon in system tray
  • âš™ī¸ Select Wired Settings or Network Settings
  • 🔧 Choose your network interface
  • 📡 Configure IPv4/IPv6 settings as needed
  • 💾 Click Apply to save changes

âŒ¨ī¸ Command Line Configuration

# List all connections
nmcli connection show

# View device status
nmcli device status

# Create a new static connection
nmcli connection add type ethernet con-name static-eth0 ifname eth0 ip4 192.168.1.100/24 gw4 192.168.1.1

# Configure DNS
nmcli connection modify static-eth0 ipv4.dns "8.8.8.8,8.8.4.4"

# Activate the connection
nmcli connection up static-eth0

⚡ Advanced Network Scenarios

🔗 Network Bonding (Link Aggregation)

# Netplan bonding configuration
network:
  version: 2
  renderer: networkd
  bonds:
    bond0:
      interfaces: [ens33, ens34]
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
      parameters:
        mode: 802.3ad
        lacp-rate: fast
        mii-monitor-interval: 100

🌉 Network Bridging

# Netplan bridge configuration
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: no
  bridges:
    br0:
      interfaces: [ens33]
      addresses: [192.168.1.100/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]
      parameters:
        stp: true
        forward-delay: 4

📡 VLAN Configuration

# Netplan VLAN configuration
network:
  version: 2
  renderer: networkd
  vlans:
    ens33.100:
      id: 100
      link: ens33
      addresses: [192.168.100.100/24]
      gateway4: 192.168.100.1
      nameservers:
        addresses: [8.8.8.8, 8.8.4.4]

🔧 Essential Network Commands

📊 Monitoring & Diagnostics

# Real-time network traffic
sudo nethogs

# Bandwidth monitoring
sudo iftop

# Network statistics
ss -tuln
netstat -tuln

# Interface statistics
ip -s link

# Continuous ping with timestamp
ping -D 8.8.8.8

đŸ› ī¸ Troubleshooting Commands

# Check network connectivity
ping -c 4 google.com

# Trace network path
traceroute google.com

# DNS resolution test
dig google.com
nslookup google.com

# Check specific port connectivity
telnet google.com 80
nc -zv google.com 443

# View network manager logs
journalctl -u NetworkManager -f

🚨 Common Network Issues & Solutions

❌ “Network Unreachable” Error

# Check gateway configuration
ip route show

# Verify interface status
ip addr show

# Restart networking
sudo netplan apply
# OR
sudo systemctl restart systemd-networkd

🔍 DNS Resolution Problems

# Check current DNS settings
systemd-resolve --status

# Test DNS resolution
nslookup google.com

# Flush DNS cache
sudo systemd-resolve --flush-caches

# Use alternative DNS temporarily
echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf

âš ī¸ Interface Not Found

# List all network interfaces
ip link show

# Check if interface is up
ip link set ens33 up

# Scan for hardware changes
sudo lshw -class network

# Reload kernel modules
sudo modprobe -r e1000
sudo modprobe e1000

đŸ›Ąī¸ Network Security Configuration

🔒 Firewall Setup with UFW

# Enable UFW firewall
sudo ufw enable

# Allow SSH access
sudo ufw allow ssh

# Allow specific ports
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

# Allow from specific IP
sudo ufw allow from 192.168.1.0/24

# View firewall status
sudo ufw status verbose

🌐 Secure Remote Access

# For OpenVPN access (if using our VPN guides)
sudo ufw allow 1194/udp

# For WireGuard access
sudo ufw allow 51820/udp

# Limit SSH access to specific network
sudo ufw allow from 192.168.1.0/24 to any port 22

â˜ī¸ Cloud & Virtualization Notes

đŸŒŠī¸ Cloud-Init Integration

# Cloud-init network configuration (usually in /etc/cloud/cloud.cfg.d/)
network:
  version: 2
  ethernets:
    eth0:
      dhcp4: true
      optional: true

đŸ–Ĩī¸ Virtual Machine Networking

  • 🔗 NAT: Default for most VMs, shares host IP
  • 🌉 Bridged: VM gets own IP on physical network
  • 🏠 Host-only: Network between host and VMs only
  • 🔒 Internal: Isolated network between VMs only

📋 Best Practices Checklist

  • ✅ Always backup original config files before changes
  • ✅ Use Netplan for Ubuntu 18.04+ servers
  • ✅ Test configurations with netplan try before applying
  • ✅ Document changes in your configuration management system
  • ✅ Monitor network metrics for performance and security
  • ✅ Use descriptive names for network interfaces and connections
  • ✅ Implement firewall rules following least privilege principle

❓ Frequently Asked Questions

🔧 Should I use Netplan or NetworkManager?

Netplan: Best for servers, cloud environments, and reproducible configurations.
NetworkManager: Best for desktops, laptops, and systems with changing network conditions.

🔄 How do I reset network configuration?

# Reset Netplan to DHCP
sudo tee /etc/netplan/01-netcfg.yaml << EOF
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: true
EOF
sudo netplan apply

🌐 My changes aren’t applying. What’s wrong?

Common issues include:

  • ❌ YAML syntax errors (check indentation)
  • ❌ Wrong interface name (use ip link show)
  • ❌ Conflicting configuration files
  • ❌ Network manager conflicts

🔗 Related Ubuntu Guides

🌐 Ready to Master Ubuntu Networking?

Our complete Ubuntu Troubleshooting category has everything you need for enterprise-grade server administration.

Explore All Ubuntu Guides →

Similar Posts