SSH Command in Linux with examples

Networking commands in Linux

Check connections, addresses, DNS and ports; download things; manage the firewall.

#ip

Network addresses and routes

Syntaxip [object] [command]
  • ip a

    Show interfaces and IP addresses

  • ip r

    Show the routing table

  • ip -br a

    Short, one line per interface

#ping

Test if a host answers

Syntaxping [options] host
  • ping -c 4 example.com

    Send four packets and stop

  • ping -c 4 8.8.8.8

    Test the internet without involving DNS

#ss

Show listening ports and connections

Syntaxss [options]
  • ss -tulpn

    Listening TCP/UDP ports and the program using each (use sudo to see all)

  • ss -t state established

    Active TCP connections

#netstat

Older port listing

Syntaxnetstat -tulpn
  • sudo netstat -tulpn

    Same idea as ss on older systems

#curl

Talk to web servers

Syntaxcurl [options] URL
  • curl https://example.com

    Print the page

  • curl -I https://example.com

    Only the response headers

  • curl -o file.zip https://example.com/file.zip

    Save to a file

  • curl -X POST -d '{"a":1}' -H "Content-Type: application/json" https://api.example.com

    Send data to an API

  • curl -sS https://ifconfig.me

    Your public IP address

#wget

Download files

Syntaxwget [options] URL
  • wget https://example.com/file.zip

    Download a file

  • wget -c https://example.com/big.iso

    Resume a broken download

  • wget -r -np https://example.com/docs/

    Download a folder of pages

#dig

DNS lookups

Syntaxdig [name] [type]
  • dig example.com

    Full answer

  • dig +short example.com

    Only the address

  • dig MX example.com

    Mail servers

#nslookup

Simple DNS lookup

Syntaxnslookup name
  • nslookup example.com

    Resolve a name

#traceroute

Show the route packets take

Syntaxtraceroute host
  • traceroute example.com

    Every hop to the destination

  • mtr example.com

    Live version that also shows packet loss

Tiptraceroute and mtr are not installed on a fresh Ubuntu. Add them with sudo apt install traceroute mtr-tiny.

#nc

Test ports, send raw data

Syntaxnc [options] host port
  • nc -zv example.com 443

    Is port 443 open?

  • nc -l 9000

    Listen on port 9000

#ufw

Simple firewall (Ubuntu)

Syntaxsudo ufw action
  • sudo ufw status verbose

    Show the rules

  • sudo ufw allow 22/tcp

    Allow SSH

  • sudo ufw allow from 203.0.113.5 to any port 5432

    Allow one address to one port

  • sudo ufw enable

    Turn it on (allow SSH first!)

CarefulEnabling a firewall without allowing SSH first can lock you out of the server.

#iptables / nft

Firewall (advanced)

Syntaxsudo iptables -L
  • sudo iptables -L -n -v

    List rules with counters

  • sudo nft list ruleset

    The newer nftables listing

#ifconfig

Old interface tool

Syntaxifconfig
  • ifconfig

    Same as ip a on older systems

Run these commands with SSH Command

SSH Command is a desktop app for Mac, Windows and Linux that puts a real terminal, SFTP file panes, a sudo switch and a searchable Linux command finder in one window. Type what you want to do, and send the command to your server with one click.

Download free Windows commands with examples SFTP & FTP client