Skip to content

Networking Basics

This guide only covers Linux networking. For a more general/infrastructure-level networking guide, see Networking.

Reference: iproute2 Docs · Debian Wiki — NetworkConfiguration · interfaces(5)


Viewing Network Info

# Show all interfaces and addresses
ip addr show
ip a                    # shorthand

# Show a specific interface
ip addr show eth0

# Show routing table
ip route show
ip r                    # shorthand

# Show default gateway
ip route show default

# Show interface statistics (errors, drops)
ip -s link show eth0

# Show ARP cache (local network neighbors)
ip neigh show

Interface Management

# Bring interface up / down
sudo ip link set eth0 up
sudo ip link set eth0 down

# Assign a temporary IP address (lost on reboot)
sudo ip addr add 192.168.1.50/24 dev eth0

# Remove an IP address
sudo ip addr del 192.168.1.50/24 dev eth0

# Add a temporary route
sudo ip route add 10.0.0.0/24 via 192.168.1.1

# Delete a route
sudo ip route del 10.0.0.0/24

Persistent Network Configuration

Debian 13 servers use ifupdown with /etc/network/interfaces (and anything in /etc/network/interfaces.d/). On trixie the DHCP client is dhcpcd (dhcpcd-base); the old isc-dhcp-client is deprecated.

/etc/network/interfaces

/etc/network/interfaces
source /etc/network/interfaces.d/*

# Loopback
auto lo
iface lo inet loopback

# DHCP (what my servers use, with a reservation on the router)
auto eno1
allow-hotplug eno1
iface eno1 inet dhcp
/etc/network/interfaces (static alternative)
auto eno1
iface eno1 inet static
    address 192.168.1.10/24
    gateway 192.168.1.1
    dns-nameservers 192.168.1.1     # only applied if the resolvconf package is installed

Always give a server's NIC an auto line

The installer writes allow-hotplug <iface> only. ifup -a at boot (which network-online.target waits for) handles auto interfaces only; allow-hotplug ones come up later from udev. On a Docker host that means containers can start before the NIC has DNS and keep an empty resolv.conf until restarted. Add auto <iface>; keeping allow-hotplug next to it is harmless. Write-up: Networking & DNS lessons learned.

# Apply changes (from the console: a mistake drops your SSH session)
sudo systemctl restart networking
# or for a single interface
sudo ifdown eno1 && sudo ifup eno1

Ubuntu uses Netplan

Ubuntu Server writes YAML in /etc/netplan/*.yaml and renders it to systemd-networkd. If you're following an Ubuntu guide, translate addresses/routes/nameservers to the address/gateway/dns-nameservers lines above, and use netplan try there instead of restarting networking.

IPv6 without a route

If the network has no IPv6 route but your DNS server returns AAAA records, some clients (.NET's HttpClient, Docker Hub pulls) hang on IPv6 instead of falling back to IPv4. Check, then disable IPv6 on that host if nothing needs it:

ip -6 route show default        # empty = no IPv6 route
dig AAAA registry-1.docker.io +short
/etc/sysctl.d/99-disable-ipv6.conf
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

sudo sysctl --system applies it. Debian 13 ignores /etc/sysctl.conf, so use a file in /etc/sysctl.d/. See AAAA records with no IPv6 route.


DNS

# /etc/hosts — local static hostname resolution (checked before DNS)
# /etc/resolv.conf — DNS servers (on Debian: written by dhcpcd from the DHCP lease, or by resolvconf)
# /etc/nsswitch.conf — controls resolution order (files, dns, mdns)

# View current DNS servers
cat /etc/resolv.conf
resolvectl status           # only if systemd-resolved is in use (Ubuntu default; not installed on Debian servers)

# Query DNS manually
dig google.com
dig @192.168.1.1 google.com   # query specific DNS server
dig google.com +short          # just the IP

# Reverse lookup
dig -x 8.8.8.8

# nslookup alternative
nslookup google.com
nslookup google.com 192.168.1.1

# Flush DNS cache (systemd-resolved only; plain Debian has no local cache to flush)
sudo resolvectl flush-caches

Containers copy resolv.conf when they start

Docker gives each container a copy of the host's resolver config at start time. Fix the host first, then docker restart the container, or pin DNS for all containers with "dns" in /etc/docker/daemon.json (see Docker post-installation).

/etc/hosts

# Add a local hostname override
sudo nano /etc/hosts

# Example entries
127.0.0.1       localhost
192.168.1.10    appserver appserver.home
192.168.1.20    nas nas.home
192.168.1.1     router opnsense.home

Checking Open Ports & Connections

# List all listening ports
ss -tlnp           # TCP listening, numeric, with process
ss -ulnp           # UDP listening

# All established connections
ss -tnp

# Check if a specific port is in use
ss -tlnp | grep :8080

# Legacy equivalent (if ss not available)
netstat -tlnp
netstat -an | grep :8080
Flag Meaning
-t TCP
-u UDP
-l Listening only
-n Numeric (no hostname resolution)
-p Show process name/PID

Diagnostics

# Test connectivity
ping 8.8.8.8               # ICMP to IP
ping google.com            # tests DNS + connectivity

# Trace network path
traceroute google.com
mtr google.com             # live combined ping + traceroute (install mtr)

# Test TCP connection to a port
nc -zv 192.168.1.10 22     # port 22 open?
nc -zv 192.168.1.10 80

# Test HTTP without a browser
curl -I https://example.com              # headers only
curl -v https://example.com             # verbose
wget --spider https://example.com       # check URL reachability

# Check bandwidth between two hosts (install iperf3)
# On server:  iperf3 -s
# On client:  iperf3 -c server-ip

Hostname

# View hostname
hostname
hostnamectl

# Set hostname permanently
sudo hostnamectl set-hostname newhostname

# Also update /etc/hosts to match
sudo nano /etc/hosts
# Change: 127.0.1.1  oldhostname
# To:     127.0.1.1  newhostname

Network Interfaces — Common Names

Modern Linux uses predictable interface names. You'll see these on servers:

Name Meaning
eth0, eth1 Old-style Ethernet
enp2s0 PCI Ethernet (bus 2, slot 0)
eno1 Onboard Ethernet
lo Loopback (always 127.0.0.1)
docker0 Docker bridge network
veth* Virtual Ethernet (Docker container pairs)

Sources & further reading