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.

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 .

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.

One blank again: combine the four flags (TCP, UDP, listening, numeric) into the right option for ss . Then run it.

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.

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.