Skip to content

Networking commands, SSH, DNS, and troubleshooting reference.

Networking commands help you connect to remote systems, move files, inspect interfaces, troubleshoot DNS, monitor traffic, and manage firewall rules from the command line.

Use SSH to log in to remote servers, run commands, and create encrypted tunnels:

Terminal window
ssh username@remote_host # Log in to a remote server
ssh -p port_number username@remote_host # Connect on a specific port
ssh username@remote_host command_to_run # Run a command remotely
ssh -i /path/to/private_key username@remote_host # Authenticate with a private key
ssh-copy-id username@remote_host # Copy public key for passwordless SSH

Forward ports when you need to reach services through an SSH connection:

Terminal window
ssh -L local_port:destination_host:destination_port username@remote_host # Local port forwarding
ssh -R remote_port:destination_host:destination_port username@remote_host # Reverse port forwarding

Use scp for simple encrypted file copies over SSH:

Terminal window
scp /path/to/local_file username@remote_host:/path/to/remote_dir # Local file to remote
scp username@remote_host:/path/to/remote_file /path/to/local_dir # Remote file to local
scp -r /path/to/local_dir username@remote_host:/path/to/remote_dir # Copy directory recursively

Use rsync when you need efficient incremental transfers:

Terminal window
rsync -avz /path/to/local_dir username@remote_host:/path/to/remote_dir # Sync local to remote
rsync -avz username@remote_host:/path/to/remote_dir /path/to/local_dir # Sync remote to local
rsync -avz --delete /path/to/source_dir username@remote_host:/path/to/destination_dir # Delete destination files missing from source

Start with simple reachability checks before moving into deeper diagnostics:

Terminal window
ping remote_host # Check whether a host responds
traceroute remote_host # Trace the route packets take to a host
nc -zv remote_host port_number # Test whether a specific TCP port is reachable

Inspect listening services and open ports on local or remote systems:

Terminal window
nmap remote_host # Scan open ports on a remote host
netstat -an # Show active connections and listening ports
ss -tuln # Show TCP/UDP listening sockets

Display interface names, addresses, and link information:

Terminal window
ip addr # Show interfaces and IP addresses
ifconfig # Legacy interface display command

Review routing decisions and update host identity:

Terminal window
ip route # View routing table
ip route add destination_network via gateway_ip dev interface # Add a static route
sudo hostnamectl set-hostname new_hostname # Change system hostname

Use DNS tools to verify records and troubleshoot name resolution:

Terminal window
nslookup domain_name # Query DNS for a domain
dig domain_name # Perform a detailed DNS query
dig domain_name A # Query A records
dig domain_name MX # Query mail exchange records
dig @dns_server domain_name # Query a specific DNS server

Capture packets or watch bandwidth usage on an interface:

Terminal window
tcpdump -i interface # Monitor traffic on an interface
tcpdump -i interface port 443 # Capture traffic for a specific port
iftop -i interface # Show bandwidth usage by connection

Inspect files opened by a process or stop processes that are causing trouble:

Terminal window
lsof -p process_id # View open files used by a process
pkill process_name # Kill a process by name
kill -9 process_id # Force kill a process by PID

Use UFW to manage common Linux firewall rules:

Terminal window
sudo ufw enable # Enable UFW
sudo ufw status # Check firewall status
sudo ufw allow port_number # Allow traffic on a specific port
sudo ufw allow 22/tcp # Allow SSH over TCP
sudo ufw deny port_number # Deny traffic on a specific port

Use these commands to fetch files and check external connectivity:

Terminal window
speedtest-cli # Check internet speed
wget file_url # Download a file
curl -O file_url # Download a file and keep the remote filename
curl -I https://example.com # Fetch HTTP response headers