Chapter 4: Linux Advanced Commands
4.7 Networking commands
| Command | Purpose | Example |
|---|---|---|
ip addr (ip a) |
Interfaces and IP addresses | ip -4 a |
ip route |
Routing table / default gateway | ip r |
ss -tulnp |
Listening TCP/UDP ports with process | sudo ss -tlnp |
netstat -tulnp |
Older equivalent of ss (package net-tools) |
sudo netstat -tlnp |
ping |
Reachability (ICMP) | ping -c 4 google.com |
curl |
HTTP client — test websites/APIs | curl -I http://localhost |
wget |
Download files | wget https://wordpress.org/latest.tar.gz |
dig / nslookup |
DNS lookup (package bind-utils or dnsutils) |
dig +short example.com |
traceroute / tracepath |
Route to a host | tracepath google.com |
nc (netcat) |
Test if a TCP port is open | nc -zv 10.0.1.25 3306 |
hostnamectl |
Show / set hostname | sudo hostnamectl set-hostname web01 |
sudo ss -tlnp # which programs listen on which ports?
sudo ss -tlnp | grep ':80 ' # is anything on port 80?
curl -I http://localhost # only response headers (HTTP status)
curl -s http://localhost:3000/api/health
curl -o page.html https://example.com
wget -q -O - https://checkip.amazonaws.com # print public IP
ping -c 3 8.8.8.8
Reading ss -tlnp output
0.0.0.0:80 or *:80 → listening on all interfaces (reachable from outside if the security group allows). 127.0.0.1:3000 → only reachable from the server itself (good for apps behind a reverse proxy).
ping to EC2 fails?
Security groups block ICMP by default. A failed ping does not mean the server is down — test with curl or nc on the actual port, or allow All ICMP – IPv4 from your IP for testing.
Installing missing network tools
# Ubuntu
sudo apt install -y net-tools dnsutils traceroute netcat-openbsd
# Amazon Linux 2023 / CentOS Stream 9
sudo yum install -y net-tools bind-utils traceroute nmap-ncat