Catalog / Networking Commands Cheatsheet

Networking Commands Cheatsheet

A quick reference guide to essential networking commands for troubleshooting, configuration, and monitoring network connectivity. This cheatsheet provides concise information on commonly used commands across various operating systems.

Basic Network Information

IP Configuration

ipconfig (Windows)

Displays IP address, subnet mask, default gateway, and DNS settings.

Example:

ipconfig /all

ifconfig (Linux/macOS)

Configures network interfaces and displays IP address information.

Example:

ifconfig eth0

ip addr (Linux)

Modern replacement for ifconfig, displays detailed IP information.

Example:

ip addr show eth0

hostname -I (Linux)

Displays the IP address(es) of the host.

Example:

hostname -I

nslookup <hostname>

Query DNS server to obtain domain name or IP address mapping, or other DNS records.

Example:

nslookup google.com

Routing Information

route print (Windows)

Displays the routing table.

Example:

route print

netstat -r (Windows)

Also displays the routing table.

Example:

netstat -r

route -n (Linux/macOS)

Displays the kernel IP routing table.

Example:

route -n

traceroute <destination> (Linux/macOS)

Traces the route packets take to a network host.

Example:

traceroute google.com

tracert <destination> (Windows)

The Windows version of traceroute.

Example:

tracert google.com

Network Statistics

netstat -a

Displays all active TCP connections and listening ports.

Example:

netstat -a

netstat -an

Displays active TCP connections and ports (numerical).

Example:

netstat -an

netstat -tulpn (Linux)

Shows listening TCP and UDP ports with process ID.

Example:

netstat -tulpn

ss -tulpn (Linux)

Another utility to investigate sockets.

Example:

ss -tulpn

Connectivity Testing

Ping

ping <destination>

Tests connectivity to a network host.

Example:

ping google.com

ping -t <destination> (Windows)

Pings the specified host until stopped.

Example:

ping -t google.com

ping -c <count> <destination> (Linux/macOS)

Sends a specified number of ICMP echo requests.

Example:

ping -c 4 google.com

Telnet & Netcat

telnet <host> <port>

Tests connectivity to a specific port on a host.

Example:

telnet google.com 80

nc -zv <host> <port>

Netcat: versatile tool for network connections.

Example:

nc -zv google.com 80

nc -l -p <port>

Netcat: Listens on a specific port.

Example:

nc -l -p 12345

Pathping (Windows)

pathping <destination>

Provides information about network latency and packet loss at intermediate hops between a source and a destination.

Example:

pathping google.com

Network Configuration

Interface Configuration (Linux)

ip link set <interface> up

Brings a network interface up.

Example:

ip link set eth0 up

ip link set <interface> down

Brings a network interface down.

Example:

ip link set eth0 down

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

Assigns an IP address to a network interface.

Example:

ip addr add 192.168.1.10/24 dev eth0

ip route add default via <gateway_ip>

Sets the default gateway.

Example:

ip route add default via 192.168.1.1

Firewall Management

firewall-cmd --zone=public --add-port=<port>/tcp --permanent (CentOS/RHEL)

Opens a port in the firewall.

Example:

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

ufw allow <port> (Ubuntu)

Allows traffic on a specific port.

Example:

ufw allow 80
ufw enable

iptables -A INPUT -p tcp --dport <port> -j ACCEPT (Generic Linux)

Adds a rule to accept TCP traffic on a specific port.

Example:

iptables -A INPUT -p tcp --dport 80 -j ACCEPT
service iptables save

Wireless Networking

Wireless Information (Linux)

iwconfig

Displays wireless interface configuration.

Example:

iwconfig wlan0

iwlist <interface> scan

Scans for available wireless networks.

Example:

iwlist wlan0 scan

nmcli dev wifi list

Lists available Wi-Fi networks using NetworkManager.

Example:

nmcli dev wifi list

Wireless Connection (Linux)

nmcli dev wifi connect <SSID> password <password>

Connects to a Wi-Fi network using NetworkManager.

Example:

nmcli dev wifi connect MyNetwork password MyPassword

Troubleshooting

When troubleshooting network issues, consider the following:

  1. Check physical connections: Ensure cables are properly connected.
  2. Verify IP configuration: Confirm correct IP address, subnet mask, and gateway.
  3. Test connectivity: Use ping to verify basic network reachability.
  4. Check DNS resolution: Ensure DNS is resolving hostnames correctly using nslookup.
  5. Inspect firewall rules: Make sure necessary ports are open.
  6. Examine routing table: Confirm packets are being routed correctly.