Networking commands
IP addresses and ports, ip, ping, ss, curl, dig, traceroute and a troubleshooting checklist.
Almost everything a server does involves the network: serving web pages, talking to a database, pulling packages, receiving SSH connections. When something "can't connect", you need to work out where the chain breaks. This lesson covers the core concepts (IP addresses, ports, DNS, routes) and the modern Linux tools to inspect and troubleshoot each layer: ip, ping, ss, dig, curl and traceroute.
The 60-second networking primer#
- IP address: a machine's address on a network. IPv4 looks like
192.168.1.20, IPv6 like2001:db8::20. - Private ranges (
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16) are used inside LANs and clouds and aren't reachable from the internet directly.127.0.0.1(localhost) is the machine itself. - CIDR notation:
/24means the first 24 bits are the network, so192.168.1.0/24covers192.168.1.0–192.168.1.255. - Gateway / default route: where packets for other networks go (usually your router).
- Port: a number (0–65535) identifying a service on a machine. 22 is SSH, 80 HTTP, 443 HTTPS, 3306 MySQL, 5432 PostgreSQL. Ports below 1024 need root to bind.
- TCP is reliable and connection-based (web, SSH, databases); UDP is connectionless and fast (DNS, video, games).
- DNS turns names (
example.com) into IP addresses.
To connect to https://example.com, your machine needs to: resolve the name (DNS) → route packets to that IP (gateway) → reach port 443 (firewall) → find a service listening there.
Your addresses and interfaces: ip#
ip (package iproute2) replaces the old ifconfig and route commands:
lois the loopback interface.enp0s3,eth0orens5is the wired/virtual NIC, andwlp2s0is Wi-Fi. Modern names encode the hardware location.docker0is a bridge created by Docker.
The default via 192.168.1.1 line is your gateway. ip route get 8.8.8.8 shows which route and source address a specific destination would use.
Changes made with ip (such as sudo ip addr add 10.0.0.5/24 dev eth0) are temporary and vanish at reboot. Permanent configuration lives in Netplan YAML on Ubuntu (/etc/netplan/*.yaml, applied with sudo netplan apply), or in NetworkManager on desktops and Fedora/RHEL (nmcli, nmtui).
Your public IP (as the internet sees it, after NAT) is different: curl -s https://ifconfig.me.
Is it reachable? ping#
-c 3 stops after 3 packets (without it, ping runs until Ctrl+C). Look at the packet loss and the time (latency). Many cloud servers and firewalls block ICMP, so a failed ping doesn't always mean the host is down. Test the actual port instead (see below).
Where does it break? traceroute and mtr#
Each line is a hop (router) on the way. * * * means that hop doesn't answer probes, which is common and only a concern if every hop after it is also silent.
DNS: names to addresses#
(dig prints more sections; the important parts are shown.) dig comes from dnsutils on Debian/Ubuntu and bind-utils on Fedora. Useful queries:
/etc/hostsholds static name → IP mappings, checked before DNS. It's handy for testing (203.0.113.10 staging.example.com).- On Ubuntu,
/etc/resolv.confpoints to127.0.0.53, the local systemd-resolved stub, which forwards to the real DNS servers.resolvectl statusshows those servers. - If
dig @1.1.1.1 nameworks butdig namedoesn't, your configured resolver is the problem.
Which ports are open? ss#
ss (socket statistics) replaces the old netstat:
Flags: -t TCP, -u UDP, -l listening only, -n numeric (no name lookups), -p show the process. The local address matters a lot:
0.0.0.0:80or[::]:80: listening on all interfaces, so it's reachable from other machines (if the firewall allows).127.0.0.1:3306: localhost only. MySQL here can't be reached remotely, which is a safe default.
Other handy forms: ss -tn (established TCP connections), ss -s (summary counts), ss -tnp state established '( dport = :443 )'. sudo lsof -i :8080 also answers "who is using port 8080?".
Talking HTTP: curl#
curl is the Swiss-army knife for testing web services and APIs:
(That's the output of the -w line: the status code and total time.) -f makes curl exit non-zero on HTTP errors (4xx/5xx), which is essential in scripts. -s is silent and -S still shows errors. wget is the simpler download-only alternative: wget https://example.com/file.tar.gz.
Testing a TCP port#
Is something listening, and does the firewall let you through?
How to read the result:
A troubleshooting checklist#
When "the app can't reach the server", work up the layers:
- Local interface:
ip -br addr. Do I have an IP? Is the link up? - Gateway:
ip routeandping -c 2 <gateway>. - Internet / remote network:
ping -c 2 1.1.1.1(an IP, so DNS isn't involved yet). - DNS:
dig +short name/getent hosts name. Does it resolve, and to the right IP? - Port reachability:
nc -zv host port. Refused or timeout? - On the server:
sudo ss -tlnp. Is the service listening, on the right interface (0.0.0.0vs127.0.0.1)? - Firewalls:
sudo ufw status/sudo firewall-cmd --list-allon the server, plus cloud security groups. - Application:
curl -v, then the service logs (journalctl -u service).
Working this list in order turns "the network is broken" into a precise diagnosis.
Downloading and copying files over the network#
curl -O URL and wget URL fetch files over HTTP(S). To copy between your own machines, use SSH-based tools, scp and rsync, which are covered in the next lesson.
Common mistakes#
- Assuming a failed ping means the host is down. ICMP is often blocked; test the real port.
- A service bound to
127.0.0.1and then wondering why other machines can't connect. Checkss -tlnp. - Forgetting the cloud firewall (AWS security groups, GCP firewall rules) in addition to the host firewall.
- Editing
/etc/resolv.confby hand on Ubuntu. It's managed by systemd-resolved/Netplan, and your changes get overwritten. - Temporary
ip addr addchanges that disappear at reboot. Use Netplan or NetworkManager for permanent config. - Piping
curl | bashfrom unknown sources. Download the script, read it, then run it.
What's next#
The most important network service for an admin is SSH. Next you'll log in to remote machines securely with keys, configure ~/.ssh/config, create tunnels, and copy files with scp and rsync.
Check your understanding
Quick quiz
1.Which command shows which processes are listening on TCP ports?
2.
curl http://10.0.0.5:8080works, butcurl http://api.internal:8080fails with 'Could not resolve host'. Where is the problem?3.What does 'Connection refused' (as opposed to a timeout) usually tell you?
Finished reading?
Mark this lesson complete to track your progress.