Skip to main content

Network Configuration and Troubleshooting

In today's interconnected world, understanding how to configure and troubleshoot network connectivity is essential for any Linux system administrator. This lesson builds upon your knowledge of system services and process management to help you master network operations on Ubuntu.

Learning Goals:

  • Understand Ubuntu's network configuration files and tools
  • Configure static and dynamic IP addresses
  • Use essential network troubleshooting commands
  • Diagnose and resolve common network connectivity issues

Network Configuration Files

Ubuntu uses several key files for network configuration. Understanding these files is crucial for both manual configuration and troubleshooting.

/etc/netplan/ Configuration Files

Netplan is Ubuntu's default network configuration tool. Configuration files are typically found in /etc/netplan/ and use YAML syntax.

/etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
ens33:
dhcp4: true
# Uncomment for static IP configuration:
# addresses: [192.168.1.100/24]
# gateway4: 192.168.1.1
# nameservers:
# addresses: [8.8.8.8, 1.1.1.1]

To apply Netplan configurations:

Apply network configuration
sudo netplan apply
tip

Always test network configurations in a non-production environment first. Use sudo netplan try to test configurations with a rollback option if something goes wrong.

Essential Network Commands

Checking Network Interfaces

Use ip command to view and manage network interfaces:

List network interfaces
ip addr show
# or the shorter version:
ip a
Check routing table
ip route show

Testing Connectivity

Basic connectivity testing tools:

Test network connectivity
# Ping a remote host
ping -c 4 google.com

# Test specific port connectivity
telnet google.com 80

# Modern alternative to telnet
nc -zv google.com 80

Static IP Configuration

Let's configure a static IP address using Netplan:

/etc/netplan/99-static-config.yaml
network:
version: 2
renderer: networkd
ethernets:
ens33:
addresses:
- 192.168.1.100/24
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
search: [localdomain]

After creating the configuration:

Apply static IP configuration
sudo netplan apply

Network Troubleshooting Workflow

Follow this systematic approach when troubleshooting network issues:

Step 1: Verify Local Interface

Check interface status
# Check if interface is up
ip link show ens33

# Bring interface up if down
sudo ip link set ens33 up

Step 2: Check IP Configuration

Verify IP assignment
ip addr show ens33

# If no IP, try renewing DHCP lease
sudo dhclient -r ens33 # Release
sudo dhclient ens33 # Renew

Step 3: Test Local Network

Test local connectivity
# Ping gateway
ping -c 4 192.168.1.1

# Ping another local host
ping -c 4 192.168.1.50

Step 4: Test DNS Resolution

Test DNS functionality
# Test DNS resolution
nslookup google.com

# Alternative DNS testing
dig google.com

# Check DNS configuration
cat /etc/resolv.conf

Step 5: Test Internet Connectivity

Test external connectivity
# Test with IP to bypass DNS
ping -c 4 8.8.8.8

# Test specific port
curl -I http://google.com

Advanced Network Diagnostics

Using netstat and ss

Check network connections
# Traditional netstat
netstat -tuln

# Modern ss command (faster)
ss -tuln

Network Service Management

Manage network services
# Check network manager status
sudo systemctl status NetworkManager

# Restart network services
sudo systemctl restart systemd-networkd
warning

Be cautious when restarting network services on remote systems, as you may lose connectivity. Always have alternative access methods available.

Common Pitfalls

  • Incorrect Netplan Syntax: YAML is space-sensitive - always use spaces, not tabs
  • Firewall Blocking: UFW or other firewalls may block connections even when network is configured correctly
  • DNS Issues: Network connectivity might work but DNS resolution fails
  • Interface Naming: Network interface names may differ (ens33, eth0, enp0s3, etc.)
  • Gateway Misconfiguration: Incorrect gateway prevents external network access

Summary

In this lesson, you've learned how to configure and troubleshoot network connectivity in Ubuntu. You now understand Netplan configuration, essential network commands, systematic troubleshooting approaches, and common pitfalls to avoid. These skills are fundamental for maintaining reliable network services and diagnosing connectivity issues.

Show quiz
  1. What command would you use to apply a new Netplan configuration? a) sudo network apply b) sudo netplan apply c) sudo systemctl restart network d) sudo ifup ens33

  2. Which file contains the main network configuration in modern Ubuntu systems? a) /etc/network/interfaces b) /etc/netplan/*.yaml c) /etc/sysconfig/network d) /etc/hosts

  3. What command shows all listening network ports? a) ip addr show b) netstat -tuln or ss -tuln c) ping -c 4 localhost d) nslookup localhost

  4. When troubleshooting network issues, what should you check first? a) DNS resolution b) Internet connectivity c) Local interface status d) Firewall rules

  5. What is the purpose of the dhclient command? a) Configure static IP addresses b) Renew DHCP lease c) Test DNS resolution d) Manage network services


Answers:

  1. b) sudo netplan apply
  2. b) /etc/netplan/*.yaml
  3. b) netstat -tuln or ss -tuln
  4. c) Local interface status
  5. b) Renew DHCP lease