Skip to content

Linux & shell: Network & DNS

Linux & shell commands for network & dns (tags: #network #dns #http).

Index
4 items

Linux: List listening ports and owning processes

Safe

TCP/UDP listening sockets with the PID/program that owns each one.

sudo ss -tulpn
What each part does
  1. sudo sssocket statistics (sudo to see other users' processes)
  2. -tuTCP and UDP sockets
  3. -llistening only
  4. -pshow the owning process and PID
  5. -nnumeric ports and addresses, no name lookups

Also known as: netstat -tulpn · port in use · address already in use · EADDRINUSE

Linux: Debug an HTTP request verbosely

Safe

Shows TLS handshake, request/response headers, final status code and total time.

curl -v -sS -o /dev/null -w "%{http_code} %{time_total}s\n" <url>
What each part does
  1. curlmake an HTTP request
  2. -vverbose: DNS, connect, TLS handshake, request and response headers
  3. -sShide the progress bar, still show errors
  4. -o /dev/nullthrow away the response body
  5. -w "%{http_code} %{time_total}s\n"after the request, print the status code and total time
  6. <url>the URL
Example
< HTTP/2 503
< retry-after: 30
503 0.214s

Also known as: curl -v · http debug · ssl handshake · connection refused

Linux: Resolve DNS for a host

Safe

Quick A/CNAME lookup. Use dig @<resolver> <hostname> to compare against a specific DNS server.

dig +short <hostname>
What each part does
  1. digDNS lookup tool
  2. +shortprint only the answers (IPs or CNAME targets)
  3. <hostname>the name to resolve; add @<server> to ask a specific DNS server

Also known as: nslookup · dns lookup · NXDOMAIN · could not resolve host

Linux: Open an SSH tunnel through a bastion

Safe

Forward a local port to a private host/port via a jump box. Then connect to localhost:<local-port>.

ssh -N -L <local-port>:<target-host>:<target-port> <user>@<bastion>
What each part does
  1. sshSSH client
  2. -Ndon't run a remote command: tunnel only
  3. -L <local-port>:<target-host>:<target-port>localhost:local-port forwards to target-host:target-port as seen from the bastion
  4. <user>@<bastion>the jump host to connect to
Example
$ ssh -N -L 5432:db.internal:5432 ops@bastion.example.com

Also known as: port forward · bastion · jump host · ssh tunnel

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…