Network & port commands

Find what’s using a port and stop it, look up DNS, check your public IP, test connections, inspect HTTP headers and check when an SSL certificate expires.

15 commands

What is using this port?

macOSLinux

Shows the program and PID listening on or connected to the port.

lsof -i :

Free a port (kill whatever is on it)

macOSLinuxCareful

Force-stops every process using the port. Fixes "address already in use".

kill -9 $(lsof -ti :)

Force-kills without letting the program save. Check with lsof -i first.

Free a port on Windows

WindowsPowerShellCareful

Finds the process listening on the port and stops it.

Stop-Process -Id (Get-NetTCPConnection -LocalPort ).OwningProcess -Force

All listening ports (macOS)

macOSAdmin

Every program accepting connections, with numeric addresses and ports.

sudo lsof -iTCP -sTCP:LISTEN -n -P

Your public IP address

macOSWindowsLinux

The IP the internet sees you as.

curl -s https://ifconfig.me

Look up a domain’s IP (DNS)

macOSLinux

Prints the addresses a domain resolves to. Add a record type like MX or TXT after the domain.

dig +short

DNS lookup on Windows

WindowsPowerShell/CMD

Shows the DNS server used and the addresses for a domain.

nslookup

Ping a host

macOSLinux

Sends four pings and reports latency and packet loss. (On Windows, just ping host.)

ping -c 4

Trace the route to a host

macOSLinux

Lists every hop between you and the destination. On Windows use tracert.

traceroute

See a site’s HTTP headers

macOSWindowsLinux

Fetches only the response headers: status code, caching, redirects, server.

curl -I

Download a file

macOSWindowsLinux

Saves the file with its original name, following redirects.

curl -LO

How long does a request take?

macOSLinux

Prints the total time for one request.

curl -o /dev/null -s -w "%{time_total}s\n"

When does a site’s SSL certificate expire?

macOSLinux

Shows the certificate’s valid-from and valid-until dates.

echo | openssl s_client -connect :443 -servername 2>/dev/null | openssl x509 -noout -dates

Share a folder over HTTP

macOSWindowsLinux

Serves the current folder at http://localhost:8000. Great for testing static sites.

python3 -m http.server

Who owns a domain

macOSLinux

Registrar, creation and expiry dates and name servers.

whois

Every command copies as plain, clean text: no curly quotes, no long dashes, no invisible characters.

Related guides