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.
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:
sudo netplan apply
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:
ip addr show
# or the shorter version:
ip a
ip route show
Testing Connectivity
Basic connectivity testing tools:
# 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:
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:
sudo netplan apply
Network Troubleshooting Workflow
Follow this systematic approach when troubleshooting network issues:
Step 1: Verify Local Interface
# 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
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
# 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 resolution
nslookup google.com
# Alternative DNS testing
dig google.com
# Check DNS configuration
cat /etc/resolv.conf
Step 5: Test Internet 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
# Traditional netstat
netstat -tuln
# Modern ss command (faster)
ss -tuln
Network Service Management
# Check network manager status
sudo systemctl status NetworkManager
# Restart network services
sudo systemctl restart systemd-networkd
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
-
What command would you use to apply a new Netplan configuration? a)
sudo network applyb)sudo netplan applyc)sudo systemctl restart networkd)sudo ifup ens33 -
Which file contains the main network configuration in modern Ubuntu systems? a)
/etc/network/interfacesb)/etc/netplan/*.yamlc)/etc/sysconfig/networkd)/etc/hosts -
What command shows all listening network ports? a)
ip addr showb)netstat -tulnorss -tulnc)ping -c 4 localhostd)nslookup localhost -
When troubleshooting network issues, what should you check first? a) DNS resolution b) Internet connectivity c) Local interface status d) Firewall rules
-
What is the purpose of the
dhclientcommand? a) Configure static IP addresses b) Renew DHCP lease c) Test DNS resolution d) Manage network services
Answers:
- b)
sudo netplan apply - b)
/etc/netplan/*.yaml - b)
netstat -tulnorss -tuln - c) Local interface status
- b) Renew DHCP lease