Linux Networking
Learn essential Linux networking commands for inspecting addresses, testing connectivity, transferring files, and understanding DNS resolution.
Why Networking Skills Matter
In DevOps, many “application problems” are really networking problems. A service may be healthy but unreachable, a DNS name may resolve incorrectly, or a firewall may block the expected port.
Linux includes strong networking tools for checking addresses, routes, listening ports, remote connectivity, and file transfers.
Inspecting Interfaces with ip addr
The modern command for viewing network interfaces and addresses is ip.
ip addr
ip addr show eth0
This tells you what IP addresses are assigned to each interface.
If a server has no expected address, that is your first clue something is wrong.
Viewing Routes with ip route
Routing decides where traffic goes.
ip route
Example output may show a default gateway such as:
default via 10.0.0.1 dev eth0
Without a correct default route, the host may reach the local subnet but not the internet or remote networks.
Testing Reachability with ping
ping checks whether a host responds to ICMP echo requests.
ping 8.8.8.8
ping example.com
If ping 8.8.8.8 works but ping example.com fails, the issue may be DNS rather than raw network connectivity.
Note: Some hosts block ICMP, so a failed ping does not always mean the service is down.
Fetching Data with curl and wget
curl is a versatile tool for making HTTP requests and testing APIs.
curl https://example.com
curl -I https://example.com
curl -X GET https://api.example.com/health
-I fetches headers only, which is great for quick checks.
wget is commonly used to download files.
wget https://example.com/archive.tar.gz
Use curl for flexible request testing and wget when your main goal is downloading.
Inspecting Listening Ports with ss and netstat
ss is the modern tool for socket statistics.
ss -tuln
ss -tulpn
Useful flags:
-tTCP sockets-uUDP sockets-llistening only-nnumeric output, no DNS lookup-pprocess info
netstat may still appear in older guides:
netstat -tulnp
On newer systems, ss is usually preferred.
Basic Port Scanning with nmap
nmap helps discover open ports and services.
nmap localhost
nmap -p 22,80,443 example.com
Beginners should use it responsibly and only on systems they are authorized to scan.
Tip: Even a basic
nmapscan can quickly confirm whether a port is reachable from your current machine.
Remote Access with ssh
ssh is the standard tool for secure remote shell access.
ssh devops@server.example.com
ssh -i ~/.ssh/id_rsa devops@server.example.com
It is the backbone of Linux server administration.
If SSH fails, common causes include DNS issues, firewall rules, wrong keys, or the service not listening on the expected port.
File Transfer with scp and rsync
Use scp for straightforward secure copies.
scp app.conf devops@server:/etc/myapp/
scp devops@server:/var/log/app.log ./
Use rsync for more efficient sync behavior, especially on repeated transfers.
rsync -av ./site/ devops@server:/var/www/site/
rsync copies only changed data, which makes it great for deployments and backups.
/etc/hosts and DNS Resolution
DNS translates names like api.example.com into IP addresses. Linux can also use /etc/hosts for local name overrides.
Example entry:
10.0.0.15 internal-api.local
This is useful for testing or temporary overrides, but it can also create confusion if it points to an outdated address.
A good troubleshooting habit is checking whether a name resolves the way you expect.
A Practical Troubleshooting Flow
Suppose a service is “down.” You could check:
ip addr
ip route
ping api.example.com
curl -I https://api.example.com/health
ss -tulpn | grep 443
That sequence answers key questions:
- does the host have an IP?
- can it route traffic?
- does DNS work?
- does the web endpoint respond?
- is anything listening on the expected port?
Test Your Understanding
Let's see how well you understood the concepts! These exercises will help reinforce what you just learned.
Exercise 1: Diagnosing a name-resolution failure
Scenario: ping 8.8.8.8 works, but ping example.com fails.
Question: Based on the lesson, what is the most likely category of problem?
Exercise 1: Diagnosing a name-resolution failure
Decide what a working IP ping but failing hostname ping usually points to.
Exercise 2: Inspecting listening services
Question: Which command from the lesson is best for seeing listening TCP and UDP sockets with process information?
Exercise 2: Inspecting listening services
Choose the modern socket inspection command with listening and process details.
Exercise 3: Efficient repeated file syncs
Question: Why might rsync be a better fit than scp for sending a site directory to a server again and again?
Exercise 3: Efficient repeated file syncs
Identify the advantage rsync provides for repeated transfers.