Linux networking basics: ip, ss, and troubleshooting
The old networking tools (ifconfig, netstat, route) are being replaced by ip and ss from the iproute2 package. They’re more powerful and consistent, but the syntax is different enough to confuse people switching over.
ip: the replacement for ifconfig
Show all interfaces:
ip addr show
# or shorter
ip a
Show a specific interface:
ip addr show eth0
Add an IP address:
sudo ip addr add 192.168.1.100/24 dev eth0
Remove an IP:
sudo ip addr del 192.168.1.100/24 dev eth0
Bring an interface up or down:
sudo ip link set eth0 up
sudo ip link set eth0 down
Show link layer information (MAC addresses, state):
ip link show
Routing
Show the routing table:
ip route show
Add a route:
sudo ip route add 10.0.0.0/8 via 192.168.1.1
Add a default gateway:
sudo ip route add default via 192.168.1.1
Delete a route:
sudo ip route del 10.0.0.0/8
Show the route for a specific destination:
ip route get 8.8.8.8
This tells you which interface and gateway will be used to reach that address.
ss: the replacement for netstat
Show all listening sockets:
ss -tlnp
-t— TCP-l— listening only-n— numeric (don’t resolve names)-p— show process using the socket
Show all connections:
ss -tanp
Show connections to a specific port:
ss -tanp dport = :80
Show connections from a specific IP:
ss -tanp src 192.168.1.100
Count connections by state:
ss -tan | awk '{print $1}' | sort | uniq -c | sort -rn
This shows how many connections are in ESTABLISHED, TIME_WAIT, etc.
DNS resolution
Check DNS:
dig example.com
dig +short example.com # just the IP
dig example.com MX # MX records
nslookup example.com # simpler but less featured
The system’s DNS resolver config:
cat /etc/resolv.conf
On systems using systemd-resolved, the actual resolver is at 127.0.0.53 and forwards to the configured DNS servers.
Ping and traceroute
Basic connectivity test:
ping -c 4 8.8.8.8
Trace the route:
traceroute 8.8.8.8
# or
tracepath 8.8.8.8
Interface configuration persistence
Temporary changes (lost on reboot) use ip. Permanent changes depend on your system:
Ubuntu uses /etc/network/interfaces:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
Or Netplan on newer Ubuntu (17.10+):
network:
version: 2
ethernets:
eth0:
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
Network namespaces
Linux network namespaces isolate network stacks. Useful for testing:
sudo ip netns add test
sudo ip netns exec test ip addr show
sudo ip netns exec test ping 8.8.8.8
Connect namespaces with veth pairs:
sudo ip link add veth0 type veth peer name veth1
sudo ip link set veth1 netns test
Common troubleshooting steps
- Can you ping localhost?
ping 127.0.0.1— if not, networking stack is broken - Can you ping the gateway? — if not, local network issue
- Can you ping an external IP?
ping 8.8.8.8— if not, routing or firewall issue - Can you resolve DNS?
dig example.com— if not, DNS config issue - Can you reach the service?
ss -tlnp | grep :80— is it listening?
This sequence narrows down where the problem is.
Common mistakes
Using ifconfig. It’s deprecated and may not be installed. Use ip instead.
Not checking the firewall. A connection might be blocked by iptables, not a networking issue.
Temporary changes that don’t persist. ip addr add works until reboot. Make changes permanent in the config files.
Confusing 127.0.0.53 with real DNS. On systemd-resolved systems, /etc/resolv.conf points to a local stub resolver. The actual DNS servers are in resolvectl status.
Remarks
The ip and ss commands cover everything ifconfig and netstat did, and more. The syntax takes some getting used to — ip addr instead of ifconfig, ss -tlnp instead of netstat -tlnp — but it’s more consistent and powerful. For troubleshooting, the step-by-step approach (localhost → gateway → external IP → DNS → service) quickly narrows down the problem.
Related Posts
Vim survival guide for Linux admins
The minimum vim knowledge you need to survive on a Linux server. Editing config files without wanting to throw your keyboard.
Linux memory management: free, vmstat, and /proc
Understanding how Linux uses memory. Reading free correctly, using vmstat, and what /proc/meminfo actually tells you.
tmux: terminal multiplexing made simple
Using tmux to manage terminal sessions. Panes, windows, and why your SSH sessions should survive disconnects.