SSH Command in Linux with examples

Networking commands in Linux

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

Watch: Linux Network Troubleshooting Basics: ping, curl, ss & ip

Read the video transcript

Every server lives on a network. In this video, you'll learn the commands to see your network settings, test connections, look up names, and check which ports are open. All live, on a real Ubuntu server, with SSH Command. We're connected, with the Shell view open. Everything we run now is on the server's network, not yours. ip -br -4 a lists the network interfaces and their IPv4 addresses. -br means brief, and -4 means IPv4 only. lo is the loopback, always 127.0.0.1. eth0 is the real network card, with a private address. ip route show default prints the default route. The gateway is the first stop for traffic leaving this network. ping sends small test packets and times the replies. -c 4 stops after four. Here the replies take a few milliseconds, and nothing is lost: the server can reach the internet. dig looks up a name in DNS. +short prints just the answer: the IP addresses behind example.com. curl talks to web servers. -I asks for the headers only, and -s hides the progress bar. HTTP/2 200 means success. ss lists network sockets. -t is TCP, -u is UDP, -l is listening only, and -n shows numbers. Port 22 is SSH, the service you're connected through. Ports 21 and 990 are FTP. Every listening port is a door, so close the ones you don't need. nc, with -z and -v, tests whether a port is open without sending any data. Port 443 on example.com succeeded, so HTTPS is reachable. And the search bar in SSH Command has ready-made network commands. Type ping, and copy one. That's the essentials of Linux networking: ip for your settings, ping, dig and curl to test, and ss and nc for ports. The full guide is at sshcommand.com, under network commands. SSH Command is free for personal use. The link is in the description. Thanks for watching.

#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