Linux Networking Basics: Connect, Configure, and Troubleshoot
Learn essential Linux networking skills. Configure IP addresses, test connectivity, troubleshoot network issues, and access remote systems securely with SSH.
Why Networking Skills Matter
Every Linux system connects to networks - servers communicate with clients, services talk to databases, applications fetch data from APIs. Understanding networking is fundamental to working with Linux effectively.
When connections fail, you need to diagnose the problem quickly. Is it the network configuration? DNS resolution? Firewall rules? A service not listening? Without networking knowledge, you're stuck waiting for someone else to fix it.
Basic networking skills let you configure network interfaces, test connectivity, troubleshoot issues, and access remote systems. These commands are essential for running web servers, managing cloud instances, or simply connecting to the internet.
This guide covers the eight essential networking skills every Linux user needs. Learn these fundamentals and you'll confidently handle network configuration and troubleshooting.
Common Networking Mistakes
Not Using sudo When Required
The Problem: Many network commands require root privileges to modify settings or see all information. Running without sudo gives incomplete output or errors.
The Solution: Use sudo for commands that modify network settings (ip link set, editing routes) or display all processes (ss -tunap, netstat -tunap). For viewing-only commands like ip addr show, sudo usually isn't needed.
Forgetting Temporary vs Permanent Changes
The Problem: Changes made with ip command are temporary and disappear on reboot. Many users configure networking manually then wonder why it resets after restart.
The Solution: Use ip for temporary testing, but edit network configuration files for permanent changes. On Ubuntu/Debian, edit /etc/netplan/ files. On RHEL/CentOS, edit /etc/sysconfig/network-scripts/ files. Apply permanent configs with netplan apply or systemctl restart network.
Misinterpreting ping Results
The Problem: Assuming a host is down because ping fails, when many servers block ICMP for security. Or thinking the network is fine when ping succeeds but the actual service is inaccessible.
The Solution: Ping tests ICMP only, not whether a service works. No ping response doesn't always mean the host is down. Test the actual service port with telnet or nc. Check if the service is listening with ss or netstat.
Not Checking Both Ends of Connection
The Problem: Troubleshooting only the client when the issue is on the server, or vice versa. Network problems require checking both sides of the connection.
The Solution: Check that the client has network access, the server is listening on the right port and interface (0.0.0.0 vs 127.0.0.1), firewall allows the connection on both ends, and routing is correct in both directions.
8 Essential Networking Skills
These skills cover network configuration, testing, troubleshooting, and remote access. Essential for anyone working with Linux systems.
IP Address Configuration with ip Command
The ip command is the modern way to configure network interfaces, routes, and addresses. It replaced the older ifconfig and provides more features and better output.
# Show all network interfaces
$ 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> mtu 1500
inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
# Show specific interface
$ ip addr show eth0
# Show brief summary
$ ip -br addr
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0 UP 192.168.1.100/24
# Show routing table
$ ip route show
default via 192.168.1.1 dev eth0
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.100
# Bring interface up/down
$ sudo ip link set eth0 down
$ sudo ip link set eth0 up
# Add temporary IP address
$ sudo ip addr add 192.168.1.200/24 dev eth0
# Delete IP address
$ sudo ip addr del 192.168.1.200/24 dev eth0Pro Tips: Use ip -br (brief) for cleaner output. Changes with ip command are temporary and lost on reboot - make them permanent by editing network config files. The ip command combines functionality from ifconfig, route, and arp commands.
Testing Connectivity with ping
Ping tests network connectivity by sending ICMP echo requests. It verifies if a host is reachable and measures response time (latency).
# Ping a host (Ctrl+C to stop)
$ ping google.com
PING google.com (142.250.185.46): 56 data bytes
64 bytes from 142.250.185.46: icmp_seq=0 ttl=117 time=15.2 ms
64 bytes from 142.250.185.46: icmp_seq=1 ttl=117 time=14.8 ms
# Send specific number of pings
$ ping -c 4 google.com
# Ping with interval (2 seconds)
$ ping -i 2 8.8.8.8
# Flood ping (root only, for testing)
$ sudo ping -f target
# Ping IPv6 address
$ ping6 2001:4860:4860::8888
# Quiet output (summary only)
$ ping -c 10 -q google.com
PING google.com (142.250.185.46): 56 data bytes
--- google.com ping statistics ---
10 packets transmitted, 10 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 14.521/15.234/16.891/0.651 ms
# Ping local network gateway
$ ping $(ip route | grep default | awk '{print $3}')Pro Tips: Ping continuously to monitor connection stability. Some servers block ICMP, so no response doesn't always mean the host is down. Low packet loss is normal; consistent loss indicates network problems. Use ping to test each hop: local machine, gateway, then internet.
Checking Connections with ss and netstat
View active network connections, listening ports, and socket statistics. The ss command is faster and shows more information than the older netstat.
# Show all listening ports
$ sudo ss -tuln
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
# Show all connections with process info
$ sudo ss -tunap
State Recv-Q Send-Q Local:Port Peer:Port Process
ESTAB 0 0 192.168.1.100:22 192.168.1.50:54321 users:(("sshd",pid=1234))
# Find what's listening on port 80
$ sudo ss -tulpn | grep :80
tcp LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=5678))
# Show connection statistics
$ ss -s
Total: 200
TCP: 50 (estab 10, closed 30, orphaned 0, timewait 28)
# Show established connections
$ ss -t state established
# Using netstat (older way)
$ netstat -tuln
$ netstat -tunap | grep :3306
$ netstat -i # Interface statisticsPro Tips: Use ss instead of netstat - it's faster and more powerful. Add sudo to see process names and PIDs. Port numbers below 1024 are privileged ports requiring root. Use grep to filter output for specific ports or services.
DNS and Name Resolution
Resolve domain names to IP addresses and troubleshoot DNS issues using dig, nslookup, and host commands. Understanding DNS is crucial for network troubleshooting.
# Basic DNS lookup with dig
$ dig google.com
;; ANSWER SECTION:
google.com. 300 IN A 142.250.185.46
# Short output (just IP)
$ dig +short google.com
142.250.185.46
# Query specific DNS server
$ dig @8.8.8.8 example.com
# Reverse DNS lookup
$ dig -x 8.8.8.8 +short
dns.google.
# Get MX records
$ dig gmail.com MX +short
5 gmail-smtp-in.l.google.com.
# Using nslookup
$ nslookup google.com
Server: 192.168.1.1
Address: 192.168.1.1#53
Name: google.com
Address: 142.250.185.46
# Using host
$ host google.com
google.com has address 142.250.185.46
# Check local DNS resolution file
$ cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
# Test DNS resolution is working
$ dig +short google.com || echo "DNS not working"Pro Tips: Use dig for detailed DNS debugging, host for quick lookups. Check /etc/resolv.conf to see which DNS servers you're using. Google's DNS (8.8.8.8) and Cloudflare's (1.1.1.1) are good for testing. DNS caching can cause stale results - wait or flush DNS cache.
Downloading Files with wget and curl
Download files from the internet using wget or curl. Both handle HTTP, HTTPS, and FTP, but have different strengths for different use cases.
# wget: Download a file
$ wget https://example.com/file.zip
# wget: Save with different name
$ wget -O myfile.zip https://example.com/file.zip
# wget: Resume interrupted download
$ wget -c https://example.com/largefile.iso
# wget: Download to specific directory
$ wget -P ~/Downloads https://example.com/file.pdf
# wget: Recursive download (careful!)
$ wget -r -l 2 https://example.com/docs/
# curl: Download a file
$ curl -O https://example.com/file.zip
# curl: Save with specific name
$ curl -o myfile.zip https://example.com/file.zip
# curl: Follow redirects
$ curl -L https://example.com/shortened-url
# curl: Test API endpoint
$ curl https://api.example.com/users
# curl: POST request
$ curl -X POST -d "param=value" https://api.example.com/endpoint
# curl: Show only headers
$ curl -I https://example.com
HTTP/2 200
content-type: text/htmlPro Tips: Use wget for downloading files (simpler syntax), curl for API testing and piping. Always use -L with curl to follow redirects. wget resumes downloads automatically with -c. Check if a URL is accessible before downloading large files using curl -I.
Secure Remote Access with SSH
SSH (Secure Shell) provides encrypted remote access to Linux systems. Learn to connect to remote servers, transfer files, and use SSH keys for secure authentication.
# Connect to remote server
$ ssh user@192.168.1.50
$ ssh john@example.com
# Connect on different port
$ ssh -p 2222 user@host
# Execute command on remote server
$ ssh user@host 'ls -la /var/log'
# Generate SSH key pair
$ ssh-keygen -t ed25519 -C "your_email@example.com"
# Copy key to server (enables passwordless login)
$ ssh-copy-id user@host
# Use specific key file
$ ssh -i ~/.ssh/id_rsa_work user@work-server
# SSH config file example (~/.ssh/config)
Host myserver
HostName 192.168.1.50
User john
Port 2222
IdentityFile ~/.ssh/id_rsa_work
# Now just use:
$ ssh myserver
# SCP: Copy file to remote server
$ scp file.txt user@host:/path/to/destination
# SCP: Copy file from remote server
$ scp user@host:/path/to/file.txt .
# SCP: Copy directory recursively
$ scp -r mydir/ user@host:/path/Pro Tips: Use SSH keys instead of passwords - they're more secure. Create a ~/.ssh/config file for frequently accessed servers. Keep your private keys safe and never share them. Disable root SSH login on servers for security.
Network Interface Information
View detailed information about network interfaces, check link status, and monitor network statistics. Essential for troubleshooting connectivity issues.
# Show interface status
$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
# Show interface statistics
$ ip -s link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>
RX: bytes packets errors dropped
1234567 12345 0 0
TX: bytes packets errors dropped
7654321 54321 0 0
# Detailed interface info (requires ethtool)
$ sudo ethtool eth0
Settings for eth0:
Speed: 1000Mb/s
Duplex: Full
Link detected: yes
# NetworkManager device status
$ nmcli device
DEVICE TYPE STATE CONNECTION
eth0 ethernet connected Wired connection 1
wlan0 wifi disconnected --
# Show wireless info
$ iw dev wlan0 info
Interface wlan0
ifindex 3
type managed
ssid MyNetwork
channel 6 (2437 MHz)
# Monitor interface in real-time
$ watch -n 1 'ip -s link show eth0'Pro Tips: Check link detection first when troubleshooting - if link isn't detected, it's a physical issue (cable, port). High error or drop counts indicate network problems. Use ethtool to verify speed and duplex match what's expected.
Network Troubleshooting Workflow
Systematic approach to diagnosing network problems. Follow a logical sequence to identify where connectivity breaks down.
# Systematic troubleshooting workflow:
# 1. Check IP address
$ ip addr show eth0
# Expected: Valid IP in your network range
# 2. Check default gateway
$ ip route show
default via 192.168.1.1 dev eth0
# 3. Ping gateway (local network test)
$ ping -c 3 192.168.1.1
# Expected: Replies received
# 4. Ping external IP (internet test, no DNS)
$ ping -c 3 8.8.8.8
# Expected: Replies received
# 5. Ping domain name (DNS test)
$ ping -c 3 google.com
# Expected: Resolves to IP and replies
# 6. Test DNS directly
$ dig +short google.com
# Expected: Returns IP address
# 7. Check specific service port
$ telnet host 80
# or
$ nc -zv host 80
# Quick diagnostic script
#!/bin/bash
echo "Checking network..."
ping -c 1 -W 1 $(ip route | awk '/default/ {print $3}') && echo "Gateway: OK" || echo "Gateway: FAIL"
ping -c 1 -W 1 8.8.8.8 && echo "Internet: OK" || echo "Internet: FAIL"
ping -c 1 -W 1 google.com && echo "DNS: OK" || echo "DNS: FAIL"Pro Tips: Always follow a systematic approach - don't jump to conclusions. Start with physical layer and work up. If you can ping IPs but not domain names, it's DNS. If you can't ping the gateway, it's local network. Document what works and what doesn't to narrow down the issue.
Firewall Basics: ufw and iptables
Linux firewalls control which network traffic is allowed in and out. ufw (Uncomplicated Firewall) is the beginner-friendly frontend; iptables is the underlying engine used by all Linux firewalls.
ufw — Uncomplicated Firewall
Default on Ubuntu/Debian. Simple commands, human-readable rules.
# Check status $ sudo ufw status verbose # Enable / disable $ sudo ufw enable $ sudo ufw disable # Allow common ports $ sudo ufw allow ssh # port 22 $ sudo ufw allow http # port 80 $ sudo ufw allow https # port 443 $ sudo ufw allow 8080 # custom port # Deny a port $ sudo ufw deny 3306 # block MySQL # Allow from specific IP $ sudo ufw allow from 192.168.1.10 $ sudo ufw allow from 192.168.1.0/24 # Delete a rule $ sudo ufw delete allow 8080 # Reset all rules $ sudo ufw reset
iptables — Low-Level Firewall
Available on all distros. More powerful, more complex. Used by ufw and firewalld under the hood.
# List current rules
$ sudo iptables -L -n -v
# Allow incoming SSH
$ sudo iptables -A INPUT -p tcp \
--dport 22 -j ACCEPT
# Allow incoming HTTP/HTTPS
$ sudo iptables -A INPUT -p tcp \
--dport 80 -j ACCEPT
$ sudo iptables -A INPUT -p tcp \
--dport 443 -j ACCEPT
# Drop everything else
$ sudo iptables -A INPUT -j DROP
# Allow established connections
$ sudo iptables -A INPUT -m state \
--state ESTABLISHED,RELATED -j ACCEPT
# Save rules (Ubuntu/Debian)
$ sudo iptables-save > \
/etc/iptables/rules.v4
# RHEL/Fedora: use firewalld
$ sudo firewall-cmd --list-allufw on Ubuntu/Debian — it covers 90% of use cases. On RHEL/CentOS/Fedora use firewall-cmd (firewalld). Learn iptables when you need fine-grained control or are writing automation. Always allow SSH before enabling a firewall on a remote server or you will lock yourself out.Tracing Network Paths with traceroute
While ping tells you if a host is reachable, traceroute shows you how traffic gets there — every router hop along the path with its latency. Invaluable for diagnosing where a connection slows down or breaks.
# Basic traceroute (may need: sudo apt install traceroute) $ traceroute google.com traceroute to google.com (142.250.185.46), 30 hops max 1 192.168.1.1 (192.168.1.1) 1.234 ms — your router 2 10.0.0.1 (10.0.0.1) 8.456 ms — ISP gateway 3 72.14.215.1 (72.14.215.1) 12.891 ms — ISP backbone 4 * * * — hop not responding (normal) 5 142.250.185.46 (142.250.185.46) 14.567 ms — destination # Use ICMP instead of UDP (more reliable through firewalls) $ sudo traceroute -I google.com # Limit to 15 hops (default is 30) $ traceroute -m 15 google.com # mtr: combines ping + traceroute in a live view $ sudo apt install mtr $ mtr google.com # live, updating display $ mtr --report google.com # one-shot report
* * * on every hop
Firewall dropping ICMP — normal for some hops. Only a problem if the destination itself shows ***.
High latency at one hop
Network congestion or long-distance link at that router. Not always fixable from your end.
Traceroute stops mid-path
A router is blocking the probe packets. Try traceroute -I (ICMP mode) which is less likely to be filtered.
Your First Steps with Linux Networking
Build practical networking skills through hands-on practice with these essential steps.
Check Your Current Network Configuration
Run ip addr show to see your interfaces and IP addresses. Check ip route show for your gateway. Run ss -tuln to see what services are listening. Get familiar with your normal network configuration so you recognize when something is wrong.
Practice the Troubleshooting Workflow
Intentionally disconnect from the network and work through the diagnostic steps: check interface, ping gateway, ping internet, test DNS. Do this a few times until the workflow becomes automatic. This systematic approach saves hours when real problems occur.
Set Up SSH Key Authentication
Generate an SSH key with ssh-keygen, copy it to a remote server with ssh-copy-id, and practice passwordless login. Create a ~/.ssh/config file for servers you access frequently. This is essential for anyone working with remote Linux systems.
Go Deeper with Linux Networking
This guide covers essential networking skills. The Practical Linux Handbook includes advanced networking, firewall configuration, network services, and complete system administration.
What You'll Learn:
- Complete networking (TCP/IP, routing, DNS, firewalls)
- Network services setup and configuration
- Advanced troubleshooting techniques
- Security and firewall management
- Remote access and VPN configuration
Beyond Networking:
- 70+ Linux commands with detailed examples
- File operations and permissions
- Process management and monitoring
- Package management across distributions
- 3 bonus editor cheat sheets (Vim, Nano, Emacs)
Frequently Asked Questions
What are the basic Linux networking commands?
The essential commands are: ip addr (view/configure IP addresses), ping (test connectivity), ss or netstat (check open ports and connections), dig or nslookup (DNS lookups), traceroute (trace network path), ssh (remote access), curl/wget (download files), and ufw or iptables (firewall management). Start with ip, ping, and ss — they cover most day-to-day networking tasks.
How do I check network interfaces in Linux?
Run ip addr show to list all interfaces with their IP addresses, or ip -br addr for a compact summary. To check interface status (up/down): ip link show. For detailed stats including packet counts and errors: ip -s link show eth0. Use nmcli device if your system uses NetworkManager. The older ifconfig command also works but is deprecated.
What's the difference between ss and netstat?
ss is the modern replacement for netstat — faster, shows more information, and actively maintained. netstat is deprecated but still available for compatibility. Use ss -tuln to list listening ports, ss -tunap to include process names. Both show the same information; ss is preferred on all modern Linux systems.
What does 127.0.0.1 vs 0.0.0.0 mean for listening addresses?
127.0.0.1 (localhost) means the service only accepts connections from the same machine — not accessible from the network. 0.0.0.0 means it accepts connections on any interface — accessible remotely. When a service is only reachable locally, check if it is bound to 127.0.0.1 instead of 0.0.0.0.
How do I allow a port through the Linux firewall?
On Ubuntu/Debian with ufw: sudo ufw allow 80 (by port number) or sudo ufw allow http (by service name). On RHEL/Fedora/CentOS with firewalld: sudo firewall-cmd --add-port=80/tcp --permanent && sudo firewall-cmd --reload. With iptables directly: sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT. Always allow SSH (port 22) before enabling a firewall on a remote server.
Continue Your Linux Journey
Ready to Build Your Networking Skills?
Join thousands who've learned to confidently configure, troubleshoot, and manage Linux networks with The Practical Linux Handbook.