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.
ping google.comifconfig
Display network interface information (macOS/Linux).
ifconfigipconfig
Display network interface information (Windows).
ipconfignetstat
Display network connections.
netstatcurl [url]
Transfer data from or to a server.
curl https://www.example.comwget [url]
Download a file from a URL.
wget https://www.example.com/file.zipIP and Routing
Manage network interfaces, IP addresses and routing tables.
ip addr show
Show IP addresses assigned to interfaces.
ip addr showip route show
Display the routing table.
ip route showip link set [iface] up/down
Bring a network interface up or down.
ip link set eth0 upip route add [network] via [gateway]
Add a static route.
ip route add 192.168.1.0/24 via 192.168.1.1Firewall (iptables)
Managing firewall rules with iptables.
iptables -L
List all rules in the filter table.
iptables -Liptables -A INPUT -p tcp --dport 22 -j ACCEPT
Allow incoming SSH connections.
iptables -A INPUT -p tcp --dport 22 -j ACCEPTiptables -A INPUT -p tcp --dport 80 -j DROP
Block incoming HTTP traffic.
iptables -A INPUT -p tcp --dport 80 -j DROPiptables-save > rules.v4
Save iptables rules to a file.
iptables-save > rules.v4iptables-restore < rules.v4
Restore iptables rules from a file.
iptables-restore < rules.v4Firewall (nftables)
Managing firewall rules with nftables (modern replacement for iptables).
nft list ruleset
Show current nftables ruleset.
nft list rulesetnft add table inet filter
Create a new table for filtering.
nft add table inet filternft add chain inet filter input { type filter hook input priority 0 \; }
Create an input chain in the filter table.
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.
nft add rule inet filter input tcp dport 22 acceptnft delete rule inet filter input handle [num]
Delete a specific rule by its handle number.
nft delete rule inet filter input handle 5Network Configuration (Netplan)
Configuring network interfaces with Netplan (Ubuntu and related distros).
ls /etc/netplan/
Show available Netplan configuration files.
ls /etc/netplan/sudo nano /etc/netplan/01-netcfg.yaml
Edit Netplan configuration file.
sudo nano /etc/netplan/01-netcfg.yamlsudo netplan apply
Apply Netplan configuration changes.
sudo netplan applysudo netplan try
Test configuration safely (reverts after 120s if not confirmed).
sudo netplan tryNetwork Configuration (systemd-networkd)
Managing network settings using systemd-networkd.
networkctl status
Show status of all network interfaces.
networkctl statusnetworkctl status [iface]
Show detailed status of a specific interface.
networkctl status eth0sudo systemctl restart systemd-networkd
Restart the systemd-networkd service.
sudo systemctl restart systemd-networkdsudo systemctl enable systemd-networkd
Enable systemd-networkd to start at boot.
sudo systemctl enable systemd-networkdsudo nano /etc/systemd/network/20-wired.network
Edit a network configuration file for an interface.
sudo nano /etc/systemd/network/20-wired.networksudo networkctl reload
Reload configuration without restarting the service.
sudo networkctl reloadTroubleshooting
Tools for debugging network issues.
traceroute [host]
Trace the route packets take to a destination.
traceroute google.comdig [domain]
Query DNS information about a domain.
dig example.comnslookup [domain]
Look up DNS records for a domain.
nslookup example.comnc -zv [host] [port]
Test connectivity to a specific port using netcat.
nc -zv google.com 443tcpdump -i [iface]
Capture packets on a network interface.
tcpdump -i eth0