Networking
ip, ss, DNS, NetworkManager, systemd-networkd, nftables, and diagnostics.
ip — interfaces & addresses
All interfaces:
ip aOne interface:
ip addr show enp0s3IPv4 only:
ip -4 addrBrief one-liner:
ip -br addr/ip -br linkStats:
ip -s link show enp0s3Add IP (temporary):
sudo ip addr add 192.168.1.100/24 dev enp0s3Remove IP:
sudo ip addr del 192.168.1.100/24 dev enp0s3Flush all:
sudo ip addr flush dev enp0s3Up / down:
sudo ip link set enp0s3 up/downSet MTU:
sudo ip link set enp0s3 mtu 9000Add VLAN:
sudo ip link add link enp0s3 name enp0s3.100 type vlan id 100
ip — routing
Routing table:
ip rDefault route:
ip route show defaultAdd static route:
sudo ip route add 10.0.0.0/8 via 192.168.1.1Add default gateway:
sudo ip route add default via 192.168.1.1Delete:
sudo ip route del 10.0.0.0/8Trace which route applies:
ip route get 8.8.8.8ARP / neighbor table:
ip neigh
ss — sockets
TCP listeners + process:
ss -tlnpUDP listeners + process:
ss -ulnpAll TCP+UDP:
ss -tunapEstablished TCP:
ss -t state establishedBy source/dest port:
ss -tnp sport = :443ss -tnp dport = :443By process name:
ss -tnp | grep nginxUnix sockets:
ss -xlnpSummary:
ss -s
| Flag | Meaning |
|---|---|
-t | TCP |
-u | UDP |
-l | listening |
-a | all |
-n | numeric |
-p | show process |
-s | summary |
DNS — dig
Lookup:
dig example.comdig example.com +shortRecord type:
dig example.com MXdig example.com AAAAdig example.com TXTUse specific server:
dig @8.8.8.8 example.comReverse lookup:
dig -x 8.8.8.8Trace resolution path:
dig +trace example.com
DNS — simpler
host example.comhost -t MX example.comnslookup example.com
resolvectl (systemd-resolved)
Status:
resolvectl statusQuery:
resolvectl query example.comFlush cache:
sudo resolvectl flush-cachesStats:
resolvectl statisticsCurrent servers:
resolvectl dns
| File | Purpose |
|---|---|
/etc/resolv.conf | system DNS (often managed) |
/etc/hosts | static mappings |
/etc/nsswitch.conf | resolution order |
/etc/systemd/resolved.conf | resolved config |
NetworkManager (nmcli)
General status:
nmcli general statusAll connections:
nmcli connection showActive connections:
nmcli connection show --activeDevice status:
nmcli device statusDevice details:
nmcli device show enp0s3
WiFi
List networks:
nmcli device wifi listConnect:
nmcli device wifi connect "SSID" password "password"Hidden network:
nmcli device wifi connect "SSID" password "password" hidden yesDisconnect:
nmcli device disconnect wlan0
Static IP connection
nmcli connection add con-name "static-eth" ifname enp0s3 type ethernet \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8,8.8.4.4" \
ipv4.method manual
Modify:
nmcli connection modify "static-eth" ipv4.dns "1.1.1.1"Up / down:
nmcli connection up "static-eth"/downDelete:
nmcli connection delete "static-eth"Reload from disk:
nmcli connection reloadShow saved WiFi passwords:
sudo grep -r psk= /etc/NetworkManager/system-connections/
systemd-networkd
Config in /etc/systemd/network/.
DHCP wired example,
20-wired.network:[Match] Name=enp0s3 [Network] DHCP=yesStatic example:
[Network] Address=192.168.1.100/24 Gateway=192.168.1.1 DNS=8.8.8.8Enable:
sudo systemctl enable --now systemd-networkd sudo systemctl enable --now systemd-resolvedStatus:
networkctl status/networkctl listReload without restart:
sudo networkctl reload
nftables
Show ruleset:
sudo nft list rulesetFlush:
sudo nft flush rulesetList tables / chains:
sudo nft list tablessudo nft list table inet filterLoad config:
sudo nft -f /etc/nftables.confEnable on boot:
sudo systemctl enable --now nftablesAdd rule on the fly:
sudo nft add rule inet filter input tcp dport 8080 acceptFind handle to delete:
sudo nft -a list chain inet filter inputsudo nft delete rule inet filter input handle 12Block IP:
sudo nft add rule inet filter input ip saddr 10.0.0.5 dropRate-limit SSH:
sudo nft add rule inet filter input tcp dport 22 ct state new limit rate 3/minute acceptMinimal stateful firewall,
/etc/nftables.conf:table inet filter { chain input { type filter hook input priority 0; policy drop; ct state established,related accept iifname "lo" accept ip protocol icmp accept ip6 nexthdr icmpv6 accept tcp dport 22 accept tcp dport { 80, 443 } accept log prefix "[nft-drop] " drop } chain forward { type filter hook forward priority 0; policy drop; } chain output { type filter hook output priority 0; policy accept; } }
Diagnostics
Ping:
ping -c 4 8.8.8.8IPv6 ping:
ping -c 4 -6 google.comTraceroute (numeric, faster):
traceroute -n google.comMTR (live + report):
mtr google.com/mtr -r -c 10 google.comPort open check:
nc -zv 192.168.1.1 22Scan range w/ timeout:
nc -zv -w3 192.168.1.1 80-100Public IP:
curl -4 icanhazip.comcurl -6 icanhazip.comPer-iface bandwidth:
ip -s linkiftop (per-connection):
sudo iftop -i enp0s3Packet capture:
sudo tcpdump -i enp0s3 -c 100sudo tcpdump -i enp0s3 port 80 -w capture.pcapARP scan local net:
sudo arp-scan --localnetWake on LAN:
wol AA:BB:CC:DD:EE:FF
Useful files
| Path | Purpose |
|---|---|
/etc/hostname | system hostname |
/etc/hosts | static host mappings |
/etc/resolv.conf | DNS resolver |
/etc/nsswitch.conf | name resolution order |
/etc/nftables.conf | firewall rules |
/etc/NetworkManager/ | NM config + connections |
/etc/systemd/network/ | networkd config |
/etc/systemd/resolved.conf | resolved config |