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.
मित्रांनो, वेबसाइट उघडत नाही – प्रॉब्लेम सर्व्हरमध्ये आहे की नेटवर्कमध्ये? या कमांड्स तुम्हाला दोन मिनिटांत सांगतात. सगळ्यात जास्त लागणाऱ्या तीन म्हणजे ss, curl आणि dig.
दोस्तों, वेबसाइट नहीं खुल रही – प्रॉब्लम सर्वर में है या नेटवर्क में? ये कमांड्स आपको दो मिनट में बताती हैं. सबसे ज़्यादा काम आने वाली तीन हैं ss, curl और 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).
Ravindra Bagale's Tip – मराठी
बरेच students app 127.0.0.1:3000 वर चालू आहे हे न बघता security group मध्ये 3000 उघडतात, आणि तरी browser मध्ये काही दिसत नाही. sudo ss -tlnp मध्ये 127.0.0.1 दिसला तर ते फक्त server मधूनच reachable आहे – समोर Nginx reverse proxy लावा. 0.0.0.0 किंवा * दिसला तरच बाहेरून (security group allow करत असेल तर) request येते.
Ravindra Bagale's Tip – हिंदी
बहुत से students app 127.0.0.1:3000 पर चल रहा है ये देखे बिना security group में 3000 खोल देते हैं, और फिर भी browser में कुछ नहीं दिखता. sudo ss -tlnp में 127.0.0.1 दिखे तो वो सिर्फ़ server के अंदर से reachable है – सामने Nginx reverse proxy लगाओ. 0.0.0.0 या * दिखे तभी बाहर से (security group allow करे तो) request आती है.
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.