Skip to content

Networking

Common networking commands and configuration tools including connectivity tests, interface management, firewalls and routing.

Basics

Common commands for connectivity and network information.

ping [host]

Check network connectivity to a host.

Terminal window
ping google.com

ifconfig

Display network interface information (macOS/Linux).

Terminal window
ifconfig

ipconfig

Display network interface information (Windows).

Terminal window
ipconfig

netstat

Display network connections.

Terminal window
netstat

curl [url]

Transfer data from or to a server.

Terminal window
curl https://www.example.com

wget [url]

Download a file from a URL.

Terminal window
wget https://www.example.com/file.zip

IP and Routing

Manage network interfaces, IP addresses and routing tables.

ip addr show

Show IP addresses assigned to interfaces.

Terminal window
ip addr show

ip route show

Display the routing table.

Terminal window
ip route show

ip link set [iface] up/down

Bring a network interface up or down.

Terminal window
ip link set eth0 up

ip route add [network] via [gateway]

Add a static route.

Terminal window
ip route add 192.168.1.0/24 via 192.168.1.1

Firewall (iptables)

Managing firewall rules with iptables.

iptables -L

List all rules in the filter table.

Terminal window
iptables -L

iptables -A INPUT -p tcp --dport 22 -j ACCEPT

Allow incoming SSH connections.

Terminal window
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

iptables -A INPUT -p tcp --dport 80 -j DROP

Block incoming HTTP traffic.

Terminal window
iptables -A INPUT -p tcp --dport 80 -j DROP

iptables-save > rules.v4

Save iptables rules to a file.

Terminal window
iptables-save > rules.v4

iptables-restore < rules.v4

Restore iptables rules from a file.

Terminal window
iptables-restore < rules.v4

Firewall (nftables)

Managing firewall rules with nftables (modern replacement for iptables).

nft list ruleset

Show current nftables ruleset.

Terminal window
nft list ruleset

nft add table inet filter

Create a new table for filtering.

Terminal window
nft add table inet filter

nft add chain inet filter input { type filter hook input priority 0 \; }

Create an input chain in the filter table.

Terminal window
nft add chain inet filter input { type filter hook input priority 0 \; }

nft add rule inet filter input tcp dport 22 accept

Allow incoming SSH connections.

Terminal window
nft add rule inet filter input tcp dport 22 accept

nft delete rule inet filter input handle [num]

Delete a specific rule by its handle number.

Terminal window
nft delete rule inet filter input handle 5

Network Configuration (Netplan)

Configuring network interfaces with Netplan (Ubuntu and related distros).

ls /etc/netplan/

Show available Netplan configuration files.

Terminal window
ls /etc/netplan/

sudo nano /etc/netplan/01-netcfg.yaml

Edit Netplan configuration file.

Terminal window
sudo nano /etc/netplan/01-netcfg.yaml

sudo netplan apply

Apply Netplan configuration changes.

Terminal window
sudo netplan apply

sudo netplan try

Test configuration safely (reverts after 120s if not confirmed).

Terminal window
sudo netplan try

Network Configuration (systemd-networkd)

Managing network settings using systemd-networkd.

networkctl status

Show status of all network interfaces.

Terminal window
networkctl status

networkctl status [iface]

Show detailed status of a specific interface.

Terminal window
networkctl status eth0

sudo systemctl restart systemd-networkd

Restart the systemd-networkd service.

Terminal window
sudo systemctl restart systemd-networkd

sudo systemctl enable systemd-networkd

Enable systemd-networkd to start at boot.

Terminal window
sudo systemctl enable systemd-networkd

sudo nano /etc/systemd/network/20-wired.network

Edit a network configuration file for an interface.

Terminal window
sudo nano /etc/systemd/network/20-wired.network

sudo networkctl reload

Reload configuration without restarting the service.

Terminal window
sudo networkctl reload

Troubleshooting

Tools for debugging network issues.

traceroute [host]

Trace the route packets take to a destination.

Terminal window
traceroute google.com

dig [domain]

Query DNS information about a domain.

Terminal window
dig example.com

nslookup [domain]

Look up DNS records for a domain.

Terminal window
nslookup example.com

nc -zv [host] [port]

Test connectivity to a specific port using netcat.

Terminal window
nc -zv google.com 443

tcpdump -i [iface]

Capture packets on a network interface.

Terminal window
tcpdump -i eth0