Networking Commands
By the end of this lesson you'll be able to diagnose a network from the terminal: check whether a host is up, fetch URLs and download files, see your own IP, find what is listening on a port, resolve domain names, and trace the path packets take.
Learn Networking Commands in our free Command Line course — an interactive lesson with worked examples, a practice exercise and a quick reference.
Part of the free Cli course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
What You'll Learn
1. ping: Is the Host Reachable?
ping <host> sends small ICMP echo requests and waits for replies, so it answers two questions at once: can I reach this host , and how fast (the round-trip time ). By default ping keeps going until you press Ctrl+C ; add -c 4 to send exactly four packets and stop. Watch the packet loss line in the summary — 0% is healthy.
2. HTTP from the Terminal: curl & wget
Two tools fetch things over the web. curl <url> prints a URL to the screen — add -I for just the response headers, or -O to save it to a file. wget <url> downloads a file to disk, and wget -O name url sets the output filename. In short: reach for curl to inspect APIs and headers, and wget to download or mirror files.
3. Your Interfaces & IP: ip addr
ip addr (short: ip a ) lists every network interface and the IP addresses assigned to it. lo is loopback (your own machine, 127.0.0.1 ); eth0 / wlan0 is your wired/wireless link with its real address like 192.168.1.42 . On modern Linux this replaces the older ifconfig , which is legacy/deprecated on Linux but still standard on macOS.
4. What's Listening? ss -tuln
When you need to know which service is listening on a port , use ss -tuln . The flags read like a sentence: t = TCP, u = UDP, l = listening, n = numeric (show port numbers instead of names). Scan the Local Address:Port column to find, say, :8080 . The older netstat -tuln does exactly the same job on systems without ss .
5. Resolving Names: dig, nslookup & host
DNS turns a name like example.com into an IP address. Three tools do the lookup: host <domain> gives a one-line answer, nslookup <domain> is the classic tool that also shows the server it asked, and dig <domain> gives the most detailed view. For scripts, dig +short example.com prints just the IP — nothing else.
6. The Path & Remote Access: traceroute & ssh
traceroute <host> (called tracert on Windows) shows every hop — each router between you and the destination — along with how long each takes. It's how you spot where a connection slows down or stops. To actually work on a remote machine, ssh user@host opens a secure shell on it; the dedicated SSH lesson covers keys and config.
7. Ports & /etc/hosts
A port number identifies a specific service on a host: 22 is SSH, 80 is HTTP, 443 is HTTPS, 53 is DNS. So 192.168.1.42:443 means "the HTTPS service on that machine". The /etc/hosts file is a local hostname-to-IP map that the system checks before DNS — perfect for local overrides, like pointing a test name at 127.0.0.1 .
🎯 Your Turn: ping a fixed number of times
Fill in the one blank marked ___ using the # 👉 hint so ping sends a fixed count and stops on its own, then run it and check the Output panel.
🎯 Your Turn: list listening ports
One blank again: combine the four flags (TCP, UDP, listening, numeric) into the right option for ss . Then run it.
Pro Tips
- 💡 Practical recipe: to debug "the site is down", check connectivity ( ping / curl -I ), check what is listening ( ss -tuln ), then resolve the name ( dig / nslookup ).
- 💡 dig +short for scripts: it prints only the IP, so you can drop it straight into a variable or another command.
- 💡 curl prints, wget downloads: remember the split — curl for APIs and headers, wget for saving files to disk.
- 💡 Modern over legacy: prefer ip addr over ifconfig and ss over netstat — same ideas, current tools.
Common Errors (and the fix)
- ping never stops — that's normal: by default it runs forever. Press Ctrl+C to stop, or use ping -c 4 host to send a fixed number.
- "command not found: ifconfig" (or netstat) — these legacy tools may not be installed on modern Linux. Use ip addr and ss -tuln instead.
- ping fails but the website works — many servers block ICMP. A failed ping doesn't always mean "down"; confirm with curl -I https://host .
- "could not resolve host" — a DNS problem, not a connectivity one. Test resolution directly with dig example.com or nslookup example.com .
- "Permission denied" editing /etc/hosts — that file is system-owned. Open it with sudo (e.g. sudo nano /etc/hosts ) to change it.
📋 Quick Reference
Task
Command
Notes
Reachability
ping -c 4 host
Ctrl+C to stop; watch packet loss
Fetch a URL
curl url
-I for headers, -O to save
Download a file
wget url
-O name sets the filename
Interfaces & IPs
ip addr
ip a for short; replaces ifconfig
Listening ports
ss -tuln
or netstat -tuln
Resolve a name
dig +short host
or nslookup / host
Trace the path
traceroute host
tracert on Windows
Remote shell
ssh user@host
Encrypted; see SSH lesson
Common ports
22 / 80 / 443
SSH / HTTP / HTTPS
Local name map
/etc/hosts
Checked before DNS
Frequently Asked Questions
Mini-Challenge: a server health check
No blanks this time — just a brief. Combine what you've learned into a small, repeatable routine that resolves a host, confirms it's reachable, and checks that its web service is responding. Compare your results against the notes in the comments.
🎉 Lesson Complete!
- ✅ ping -c 4 host tests reachability and latency; Ctrl+C stops a running ping
- ✅ curl prints URLs and headers ( -I , -O ); wget downloads files to disk
- ✅ ip addr shows interfaces and IPs (replacing legacy ifconfig ); ss -tuln lists listening ports
- ✅ dig / nslookup / host resolve names; dig +short prints just the IP
- ✅ traceroute shows the path; ports identify services; /etc/hosts overrides DNS locally
- ✅ Next lesson: Advanced Bash Scripting — take your scripts further with arrays, traps, and robust error handling
Practice quiz
Which command tests whether a host is reachable and measures round-trip latency?
- ping example.com
- ls example.com
- cd example.com
- cat example.com
Answer: ping example.com. ping sends ICMP echo requests and reports the round-trip time for each reply.
Which command shows your network interfaces and their IP addresses on modern Linux?
- kill addr
- ping -c 4 localhost
- ip addr
- wget addr
Answer: ip addr. ip addr (short form ip a) lists interfaces and their IPs; it replaces the older ifconfig.
Which command lists listening TCP and UDP ports on a modern system?
- traceroute -tuln
- ss -tuln
- curl -tuln
- dig -tuln
Answer: ss -tuln. ss -tuln (or the older netstat -tuln) lists listening TCP/UDP sockets numerically.
Which command resolves a domain name to an IP address?
- chmod example.com
- rm example.com
- echo example.com
- dig example.com
Answer: dig example.com. dig (and the simpler nslookup or host) queries DNS to resolve a name to its IP address.
Which command shows the route, hop by hop, that packets take to reach a host?
- traceroute example.com
- touch example.com
- grep example.com
- mv example.com
Answer: traceroute example.com. traceroute (tracert on Windows) lists each router hop on the path to the host.
Which tool is best suited to downloading a file to disk?
- ssh
- wget
- ping
- nslookup
Answer: wget. wget is designed for downloading and mirroring files to disk; curl is geared toward printing and API calls.
What does curl -I do?
- Opens an interactive shell
- Downloads the page and saves it
- Pings the server first
- Shows only the HTTP response headers
Answer: Shows only the HTTP response headers. The -I flag makes curl issue a HEAD request and print only the response headers.
What is the standard port number for HTTPS?
- 80
- 21
- 443
- 22
Answer: 443. HTTPS uses port 443 by default; HTTP uses 80 and SSH uses 22.
What is the purpose of the /etc/hosts file?
- It logs every ping you send
- It maps hostnames to IPs locally and is checked before DNS
- It stores your SSH keys
- It lists open ports
Answer: It maps hostnames to IPs locally and is checked before DNS. /etc/hosts is a local hostname-to-IP map consulted before DNS, handy for local overrides.
Which command connects you to a remote machine over the network?
- ssh user@host
- ss -tuln
- ping host
- ip addr
Answer: ssh user@host. ssh user@host opens an encrypted shell session on the remote machine.
Continue this course
- Previous: Scheduling Tasks with cron
- Next: Advanced Bash Scripting