Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 4: Linux Advanced Commands

4.7 Networking commands

Friends, the website won't open – is the problem in the server or in the network? These commands tell you in two minutes. The three you need most are ss, curl and dig.

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

Ravindra Bagale's Tip

Many students open 3000 in the security group without noticing that the app is running on 127.0.0.1:3000, and still nothing shows in the browser. If sudo ss -tlnp shows 127.0.0.1, it is reachable only from inside the server – put an Nginx reverse proxy in front. Only when you see 0.0.0.0 or * can a request come from outside (if the security group allows it).

Lab

Chala, tumchya EC2 var ip -4 a, ip r, sudo ss -tlnp aani curl -I http://localhost chalva, aani laptop varun nc -zv <PUBLIC_IP> 22 chalva. Pratyek output madhun ek goshta liha – IP, default gateway, listening ports aani HTTP status.