Networking Commands
When a website will not load, the cause could be anywhere: the server's network card, its IP address, a firewall, DNS, the web server itself or the app behind it. A handful of commands let you check each layer in turn, from "does this machine have an address?" to "what does the web server actually reply?".
This lesson teaches the modern tools: ip for addresses and routes, ss for open ports, ping for reachability, dig for DNS and curl and wget for HTTP. The examples use Priya's server shop-server, whose public address is 203.0.113.10.
ip: addresses, interfaces and routes
A network interface is a connection to a network, such as a wired card (eth0, enp1s0), Wi-Fi (wlp2s0) or lo, the loopback interface through which a machine talks to itself at 127.0.0.1. The ip command shows and changes them. Its -br (brief) option gives a neat one-line summary:
ip -br address
ip routelo UNKNOWN 127.0.0.1/8 ::1/128 eth0 UP 203.0.113.10/24 metric 100 fe80::f03c:94ff:fe12:3456/64 default via 203.0.113.1 dev eth0 proto dhcp src 203.0.113.10 metric 100 203.0.113.0/24 dev eth0 proto kernel scope link src 203.0.113.10 metric 100
eth0 is UP with IPv4 address 203.0.113.10 in a /24 network (256 addresses), plus an IPv6 link-local address starting with fe80. The default route says that traffic for anywhere outside the local network goes to the gateway 203.0.113.1, the router. No default route means no internet.
Useful variations: ip address show eth0 gives full details for one interface, ip -br link shows interfaces and their hardware (MAC) addresses, ip -4 address hides IPv6, and hostname -I prints just the addresses. ip commands can also change settings (for example sudo ip link set eth0 down), but such changes are lost at reboot; permanent settings belong in netplan, covered below.
ping: can I reach it?
ping sends small ICMP "echo request" packets and reports each reply and how long it took. -c sets how many to send; without it, ping runs until Ctrl+C.
ping -c 3 192.168.1.1PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data. 64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=2.31 ms 64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.87 ms 64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=2.05 ms --- 192.168.1.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2003ms rtt min/avg/max/mdev = 1.870/2.076/2.310/0.180 ms
Troubleshoot in order: ping your router, then a public IP address, then a name such as ubuntu.com. If the IP works but the name does not, the problem is DNS. Note that many servers and firewalls block ping, so "no reply" does not always mean "down". tracepath ubuntu.com (or traceroute, if installed) shows each router along the path and where packets stop.
ss: which ports are open?
A port is a number that identifies one service on a machine: 22 for SSH, 80 for HTTP, 443 for HTTPS, 3306 for MySQL. ss (socket statistics) lists network connections and listening ports. The combination -tulpn is worth memorising: tCP, uDP, listening only, show the process, numeric ports.
sudo ss -tulpnNetid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
udp UNCONN 0 0 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=512,fd=14))
tcp LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=512,fd=15))
tcp LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=845,fd=5),("nginx",pid=846,fd=5))
tcp LISTEN 0 4096 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1033,fd=3),("systemd",pid=1,fd=63))
tcp LISTEN 0 4096 127.0.0.1:3306 0.0.0.0:* users:(("mysqld",pid=1120,fd=21))Read the Local Address column carefully. 0.0.0.0:80 means nginx accepts connections on port 80 from any network: reachable from the internet. 127.0.0.1:3306 means MySQL listens only on loopback, so only programs on this server can reach it, which is exactly what you want for a database. ss -tn (without -l) shows current connections instead, for example who is connected over SSH right now.
dig: DNS lookups
DNS turns names like shop.example.in into IP addresses. dig asks DNS servers directly and shows the answer. +short prints only the result:
dig +short shop.example.in
dig shop.example.in A @1.1.1.1203.0.113.10 ... ;; ANSWER SECTION: shop.example.in. 3600 IN A 203.0.113.10 ;; Query time: 24 msec ;; SERVER: 1.1.1.1#53(1.1.1.1) (UDP)
The second form asks a specific DNS server (@1.1.1.1) for an A record (IPv4 address). The 3600 is the TTL: how many seconds other servers may cache the answer, which is why DNS changes take time to spread. Other record types: AAAA (IPv6), MX (mail), TXT, CNAME. If dig is missing, install bind9-dnsutils; the simpler host shop.example.in gives a one-line answer. resolvectl status shows which DNS servers this machine itself uses.
curl and wget: talk HTTP
curl sends a request to a URL and prints the response. It is the quickest way to test a web server or an API from the command line:
curl -I https://shop.example.in
curl -s https://shop.example.in/api/health
curl -o menu.pdf https://shop.example.in/menu.pdfHTTP/2 200
server: nginx
date: Fri, 30 Oct 2026 05:14:09 GMT
content-type: text/html
content-length: 5120
last-modified: Wed, 28 Oct 2026 16:00:12 GMT
{"status":"ok","orders_today":42}-I fetches only the headers: the status code (200 OK, 301 redirect, 404 not found, 500 server error) and details such as the server type and content type. -s hides the progress meter, -o saves the body to a file, -L follows redirects, and -X POST -d '{"item":"ladoo"}' -H "Content-Type: application/json" sends data to an API.
wget is designed for downloading. It saves to a file by default, can resume with -c and can fetch many files: wget -c https://releases.ubuntu.com/26.04/ubuntu-26.04-live-server-amd64.iso.
Permanent settings with netplan
Ubuntu stores network settings in YAML files in /etc/netplan/. Cloud servers usually get their address by DHCP and need no changes, but a home server often needs a fixed address. A file such as /etc/netplan/50-static.yaml might contain:
network:
version: 2
ethernets:
eth0:
addresses:
- 192.168.1.50/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses: [1.1.1.1, 9.9.9.9]Apply it with sudo netplan try, which rolls the change back automatically after two minutes unless you press Enter to confirm. That protects you from locking yourself out of a remote server. Indentation must be spaces, never tabs, and the file should be readable only by root (chmod 600).
Common mistakes
- Assuming "no ping reply" means "down". Many hosts block ICMP. Test the actual service with
curlorss. - A database listening on
0.0.0.0. That exposes it to the network. Bind it to127.0.0.1unless remote access is truly needed. - Changing addresses with
ipand expecting them to survive reboot. Use netplan for permanent settings. - Editing netplan over SSH with
apply. A typo can cut your connection; usenetplan try.
Key points
ip -br addressshows interfaces and addresses;ip routeshows the default gateway.ping -c 3 hosttests reachability; check the router, a public IP, then a name.sudo ss -tulpnlists listening ports and the programs behind them;0.0.0.0means all networks,127.0.0.1means local only.dig +short nameresolves DNS;curl -I urlshows HTTP headers and status codes;wgetdownloads files.- Permanent network settings live in
/etc/netplan/; apply them safely withnetplan try.
Exercise
Priya's website shop.example.in is not loading in her browser. List, in order, the commands she should run on the server and from her laptop to find which layer is failing: the server's IP and gateway, internet reachability, DNS, whether nginx is listening, and the HTTP reply both locally and from outside.
Show solution
ip -br address
ip route
ping -c 3 1.1.1.1
dig +short shop.example.in
sudo ss -tlpn | grep -E ':(80|443) '
curl -I http://localhost
curl -I https://shop.example.in...
203.0.113.10
tcp LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=845,fd=5),("nginx",pid=846,fd=5))
HTTP/1.1 200 OK
curl: (28) Failed to connect to shop.example.in port 443 after 10002 ms: Timeout was reachedThe server has an address, DNS points to it, nginx answers locally on port 80, but nothing listens on 443 and the HTTPS request times out. The next steps are to set up HTTPS in nginx and check that the firewall allows port 443, as in the final project.
Quick Quiz
1. Which command shows the IP addresses of all interfaces in short form?
ip -br address prints one line per interface with its addresses.
2. In ss -tulpn output, MySQL shows 127.0.0.1:3306. What does that mean?
127.0.0.1 is loopback, so only local programs can connect.
3. ping 1.1.1.1 works but ping ubuntu.com says the name cannot be resolved. What is the likely problem?
The network works by IP, so name resolution (DNS) is failing.
4. Which command fetches only the HTTP headers of a page?
-I sends a HEAD request and prints just the status line and headers.
Learn Linux with a mentor
Free lessons get you started. Our Ethical Hacking & Cyber Security training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
