Catalog / Remote & Network Command-Line Cheatsheet

Remote & Network Command-Line Cheatsheet

A comprehensive cheat sheet for remote access, network diagnostics, and management commands in the command-line interface. This guide provides quick references and examples for common tasks.

Basic Network Information

Network Configuration

ip addr show or ifconfig

Displays network interface configurations including IP addresses, MAC addresses, and status.

ip route show or route -n

Shows the kernel’s IP routing table.
-n option displays numerical addresses instead of trying to determine symbolic host names.

netstat -rn

Displays network routing information, including the destination network, gateway, and interface.

hostname

Displays the system’s hostname.

hostname -I

Displays all IP addresses of the host.

resolvectl status

Show current DNS configuration. (systemd-resolved required)

DNS Lookup

nslookup <domain>

Queries DNS servers to find the IP address associated with a domain.

dig <domain>

A more advanced DNS lookup utility, providing detailed DNS record information.

host <domain>

Performs DNS lookups to find the IP address of a domain.

resolvectl query <domain>

Resolve domain name to IP addresses and vice versa using systemd-resolved.

cat /etc/resolv.conf

Check what DNS server is used.

Remote Access and File Transfer

Secure Shell (SSH)

ssh <user>@<host>

Connects to a remote host via SSH.

ssh -p <port> <user>@<host>

Connects to a remote host using a specific port.

ssh-copy-id <user>@<host>

Copies your public key to the remote host for passwordless login.

ssh -L <local_port>:<remote_host>:<remote_port> <user>@<ssh_server>

Creates a local port forwarding via SSH.

ssh -R <remote_port>:<local_host>:<local_port> <user>@<ssh_server>

Creates a remote port forwarding via SSH.

Secure Copy (SCP)

scp <file> <user>@<host>:<destination>

Copies a file to a remote host.

scp <user>@<host>:<file> <destination>

Copies a file from a remote host.

scp -r <directory> <user>@<host>:<destination>

Copies a directory recursively to a remote host.

scp -P <port> <file> <user>@<host>:<destination>

Copies a file to a remote host using a specific port.

rsync

rsync -avz <source> <destination>

Synchronizes files/directories between two locations (local or remote).
-a archive mode; -v verbose; -z compression.

rsync -avz <source> <user>@<host>:<destination>

Synchronizes files/directories to a remote host.

rsync -avz <user>@<host>:<source> <destination>

Synchronizes files/directories from a remote host.

Network Diagnostics

Ping

ping <host>

Tests network connectivity by sending ICMP echo requests to a host.

ping -c <count> <host>

Sends a specific number of ping requests.

ping -i <interval> <host>

Specifies the interval between ping requests in seconds.

ping -s <size> <host>

Sets the size of the ping packet.

Traceroute

traceroute <host>

Traces the route packets take to a destination host.

traceroute -m <max_hops> <host>

Sets the maximum number of hops to search for the destination.

traceroute -n <host>

Prints hop addresses numerically rather than symbolically.

netcat (nc)

nc -zv <host> <port>

Performs a port scan to check if a port is open. -z: zero-I/O mode, -v: verbose.

nc -l -p <port>

Listen on a specified port for incoming connections.

nc <host> <port>

Connect to a specified port on a remote host.

Network Management

Network Interface Management

ip link set <interface> up

Brings up a network interface.

ip link set <interface> down

Brings down a network interface.

ip addr add <ip_address>/<cidr> dev <interface>

Assigns an IP address to a network interface.

ip addr del <ip_address>/<cidr> dev <interface>

Removes an IP address from a network interface.

Firewall Management (iptables)

iptables -L

Lists the current iptables rules.

iptables -A INPUT -p tcp --dport <port> -j ACCEPT

Allows incoming TCP traffic on a specific port.

iptables -A INPUT -p tcp --dport <port> -j DROP

Blocks incoming TCP traffic on a specific port.

iptables -F

Flushes all existing iptables rules (use with caution).

Firewall Management (firewalld)

firewall-cmd --state

Check if firewalld is running.

firewall-cmd --list-all

Lists all settings of the default zone.

firewall-cmd --zone=public --add-port=<port>/tcp --permanent

Opens a port permanently in the public zone.

firewall-cmd --reload

Reloads firewalld to apply changes.