Debian and Ubuntu Linux Networking Cheat Sheet and Guide
General Description of Linux Networking
Linux networking is the collection of kernel facilities, device drivers, user-space services, configuration files, and command-line tools that connect a Debian or Ubuntu system to local networks, routed networks, and application services. The kernel provides interfaces, Ethernet and Wi-Fi data-link handling, IPv4 and IPv6, routing, neighbour discovery, TCP and UDP, packet filtering, traffic control, and network namespaces. User-space components select addresses, maintain routes, resolve names, synchronise time, authenticate users, mount remote file systems, and make configuration persistent across reboots.
A reliable administrator works from the bottom of the stack upward. First confirm that the device and link are present. Then validate the data-link state, IP address and subnet, neighbours, routes, DNS, transport ports, and finally the application. This layered approach avoids changing unrelated settings and makes failures easier to isolate.
Typical networking tasks include:
- Discovering wired, wireless, physical, and virtual interfaces.
- Assigning static or DHCP addresses, routes, DNS servers, and search domains.
- Creating VLANs, bridges, virtual Ethernet pairs, and bonded interfaces.
- Providing link failover or IEEE 802.3ad LACP aggregation.
- Managing client services such as DNS, NTP, LDAP, and NFS.
- Controlling traffic with UFW, nftables, and Linux traffic control.
- Monitoring utilisation, errors, latency, packet loss, sockets, and application reachability.
- Collecting logs and packet captures for repeatable troubleshooting.
Scope: This guide focuses on Debian and Ubuntu server and desktop systems. It covers Netplan, NetworkManager, systemd-networkd, and legacy ifupdown because the active configuration stack depends on the distribution release, installation type, and local policy.
Safety, Conventions, and Example Addresses
Warning: Changing an interface, default route, firewall, VLAN, or bond over the same remote session can disconnect you. Keep console or out-of-band access available, back up configuration files, schedule a rollback, and use netplan try rather than netplan apply for the first remote test.
Command prompts used in this guide:
|
$ command # Run as an ordinary user |
The examples use documentation-only address ranges so they are not mistaken for real production networks:
|
Purpose |
Example |
|
IPv4 LAN |
192.0.2.0/24 |
|
Second IPv4 network |
198.51.100.0/24 |
|
Third IPv4 network |
203.0.113.0/24 |
|
IPv6 documentation prefix |
2001:db8::/32 |
|
Example domain |
example.com |
|
Example interfaces |
enp1s0, enp2s0, wlp2s0, bond0, vlan100 |
Before editing a persistent file, make a dated backup and validate syntax before activating it:
|
# stamp=$(date +%F-%H%M%S) |
Contents
- Built-in utilities and commonly installed tools
- Networking layers and layer-specific commands
- Management of network services and configuration stacks
- Configuration files, errors, and logs
- Interface discovery and link management
- Static and DHCP IP addressing
- VLANs and IEEE 802.1Q tagging
- Failover bonding and LACP aggregation
- Routing and policy routing
- Host naming and DNS client management
- NTP client management
- LDAP client management
- NFS client management
- Firewalls and network security
- Traffic flow, bandwidth, and resource control
- Monitoring and performance metrics
- Troubleshooting tools and workflows
- Command reference summary and authoritative references
Built-in Utilities and Commonly Installed Tools
Debian and Ubuntu include many core administration commands in the base system. Some diagnostic and service-specific tools are separate packages. The modern iproute2 family should be preferred over the older net-tools commands because it supports current kernel features and presents IPv4, IPv6, policy routing, tunnels, neighbours, bridges, and namespaces consistently.
Core Utilities Normally Available
|
Utility |
Primary purpose |
Example |
|
ip |
Interfaces, addresses, neighbours, routes, rules, tunnels, and namespaces. |
ip -br address |
|
ss |
Listening and established TCP/UDP/UNIX sockets. |
ss -lntup |
|
systemctl |
Start, stop, enable, and inspect networking services. |
systemctl status NetworkManager |
|
journalctl |
Read boot, kernel, and service logs. |
journalctl -b -u systemd-networkd |
|
networkctl |
Inspect and reconfigure interfaces managed by systemd-networkd. |
networkctl status enp1s0 |
|
resolvectl |
Inspect and manage systemd-resolved DNS state. |
resolvectl status |
|
hostnamectl |
Display or set the static host name. |
hostnamectl set-hostname web01.example.com |
|
udevadm |
Inspect device properties and monitor hotplug events. |
udevadm info -q property -p /sys/class/net/enp1s0 |
|
sysctl |
Read or change kernel networking parameters. |
sysctl net.ipv4.ip_forward |
|
/proc and /sys |
Kernel counters and interface/device attributes. |
cat /proc/net/dev |
Common Packages to Install
|
Package |
Important commands |
Use |
|
iproute2 |
ip, ss, bridge, tc, nstat |
Core modern networking administration. |
|
iputils-ping |
ping |
ICMP reachability and latency testing. |
|
iputils-tracepath |
tracepath |
Path and path-MTU discovery without raw-socket privileges. |
|
iputils-arping |
arping |
ARP reachability and duplicate-address checks. |
|
ethtool |
ethtool |
Ethernet speed, duplex, driver, offload, ring, and hardware counters. |
|
iw, rfkill |
iw, rfkill |
Wireless capabilities, association state, and radio blocking. |
|
traceroute |
traceroute |
ICMP, UDP, or TCP path tracing. |
|
netcat-openbsd |
nc |
TCP/UDP connection and listener testing. |
|
tcpdump |
tcpdump |
Packet capture and protocol filtering. |
|
dnsutils |
dig, nslookup |
DNS queries and response analysis. |
|
nftables, ufw |
nft, ufw |
Native and simplified host firewall management. |
|
pciutils, usbutils, lshw |
lspci, lsusb, lshw |
Hardware and driver discovery. |
|
sysstat |
sar |
Historical and live network performance counters. |
|
iperf3 |
iperf3 |
Controlled TCP/UDP throughput testing. |
|
nload, iftop, bmon, vnstat |
nload, iftop, bmon, vnstat |
Interactive and historical bandwidth monitoring. |
|
chrony |
chronyd, chronyc |
NTP time synchronisation client and server. |
|
sssd-ldap, ldap-utils |
sssctl, ldapsearch |
LDAP identity/authentication client and directory queries. |
|
nfs-common |
mount.nfs, nfsstat, showmount |
NFS client support and diagnostics. |
|
net-tools |
ifconfig, route, arp, netstat |
Legacy compatibility only; not the preferred interface. |
Install a practical troubleshooting set:
|
# apt update |
Modern Replacements for Legacy Commands
|
Legacy command |
Preferred command |
Example |
|
ifconfig -a |
ip address show / ip -br address |
ip -br address |
|
ifconfig eth0 up |
ip link set dev eth0 up |
ip link set dev enp1s0 up |
|
route -n |
ip route show |
ip -4 route show |
|
arp -n |
ip neighbour show |
ip neigh show dev enp1s0 |
|
netstat -lntup |
ss -lntup |
ss -lntup |
|
brctl show |
bridge link / ip link |
bridge link show |
|
vconfig |
ip link type vlan |
ip link add link enp1s0 name vlan100 type vlan id 100 |
Networking Layers and Layer-Specific Commands
The practical Linux networking stack can be viewed as a sequence of layers. Each layer depends on the one below it. A DNS failure, for example, should not be investigated before confirming that the interface has carrier, an address, a usable route, and transport reachability to the DNS server.
|
Layer |
Questions to answer |
Key inspection tools |
Typical configuration |
|
Physical |
Is the device detected? Is the cable, radio, optic, driver, and carrier working? |
lspci, lsusb, lshw, ethtool, iw, rfkill, journalctl -k |
Driver/module options, ethtool link settings, systemd .link files |
|
Data link |
Is the interface up? What is the MAC, MTU, VLAN, bridge, bond, and neighbour state? |
ip link, ip -s -d link, bridge, ip neigh, ethtool, iw |
ip link, VLAN/bridge/bond profiles, Netplan, NetworkManager, networkd |
|
IP and routing |
Does the host have the correct prefix, gateway, route, and source address? |
ip address, ip route, ip rule, ping, tracepath, arping |
ip address/route, Netplan, nmcli, .network, /etc/network/interfaces |
|
TCP and UDP |
Is the service listening? Does a handshake or datagram exchange succeed? |
ss, nc, tcpdump, nstat, iperf3 |
Application bind/listen settings, firewall, sysctl, traffic control |
|
Name/application |
Can names resolve and can the application protocol complete? |
getent, resolvectl, dig, curl, openssl, journalctl |
DNS, /etc/hosts, service configuration, certificates and access policy |
Physical Layer
The physical layer covers the network adapter, bus, driver, cable or fibre, transceiver, radio, signal state, negotiated speed, and carrier. Linux represents a detected adapter as a network interface only after a driver binds to the device.
List PCI and USB network hardware and the associated kernel driver:
|
$ lspci -nnk | grep -A3 -i ‘ethernet\|network’ |
Inspect the driver and firmware for an interface:
|
$ ethtool -i enp1s0 |
Check carrier, link negotiation, and recent kernel events:
|
$ ethtool enp1s0 |
Interpretation: carrier 1 normally means the physical link is detected; carrier 0 means no usable link. An administratively DOWN interface can still have a connected cable, so inspect both administrative state and carrier.
Data-Link Layer
The data-link layer handles Ethernet or Wi-Fi frames, MAC addresses, MTU, VLAN tags, bridges, bonding, and ARP or IPv6 neighbour discovery. The state UP means the interface is administratively enabled. LOWER_UP means the kernel sees a working lower-layer link.
Inspect link state, detailed attributes, and counters:
|
$ ip -br link |
Bring an interface up or down temporarily and change its MTU:
|
# ip link set dev enp1s0 up |
Warning: Bringing down the interface carrying your SSH session immediately disconnects it. An MTU change can also interrupt active connections.
IP, ICMP, and Routing Layer
The IP layer assigns local IPv4 and IPv6 addresses, selects source addresses, maintains routing tables and policy rules, and reports network errors through ICMP or ICMPv6. A route must match the destination, and the selected source address must be valid on the outgoing path.
Display addresses, routes, rules, and the route the kernel would use for one destination:
|
$ ip -br address |
Test the local gateway and a routed destination:
|
$ ping -c 4 192.0.2.1 |
TCP and UDP Transport Layer
TCP provides a connection-oriented byte stream with handshakes, sequencing, retransmission, congestion control, and orderly close. UDP sends independent datagrams without a transport-layer handshake. A host can have correct IP connectivity while an application still fails because no service is listening, the wrong address is bound, or a firewall blocks the port.
List listening sockets and established connections:
|
$ ss -lntup |
Test a TCP port and a UDP service:
|
$ nc -vz -w 3 192.0.2.20 443 |
UDP testing: A successful UDP nc command does not always prove that the application replied because UDP has no handshake. Confirm with an application query such as dig and, when needed, a packet capture.
A Layered Test Sequence
- Confirm that the kernel detects the adapter and that the correct driver is loaded.
- Confirm administrative state, carrier, speed, duplex, MTU, VLAN, bridge, and bond membership.
- Confirm the expected IPv4 or IPv6 address and prefix.
- Confirm ARP or neighbour discovery to the local gateway.
- Confirm the default and destination-specific routes, including policy rules.
- Test reachability by numeric address before testing DNS.
- Confirm that the local or remote application port is listening and permitted by firewalls.
- Capture packets and compare timestamps with service and kernel logs when the failure remains unclear.
|
$ ip -br link |
Management of Network and Networking Services
A Debian or Ubuntu installation can use more than one networking component, but a given interface should normally have only one configuration owner. Netplan is a declarative front end that generates configuration for NetworkManager or systemd-networkd. NetworkManager is common on desktops and is also suitable for servers. systemd-networkd is lightweight and common on servers. Traditional Debian systems may use ifupdown through the networking service.
Identify the Active Configuration Stack
Check service state and ask each manager what it owns:
|
$ systemctl is-active NetworkManager systemd-networkd networking systemd-resolved |
Determine which process is controlling one interface:
|
$ nmcli -f GENERAL.DEVICE,GENERAL.STATE,GENERAL.CONNECTION device show enp1s0 |
Rule: Do not define the same address or route in Netplan, a NetworkManager profile, a systemd-networkd file, and /etc/network/interfaces at the same time. Duplicate ownership causes flapping addresses, overwritten routes, and confusing DNS behaviour.
systemd Service Management
Inspect, start, restart, and enable a networking service:
|
$ systemctl status NetworkManager |
Warning: Restarting a network manager can interrupt every interface it controls. Prefer a connection-specific reload or reapply operation when working remotely.
Netplan Management
Netplan reads YAML from /etc/netplan and generates backend configuration. Validate and test before committing:
|
# chmod 600 /etc/netplan/*.yaml |
Change one value with the Netplan CLI and review the result before applying:
|
# netplan set ethernets.enp1s0.dhcp4=true |
netplan try: The command applies the proposed configuration and asks for confirmation. If confirmation is not received, Netplan attempts to roll back, making it safer than a blind remote apply. Console access is still recommended.
NetworkManager Management
NetworkManager stores configuration as connection profiles. A profile can be associated with a device and activated or deactivated independently:
|
$ nmcli general status |
Temporarily disable and re-enable all NetworkManager networking:
|
# nmcli networking off |
Warning: nmcli networking off disconnects NetworkManager-managed interfaces and should not be used from a session that depends on them.
systemd-networkd Management
Inspect status and reload definitions without restarting all links:
|
$ networkctl list |
Use networkctl lldp when LLDP is enabled to learn adjacent switch information:
|
$ networkctl lldp enp1s0 |
ifupdown Management
Traditional ifupdown reads /etc/network/interfaces and included files. Bring up or down only the named interface:
|
# ifup enp1s0 |
Warning: ifdown followed by ifup is risky remotely. Commands in pre-up, up, post-up, pre-down, down, and post-down stanzas can also fail and leave partial state.
Management of Networking Configuration Files
Persistent networking state is stored in different files depending on the active stack. Generated files should not be edited directly because the generator will overwrite them.
|
Path |
Owner or purpose |
Important notes |
|
/etc/netplan/*.yaml |
Netplan source configuration |
Use spaces, not tabs. Set restrictive permissions. Validate with netplan generate. |
|
/run/systemd/network/* and /run/NetworkManager/* |
Generated runtime files |
Do not edit; regenerated by Netplan or services. |
|
/etc/NetworkManager/NetworkManager.conf |
NetworkManager main configuration |
Use /etc/NetworkManager/conf.d/*.conf for local drop-ins where practical. |
|
/etc/NetworkManager/system-connections/*.nmconnection |
NetworkManager connection profiles |
Usually mode 600 and owned by root. Prefer nmcli to edit. |
|
/etc/systemd/network/*.network |
systemd-networkd link addressing and routing |
Lexical ordering matters; first matching file usually wins. |
|
/etc/systemd/network/*.netdev |
Virtual devices such as bond, bridge, VLAN, tunnel |
Create the device, then reference it from .network files. |
|
/etc/systemd/network/*.link |
Persistent link properties and naming |
Applied early by udev; match carefully. |
|
/etc/network/interfaces |
ifupdown configuration |
May source /etc/network/interfaces.d/*. |
|
/etc/hostname and /etc/hosts |
Local host naming |
Keep the static host name and local address mapping consistent. |
|
/etc/nsswitch.conf |
Name service lookup order |
Controls files, DNS, systemd, LDAP/SSSD, and other databases. |
|
/etc/resolv.conf |
Resolver entry point |
Often a symlink managed by systemd-resolved or NetworkManager. Do not overwrite blindly. |
|
/etc/systemd/resolved.conf.d/*.conf |
systemd-resolved policy |
Use drop-ins and restart systemd-resolved after changes. |
|
/etc/chrony/chrony.conf |
Chrony NTP configuration |
Distribution includes and paths can vary. |
|
/etc/sssd/sssd.conf |
SSSD LDAP identity and authentication |
Must normally be root-owned and mode 600. |
|
/etc/fstab |
Persistent NFS and local mounts |
Use _netdev and systemd automount options for resilient boot behaviour. |
|
/etc/nftables.conf |
Persistent nftables ruleset |
Validate before loading and retain console access. |
|
/etc/ufw/* |
UFW policy and generated rules |
Use ufw commands for ordinary rule management. |
|
/etc/sysctl.d/*.conf |
Persistent kernel networking parameters |
Apply with sysctl –system. |
Safe Editing and Validation
- Identify the active manager and the source file that owns the interface.
- Copy the file with metadata before editing.
- Make the smallest possible change and keep the old session open.
- Validate syntax without applying when the tool supports it.
- Apply to one interface or profile rather than restarting all networking.
- Verify link, address, routes, DNS, and application connectivity.
- Only then remove obsolete configuration or close the recovery session.
|
# install -m 600 /dev/null /etc/netplan/99-local.yaml |
Validate an nftables file without applying it:
|
# nft –check –file /etc/nftables.conf |
Check NetworkManager profile values and reload profile files:
|
$ nmcli –fields all connection show “server-lan” |
Errors, Logs, and Event Monitoring
On current Debian and Ubuntu systems, the systemd journal is the primary source for service and kernel events. Traditional files such as /var/log/syslog and /var/log/kern.log may also exist when rsyslog is installed and configured.
General and Kernel Logs
|
$ journalctl -b # All messages from this boot |
Filter kernel events for network drivers, link state, MTU, and firmware:
|
$ journalctl -k -b | grep -Ei ‘net|eth|enp|wlp|link|carrier|firmware|mtu|bond|vlan’ |
Manager and Service Logs
|
$ journalctl -b -u NetworkManager |
Follow NetworkManager events for one device while reproducing a problem:
|
# journalctl -f -u NetworkManager | grep –line-buffered enp1s0 |
Temporarily increase NetworkManager logging, then restore the normal level:
|
# nmcli general logging level DEBUG domains ALL |
Warning: Debug logging can reveal addresses, host names, and connection details and can grow rapidly. Enable it only for a bounded test and restore normal logging afterward.
Live Link, Address, and Route Events
Use ip monitor to watch kernel network state change without repeatedly polling:
|
$ ip monitor all |
Monitor udev add, remove, and property events for network devices:
|
# udevadm monitor –kernel –udev –property –subsystem-match=net |
Common Error Messages and Their Layer
|
Message or symptom |
Likely layer |
First checks |
|
NO-CARRIER or carrier 0 |
Physical/data link |
Cable, optic, radio, switch port, ethtool, rfkill, driver logs. |
|
RTNETLINK answers: File exists |
IP/routing |
Existing address, route, rule, or duplicate manager ownership. |
|
Network is unreachable |
Routing |
Address/prefix, link route, default route, policy rules. |
|
No route to host |
Routing/firewall |
Route lookup, neighbour state, ICMP reject, remote firewall. |
|
Connection refused |
TCP/application |
Host reached, but no listener or an active reject. Check ss and service status. |
|
Connection timed out |
Path/firewall/application |
Packet loss, silent firewall drop, incorrect route, service not replying. |
|
Temporary failure in name resolution |
DNS |
resolv.conf link, resolvectl status, DNS route/reachability. |
|
YAML parse or inconsistent indentation |
Persistent configuration |
Spaces only, indentation, netplan generate output. |
|
DHCP timeout or no lease |
Data link/DHCP |
Carrier, VLAN, DHCP broadcasts, server scope, firewall, logs. |
|
Neighbour FAILED or INCOMPLETE |
Data link |
Wrong subnet/VLAN, gateway offline, switch filtering, duplicate address. |
Interface Discovery and Link Management
Discover All Interfaces
Display a concise list of interface names, link state, and addresses:
|
$ ip -br link |
Show only interfaces that are operationally up:
|
$ ip -br link | awk ‘$2 ~ /UP/ {print}’ |
Names: Predictable interface names such as enp1s0 describe device topology. Names such as eth0 can still be used when predictable naming is disabled or overridden.
Distinguish Physical and Virtual Interfaces
A physical interface normally has a device path under sysfs. Virtual devices such as loopback, bridge, bond, VLAN, dummy, veth, and tunnels often do not:
|
$ test -e /sys/class/net/enp1s0/device && echo physical-or-hardware-backed |
List interface types with one command per device:
|
$ for path in /sys/class/net/*; do |
Discover Wireless Interfaces
List wireless physical radios, interfaces, and association state:
|
$ iw phy |
Check whether the radio is blocked and scan through NetworkManager:
|
$ rfkill list |
Connect to a WPA/WPA2 Personal network with NetworkManager:
|
# nmcli device wifi connect “ExampleSSID” password “replace-with-real-secret” ifname wlp2s0 |
Warning: Passwords entered on a command line can be exposed through shell history or process inspection. Prefer nmcli –ask or a protected profile when handling real credentials.
Find the MAC Address
Display the current MAC address:
|
$ ip link show dev enp1s0 |
Display the permanent hardware address when supported:
|
$ ethtool -P enp1s0 |
Temporarily assign a locally administered MAC address:
|
# ip link set dev enp1s0 down |
MAC changes: A MAC change can invalidate switch security, DHCP reservations, neighbour caches, and active connections. Use a locally administered address with the second-least-significant bit set, such as a first octet of 02.
Find Advanced Interface Properties
|
$ ip -details -statistics link show dev enp1s0 |
Inspect MTU, queue count, qdisc, state, and master device in one line:
|
$ ip -d link show dev enp1s0 |
Display NetworkManager and networkd views:
|
$ nmcli –fields GENERAL,CAPABILITIES,WIRED-PROPERTIES device show enp1s0 |
Find Link Speed and Duplex
ethtool is the most direct tool for Ethernet negotiation:
|
$ ethtool enp1s0 | grep -E ‘Speed:|Duplex:|Auto-negotiation:|Link detected:’ |
Alternative views are useful for scripting:
|
$ cat /sys/class/net/enp1s0/speed 2>/dev/null |
Units: The sysfs speed value is normally in megabits per second. A value of -1 or an error can mean the link is down or the driver does not expose speed.
Configure Fixed or Automatic Link Speed
Set 100 Mbit/s full duplex with autonegotiation disabled until the next reset or reboot:
|
# ethtool -s enp1s0 autoneg off speed 100 duplex full |
Return to autonegotiation:
|
# ethtool -s enp1s0 autoneg on |
Warning: Both ends must use compatible settings. A forced speed or duplex mismatch can cause loss, late collisions, poor throughput, or no link. Copper Gigabit Ethernet normally requires autonegotiation; do not force 1000BASE-T off-negotiation.
Persist a fixed 100 Mbit/s full-duplex mode in a NetworkManager profile:
|
# nmcli connection modify “server-lan” \ |
For 1000BASE-T, retain autonegotiation. NetworkManager can advertise only 1 Gbit/s full duplex while still negotiating:
|
# nmcli connection modify “server-lan” \ |
Restore unrestricted automatic negotiation in NetworkManager:
|
# nmcli connection modify “server-lan” \ |
Persist a fixed 100 Mbit/s link mode with a systemd link file:
|
# cat >/etc/systemd/network/10-enp1s0.link <<‘EOF’ [Link] |
Activation: A .link change is applied when the device is recreated or retriggered. It can disrupt the link. A reboot is often the safest planned activation method.
Persist a fixed 100 Mbit/s command under ifupdown:
|
auto enp1s0 |
Administrative State, MTU, and Queue State
|
# ip link set dev enp1s0 up |
Warning: Jumbo frames require every relevant path component to support the larger MTU. An inconsistent path can allow small pings while large TCP sessions stall.
Probe IPv4 path MTU with the do-not-fragment flag. For a 1500-byte Ethernet path, 1472 bytes of ICMP payload plus 28 bytes of IPv4/ICMP headers totals 1500:
|
$ ping -c 3 -M do -s 1472 198.51.100.25 |
Configure Virtual Interfaces
Linux supports virtual interfaces for testing, containers, virtual machines, routing, service addresses, and network segmentation. Temporary objects created with ip disappear at reboot unless a network manager recreates them.
Dummy Interface
|
# ip link add dummy0 type dummy |
Persist a dummy interface with Netplan:
|
network: |
Create a persistent NetworkManager dummy profile:
|
# nmcli connection add type dummy ifname dummy0 con-name dummy0 \ |
Virtual Ethernet Pair
A veth pair acts like a virtual patch cable. Frames entering one end leave the other and are commonly used with namespaces and containers:
|
# ip link add veth-a type veth peer name veth-b |
Bridge Interface
A bridge forwards Ethernet frames between member ports and is commonly used for virtual machines:
|
# ip link add br0 type bridge |
Address placement: When a physical interface becomes a bridge port, place the host IP address on the bridge, not on the enslaved physical interface.
Persist a bridge with Netplan:
|
network: |
Macvlan Interface
A macvlan gives a virtual interface its own MAC address on top of a parent interface. In bridge mode, peers can communicate through the lower interface, although direct host-to-macvlan communication needs extra design:
|
# ip link add macvlan0 link enp1s0 type macvlan mode bridge |
Static and DHCP IP Addressing
An IP address is written with a prefix length, such as 192.0.2.10/24 or 2001:db8:1::10/64. The prefix identifies which destinations are on-link. A default gateway is used for destinations not covered by a more specific route. Temporary ip commands modify the running kernel only; persistent settings must be stored in the active network manager.
Inspect Current Addresses and Address Metadata
|
$ ip -br address |
Useful address fields include scope, dynamic, secondary, tentative, deprecated, valid_lft, and preferred_lft. A tentative IPv6 address is still undergoing duplicate-address detection.
Temporary Static IPv4 Address – Add, Change, and Delete
Add a second address without removing existing addresses:
|
# ip address add 192.0.2.10/24 dev enp1s0 |
Replace an address entry, including its lifetime or label attributes:
|
# ip address replace 192.0.2.10/24 dev enp1s0 |
Delete one exact address:
|
# ip address del 192.0.2.10/24 dev enp1s0 |
Flush all global IPv4 addresses from an interface:
|
# ip -4 address flush dev enp1s0 scope global |
Warning: Flushing addresses can remove DHCP and static addresses at once and disconnect every session using the interface. Prefer deleting the exact unwanted prefix.
Temporary Static IPv6 Address
|
# ip -6 address add 2001:db8:1::10/64 dev enp1s0 |
IPv6 gateways: An IPv6 default gateway is commonly a link-local address such as fe80::1 and may require an explicit interface, for example ip -6 route add default via fe80::1 dev enp1s0.
Persistent Static Address with Netplan
Example /etc/netplan/01-server-lan.yaml using systemd-networkd as the renderer:
|
network: |
Protect, validate, test, and inspect the configuration:
|
# chmod 600 /etc/netplan/01-server-lan.yaml |
Default routes: Current Netplan configurations should express gateways as routes. Older gateway4 and gateway6 keys can still appear in existing systems but are less flexible and are deprecated in newer schemas.
Persistent Static Address with NetworkManager
Create a new Ethernet profile with a static IPv4 address:
|
# nmcli connection add type ethernet ifname enp1s0 con-name server-lan \ |
Change the address and remove the old value:
|
# nmcli connection modify server-lan ipv4.addresses 192.0.2.20/24 |
Add and remove a secondary address while retaining the primary:
|
# nmcli connection modify server-lan +ipv4.addresses 192.0.2.21/24 |
Persistent Static Address with systemd-networkd
Create /etc/systemd/network/20-enp1s0.network:
|
[Match] [Network] [Route] [Route] |
Reload and reconfigure only the interface:
|
# networkctl reload |
Persistent Static Address with ifupdown
Example /etc/network/interfaces stanza:
|
auto enp1s0 |
Apply during a maintenance window:
|
# ifdown enp1s0 && ifup enp1s0 |
Configure DHCP with Netplan
Obtain IPv4 and IPv6 configuration dynamically:
|
network: |
Use DHCP for the address but override route priority and ignore DHCP-provided DNS:
|
network: |
Configure DHCP with NetworkManager
Convert an existing profile to DHCP and clear manual IPv4 values:
|
# nmcli connection modify server-lan \ |
Inspect DHCP-derived parameters:
|
$ nmcli -f GENERAL,IP4,DHCP4 device show enp1s0 |
Configure DHCP with systemd-networkd
|
[Match] [Network] [DHCPv4] |
Configure DHCP with ifupdown
|
auto enp1s0 |
Request a new lease through ifupdown or, when the isc-dhcp-client package is installed, with dhclient:
|
# ifdown enp1s0 && ifup enp1s0 |
Verify a DHCP Lease
|
$ ip -br address show dev enp1s0 |
A valid lease normally supplies an address and prefix, one or more routes, lease lifetimes, and often DNS servers and search domains. Missing DNS does not mean the address lease failed; inspect each DHCP option separately.
Duplicate-Address Checks
Before assigning a static IPv4 address, send duplicate-address probes from the intended interface:
|
# arping -D -I enp1s0 -c 3 192.0.2.10 |
After assigning the address, announce it and update neighbour caches:
|
# arping -A -I enp1s0 -c 3 192.0.2.10 |
Caution: No reply does not prove that an address is unused if filtering, VLAN errors, sleeping systems, or non-ARP devices are present. Confirm with the address-management source of truth when available.
VLANs and IEEE 802.1Q Tagging
A VLAN separates Layer 2 broadcast domains by adding an IEEE 802.1Q tag containing a VLAN identifier. A switch access port normally carries one untagged VLAN. A trunk carries one or more tagged VLANs. The Linux parent interface must connect to a switch port configured for the same tagging model and allowed VLAN IDs.
Temporary VLAN Interface
Create VLAN 100 on parent enp1s0, assign an address, and activate it:
|
# ip link add link enp1s0 name vlan100 type vlan id 100 |
Delete the VLAN interface:
|
# ip link delete vlan100 |
Persistent VLAN with Netplan
|
network: |
Persistent VLAN with NetworkManager
|
# nmcli connection add type vlan con-name vlan100 ifname vlan100 \ |
Persistent VLAN with systemd-networkd
Create /etc/systemd/network/20-vlan100.netdev:
|
[NetDev] [VLAN] |
Attach the VLAN to the parent in /etc/systemd/network/20-enp1s0.network:
|
[Match] [Network] |
Address it in /etc/systemd/network/30-vlan100.network:
|
[Match] [Network] |
Persistent VLAN with ifupdown
Install VLAN support if required and use the dotted interface naming convention:
|
# apt install -y vlan auto enp1s0.100 |
VLAN Verification and Troubleshooting
|
$ ip -d link show type vlan |
- If no tagged frames leave the parent, confirm that the VLAN interface is up and traffic is routed through it.
- If tagged frames leave but no replies return, verify the switch trunk, allowed VLAN list, native VLAN, and remote VLAN membership.
- If untagged traffic is expected, configure the host on the physical interface rather than creating an 802.1Q subinterface.
- When using jumbo frames, include the VLAN overhead in the end-to-end MTU design and verify every switch hop.
Failover IP Address over Two Interfaces
For one host with two physical links, the normal method is an active-backup bond. The IP address is assigned once to bond0, not independently to both member interfaces. One member carries traffic while the other takes over after link failure. This keeps routing and application binding stable and allows gratuitous ARP or neighbour advertisements to update the network after failover. Both member links normally need equivalent Layer 2 and VLAN reachability to the same subnet; otherwise failover can preserve link state while still losing network reachability.
Different requirement: Moving a service IP between two separate hosts is a high-availability problem and normally uses VRRP/keepalived, a cluster manager, or a load balancer. The examples here provide link failover inside one host.
Active-Backup Bond with Netplan
|
network: |
The optional fail-over-mac-policy parameter can be none, active, or follow. Choose it only after considering switch port security, virtualisation, and hardware behaviour; the default policy is often the least surprising starting point.
Active-Backup Bond with NetworkManager
|
# nmcli connection add type bond ifname bond0 con-name bond0 \ |
Active-Backup Bond with systemd-networkd
Create /etc/systemd/network/10-bond0.netdev:
|
[NetDev] [Bond] |
Create a matching member file such as /etc/systemd/network/20-bond-members.network:
|
[Match] [Network] [Link] |
Address bond0 in /etc/systemd/network/30-bond0.network:
|
[Match] [Network] |
Active-Backup Bond with ifupdown
Install the bonding integration and configure the IP only on bond0:
|
# apt install -y ifenslave auto bond0 |
Test Active-Backup Failover
- Start a continuous ping through bond0 and note the active member.
- Disable the active switch port or administratively lower the active member.
- Confirm that the standby becomes active and packet loss is limited to the detection interval.
- Re-enable the member and observe whether primary re-selection matches policy.
- Check neighbour tables on adjacent systems if traffic does not resume.
|
$ watch -n 1 cat /proc/net/bonding/bond0 |
LACP / IEEE 802.3ad Aggregation
An 802.3ad bond negotiates a link aggregation group with the switch using LACP. It can provide link redundancy and aggregate bandwidth across multiple flows. A single flow is normally hashed to one member, so one TCP session may not exceed one physical link. The switch ports must be in the same compatible LACP port-channel; connecting members to independent switches requires multi-chassis link aggregation support on those switches.
LACP Bond with Netplan
|
network: |
LACP Bond with NetworkManager
|
# nmcli connection add type bond ifname bond0 con-name bond0 \ |
LACP Bond with systemd-networkd
|
[NetDev] [Bond] |
Use the same member and bond0 .network pattern shown for active-backup, then reload networkd. The switch-side LACP group must already be compatible or the members may remain collecting/distributing false.
LACP Bond with ifupdown
|
auto bond0 |
Verify LACP State and Distribution
|
$ cat /proc/net/bonding/bond0 |
- The aggregator IDs, actor/partner keys, and partner MAC should be consistent for members in the same LAG.
- Both members should report the expected speed and full duplex.
- Use several parallel iperf3 streams to exercise hashing across members.
- Unexpected one-way traffic often indicates an inconsistent switch port-channel or VLAN list.
|
$ iperf3 -c 198.51.100.20 -P 8 |
Routing
Linux selects the most specific matching route, then applies route preference and metrics. Connected routes are normally created from interface prefixes. Additional tables and ip rules can select routes by source address, destination, incoming interface, firewall mark, or other policy.
List All Routes and Rules
|
$ ip -4 route show |
Show routes associated with one device or protocol:
|
$ ip route show dev enp1s0 |
Temporary Default Route – Add, Change, and Delete
|
# ip route add default via 192.0.2.1 dev enp1s0 metric 100 |
IPv6 default route through a link-local gateway:
|
# ip -6 route add default via fe80::1 dev enp1s0 metric 100 |
Temporary Static Route – Add, Change, and Delete
|
# ip route add 198.51.100.0/24 via 192.0.2.254 dev enp1s0 metric 50 |
Create special-purpose routes:
|
# ip route add blackhole 203.0.113.0/24 |
replace: ip route replace is useful in scripts because it creates the route when absent and replaces it when present. Check ip route get afterward to confirm the selected source and next hop.
Permanent Default and Static Routes with Netplan
|
network: |
Permanent Routes with NetworkManager
Set the default gateway and add a static route to an existing profile:
|
# nmcli connection modify server-lan ipv4.gateway 192.0.2.1 |
Delete the exact static route entry:
|
# nmcli connection modify server-lan \ |
Permanent Routes with systemd-networkd
|
[Match] [Network] [Route] [Route] |
Permanent Routes with ifupdown
|
auto enp1s0 |
Multiple Default Routes and Metrics
A lower metric is preferred when otherwise equivalent routes exist. For example, use the wired default as primary and Wi-Fi as backup:
|
# ip route replace default via 192.0.2.1 dev enp1s0 metric 100 |
Netplan DHCP route metrics:
|
network: |
Policy Routing
Policy routing selects a table before the normal destination lookup. The following temporary example sends traffic sourced from 192.0.2.10 through table 100:
|
# ip route add table 100 192.0.2.0/24 dev enp1s0 src 192.0.2.10 |
Remove the policy in reverse order:
|
# ip rule del priority 100 |
Persist the same policy with Netplan:
|
network: |
Warning: Policy rules can create asymmetric paths that stateful firewalls or reverse-path filtering reject. Always inspect both forward and return routes.
Enable IP Forwarding
Temporarily enable IPv4 and IPv6 forwarding for a router or gateway:
|
# sysctl -w net.ipv4.ip_forward=1 |
Persist the settings in /etc/sysctl.d/60-router.conf:
|
net.ipv4.ip_forward = 1 |
Forwarding security: Enabling forwarding does not create firewall rules or NAT. Add an explicit nftables forward policy and, only when required, a carefully scoped masquerade or source-NAT rule.
Host Naming and Naming Services
Linux name resolution is broader than DNS. Applications commonly use the Name Service Switch (NSS), configured in /etc/nsswitch.conf, to search local files, systemd-resolved, DNS, mDNS, LDAP/SSSD, and other databases. Use getent to test the same NSS path used by most applications instead of testing DNS alone.
Display and Configure the Host Name
|
$ hostnamectl status |
Add a deliberate local mapping in /etc/hosts when required:
|
127.0.0.1 localhost |
FQDN behaviour: hostname –fqdn depends on name service configuration and is not simply the text stored in /etc/hostname. Verify the returned address as well as the name.
Inspect Name Service Switch Order
|
$ grep -E “^(hosts|networks|passwd|group):” /etc/nsswitch.conf |
A common hosts line includes local files before a DNS-capable source, for example:
|
hosts: files systemd dns |
Warning: Do not replace the hosts line blindly. Desktop discovery, mDNS, containers, LDAP, and local policy can require additional modules and ordering.
DNS Client Architecture
The resolver path can include an application, glibc NSS, /etc/resolv.conf, systemd-resolved, NetworkManager, a local caching resolver, and one or more upstream DNS servers. /etc/resolv.conf is frequently a symbolic link and may contain a local stub address rather than the upstream servers themselves.
Inspect DNS Configuration and Resolution
|
$ readlink -f /etc/resolv.conf |
Query a specific DNS server and display delegation or trace information:
|
$ dig @192.0.2.53 app.example.com A +noall +answer |
getent versus dig: getent tests the system NSS path and can return /etc/hosts or LDAP results. dig queries DNS directly and is better for inspecting DNS flags, authority records, TTLs, and a specific server. Use both when their results differ.
Temporary DNS Settings with systemd-resolved
|
# resolvectl dns enp1s0 192.0.2.53 192.0.2.54 |
Configure split DNS so only corp.example.com is routed to the interface DNS servers:
|
# resolvectl dns enp1s0 192.0.2.53 |
Routing domain: The leading tilde marks a route-only domain. It selects a DNS link without appending the domain as a search suffix.
Persistent DNS with Netplan
|
network: |
Persistent DNS with NetworkManager
|
# nmcli connection modify server-lan \ |
Use DHCP-provided DNS again:
|
# nmcli connection modify server-lan ipv4.ignore-auto-dns no ipv4.dns “” ipv4.dns-search “” |
Persistent DNS with systemd-networkd
|
[Match] [Network] [DHCPv4] |
systemd-resolved Drop-In
A global fallback resolver can be configured in /etc/systemd/resolved.conf.d/10-site-dns.conf:
|
[Resolve] |
Warning: A global DNS= setting can bypass link-specific split-DNS design. Prefer per-link DNS from the interface manager when different networks use different namespaces.
DNS Troubleshooting Sequence
- Resolve with getent to test the application NSS path.
- Inspect /etc/nsswitch.conf and the /etc/resolv.conf symlink.
- Inspect per-link servers and domains with resolvectl status.
- Ping or route-check the numeric DNS server address.
- Query the selected server directly with dig @server.
- Capture UDP and TCP port 53 while repeating the query.
- Check DNSSEC, VPN split-DNS, firewall, and MTU issues when replies are present but rejected.
|
$ getent ahosts app.example.com |
NTP Client Configuration and Management
Accurate time is required for TLS certificate validation, Kerberos, distributed logs, databases, monitoring, and LDAP or other authentication workflows. Chrony is a full-featured NTP implementation commonly used on servers. systemd-timesyncd is a simpler SNTP/NTP client on installations that do not use chrony. Avoid running multiple time synchronisation daemons against the same clock.
Inspect Time Synchronisation State
|
$ timedatectl status |
Configure Chrony
Install and enable chrony:
|
# apt update |
Example entries for /etc/chrony/chrony.conf:
|
pool ntp.ubuntu.com iburst maxsources 4 |
Validate source selection, offset, frequency, and reachability:
|
# systemctl restart chrony |
Step the clock immediately when policy permits:
|
# chronyc makestep |
Warning: A backward or large time step can disrupt databases, clustered services, token validation, and log ordering. Review application requirements before forcing a step on a production system.
Configure systemd-timesyncd
Create /etc/systemd/timesyncd.conf.d/10-site.conf:
|
[Time] |
Network requirements: An NTP client normally sends UDP to destination port 123. DNS must resolve named servers, and the firewall must permit the traffic. chronyc sources shows a reachability register that helps distinguish network failure from source rejection.
NTP Troubleshooting
|
$ getent ahosts ntp1.example.com |
- A source marked with an asterisk is the selected chrony source; a question mark usually means it is not reachable or usable.
- Large offsets can require time to slew unless makestep policy allows a step.
- Virtual machines can also receive time from the hypervisor; avoid conflicting clock sources.
- TLS and LDAP failures can be secondary symptoms of a clock that is outside certificate or ticket validity windows.
LDAP Client Configuration and Management
An LDAP client retrieves identity attributes such as users and groups and can authenticate through LDAP when designed to do so. On Debian and Ubuntu, SSSD provides caching, offline operation, NSS and PAM integration, access rules, and detailed diagnostics. Correct DNS, time synchronisation, certificate trust, and directory schema are prerequisites.
Warning: Do not send authentication credentials over unencrypted LDAP. Use StartTLS with ldap:// or use ldaps://, validate the server certificate, and restrict service-account secrets to root-readable files.
Test Directory Connectivity Before NSS/PAM Integration
Install query and SSSD tools:
|
# apt update |
Test anonymous or permitted StartTLS access and the search base:
|
$ ldapsearch -x -H ldap://ldap01.example.com -ZZ \ |
Configure SSSD for LDAP
Example /etc/sssd/sssd.conf for an RFC 2307bis-style directory:
|
[sssd] [domain/example.com] |
Protect, validate, and start SSSD:
|
# chown root:root /etc/sssd/sssd.conf |
Enable automatic home-directory creation when required by local policy:
|
# pam-auth-update –enable mkhomedir |
Verify LDAP Identity and Authentication Paths
|
$ getent passwd alice |
Clear cached records after a controlled directory change:
|
# sss_cache -u alice |
Warning: Clearing the entire cache removes offline identity data and can increase directory load. Clear only the affected entry when possible.
LDAP Logs and Troubleshooting
|
$ journalctl -b -u sssd |
||
|
Symptom |
Common cause |
Check |
|
ldapsearch works, getent fails |
NSS/SSSD configuration or cache |
nsswitch.conf, sssd service, sssctl config-check, SSSD logs. |
|
Certificate verify failed |
Untrusted CA, wrong name, expired certificate, or wrong time |
openssl s_client, CA bundle, timedatectl, server FQDN. |
|
User resolves but login fails |
PAM, bind/auth policy, access rule, or password control |
sssctl user-checks, auth logs, PAM profile, directory policy. |
|
Intermittent lookup delays |
DNS, unreachable LDAP URI, referrals, or enumeration |
DNS order, per-server reachability, enumerate=false, SSSD failover logs. |
|
Offline login fails |
Credentials never cached or cache expired |
Perform one online login, cache_credentials, offline policy. |
A lighter nslcd/libnss-ldapd client is available for simpler environments:
|
# apt install -y nslcd libnss-ldapd libpam-ldapd |
Client choice: Use one coherent LDAP integration stack. Running SSSD and nslcd for the same NSS databases can create duplicate lookups and inconsistent caching.
NFS Client Configuration and Management
NFS mounts a server-exported file system into the local directory tree. NFSv4 normally uses TCP port 2049 and can integrate authentication, locking, and pseudo-filesystem exports more cleanly than older versions. The exact export path and security flavour are controlled by the server.
Install and Discover NFS Exports
|
# apt update |
NFSv4 discovery: showmount queries the older mount protocol and can be empty or blocked on a pure NFSv4 server even when NFSv4 mounts work. Confirm the server-exported NFSv4 path with the server administrator.
Mount and Unmount an NFS File System
|
# mkdir -p /mnt/projects |
Test file access and the effective numeric ownership:
|
$ stat -f /mnt/projects |
Persistent NFS Mount in /etc/fstab
An on-demand systemd automount avoids blocking boot while the network or server is unavailable:
|
nfs01.example.com:/projects /mnt/projects nfs4 rw,_netdev,nofail,x-systemd.automount,x-systemd.idle-timeout=600,vers=4.2,proto=tcp 0 0 |
Hard mounts: NFS hard-mount behaviour is normally preferred for data integrity because operations retry during an outage. Soft mounts can turn a network interruption into application I/O errors and possible data corruption. Use them only with a clear application-specific reason.
NFS Performance and Troubleshooting
|
$ nfsstat -m |
Find processes preventing an unmount:
|
# fuser -vm /mnt/projects |
- Permission denied can mean the client is outside the export allow-list, the requested path is wrong, or the security flavour does not match.
- Numeric UID/GID mismatches produce unexpected ownership even when networking is correct. Keep directory identity sources consistent.
- Stale file handle errors normally require the server export or file identity to be corrected; remounting can clear the client state after the server issue is fixed.
- For NFSv4 through a firewall, permit TCP 2049 from the required clients. Older NFS versions can require additional dynamic RPC services.
Built-in Firewalls and Network Security
The Linux kernel netfilter framework performs packet filtering, state tracking, NAT, and mangling. nftables is the modern native ruleset interface. UFW provides a simpler policy-oriented front end and is commonly used on Ubuntu. Check which tool already owns the rules before making changes; UFW can itself program nftables or iptables-compatible rules depending on the system.
Inspect Existing Firewall State
|
$ sudo ufw status verbose |
Listening versus permitted: A listening socket does not prove that traffic is allowed, and an allow rule does not prove that a service is listening. Check both the socket and the firewall path.
Enable a UFW Firewall Safely
Permit management SSH from the administration subnet before enabling a default-deny inbound policy:
|
# apt install -y ufw |
Warning: Enabling a firewall remotely without a tested management allow rule can lock you out. Keep the current session open and test a second connection before closing it.
List and Manage UFW Rules
|
# ufw status numbered |
Warning: ufw reset removes user rules and returns UFW to an initial state. Export or record the rules before using it.
UFW Allow Examples
|
# ufw allow 80/tcp comment “HTTP” |
Application profiles can group related ports:
|
$ ufw app list |
UFW Block Examples
|
# ufw deny from 198.51.100.50 comment “Blocked source” |
deny versus reject: deny silently drops traffic. reject returns an error. Silent drops reveal less but take longer to diagnose; explicit rejects can be appropriate on trusted internal networks.
UFW Logging and IPv6
|
# ufw logging medium |
Confirm IPv6 policy in /etc/default/ufw and review both address families:
|
$ grep ^IPV6= /etc/default/ufw |
Warning: Do not secure only IPv4 while leaving globally routed IPv6 unfiltered. Also do not block all ICMPv6; neighbour discovery and path-MTU discovery depend on it.
Enable and Manage nftables
Install nftables, validate the persistent file, and enable the service:
|
# apt install -y nftables |
Example /etc/nftables.conf with a default-deny input policy:
|
#!/usr/sbin/nft -f flush ruleset table inet filter { chain input { ct state invalid drop ip protocol icmp accept ip saddr @management_v4 tcp dport 22 ct state new \ limit rate 5/second counter log prefix “nft-input-drop: ” drop chain forward { chain output { |
List, Add, and Delete nftables Rules
|
# nft list tables |
Delete a rule by the handle shown with nft -a:
|
# nft -a list chain inet filter input |
Rule order: nftables evaluates a base chain in order. Insert an exception before a broad terminal drop. Persist intentional changes in /etc/nftables.conf; interactive changes disappear when the ruleset is reloaded or the host reboots.
nftables Allow and Block Examples
|
# nft insert rule inet filter input iifname “vlan100” \ |
Use counters to confirm that a rule matches traffic:
|
# nft -a list chain inet filter input |
Forwarding and NAT with nftables
Allow a private subnet to forward out enp1s0 and masquerade its IPv4 source addresses:
|
table inet filter { table ip nat { |
Warning: NAT can conceal routing mistakes and complicate auditing. Prefer ordinary routed prefixes where possible, and scope masquerade to the exact source network and egress interface.
Firewall Diagnostics
|
$ ss -lntup |
A packet seen on the inbound interface but not delivered to a listening socket points toward local filtering, policy routing, address binding, or reverse-path checks. A packet never seen locally points toward the upstream path, VLAN, switch, or remote sender.
Selected Kernel Security Controls
Inspect reverse-path filtering and source routing controls:
|
$ sysctl net.ipv4.conf.all.rp_filter |
Example /etc/sysctl.d/60-network-security.conf for a simple single-path host:
|
net.ipv4.conf.all.accept_source_route = 0 |
Warning: Strict rp_filter can break asymmetric routing, policy routing, some VPNs, and multihomed servers. Use loose mode 2 or disable it only after understanding the path and compensating firewall controls.
Traffic Flow, Bandwidth, and Resource Control
Linux traffic control, exposed through tc, manages queueing disciplines, shaping, scheduling, policing, delay, loss, and packet classification. Queueing normally acts on egress because the host controls when it transmits. Ingress shaping generally requires policing or redirecting traffic to an Intermediate Functional Block (IFB) device.
Inspect Queueing Disciplines and Traffic-Control Counters
|
$ tc qdisc show dev enp1s0 |
The statistics show bytes, packets, drops, overlimits, requeues, and backlog. Record the original qdisc before replacing it so the change can be reversed accurately.
Use Fair Queueing with Controlled Delay
Replace the root qdisc with fq_codel to provide per-flow fairness and control excessive queue delay:
|
# tc qdisc replace dev enp1s0 root fq_codel |
Remove the custom root qdisc and allow the default to be recreated:
|
# tc qdisc del dev enp1s0 root |
Limit Egress Bandwidth with a Token Bucket Filter
Shape enp1s0 to approximately 100 Mbit/s:
|
# tc qdisc replace dev enp1s0 root tbf \ |
Remove the limit:
|
# tc qdisc del dev enp1s0 root |
Shaping accuracy: The burst, latency, timer resolution, NIC offloads, and workload affect the observed rate. Measure with iperf3 and application traffic, not only with the configured value.
Classify Traffic with HTB
The following laboratory example creates a 100 Mbit/s parent, gives traffic to 198.51.100.0/24 a 60 Mbit/s guarantee, and places other traffic in a 10 Mbit/s default class that can borrow unused capacity:
|
# tc qdisc replace dev enp1s0 root handle 1: htb default 20 |
Warning: A tc syntax or classification error can degrade all traffic on the interface. Test in a lab, retain a removal command, and make production changes from console access.
Emulate Delay, Loss, and Reordering for Testing
netem is useful for controlled application testing, not as a production fix:
|
# tc qdisc replace dev enp1s0 root netem delay 50ms 10ms loss 0.5% |
Warning: Always remove netem after the test. An abandoned impairment rule can look like a real network incident.
Measure Throughput with iperf3
Start a test server on one endpoint:
|
$ iperf3 -s |
Run forward, reverse, parallel, and UDP tests from the client:
|
$ iperf3 -c 198.51.100.20 |
Test design: iperf3 measures the endpoints and path under the selected protocol and stream count. CPU, encryption, window size, NIC offloads, disk I/O, Wi-Fi airtime, and other traffic can all limit results.
Per-Service Network Accounting and Address Restrictions
systemd can account IP traffic for a service and, on supported systems, enforce address allow/deny controls. Create a service drop-in with systemctl edit example.service:
|
[Service] |
Warning: IPAddressAllow and IPAddressDeny can prevent a service from reaching dependencies such as DNS, NTP, package repositories, proxies, or databases. Apply them only after mapping all required destinations and confirming kernel/cgroup support.
Network Namespace Isolation Example
A network namespace has its own interfaces, routes, neighbours, firewall state, and sockets. Create a small isolated namespace connected by a veth pair:
|
# ip netns add lab |
Remove the laboratory namespace and its veth pair:
|
# ip netns delete lab |
Monitoring Traffic on an Interface
Interface Counters
|
$ ip -s link show dev enp1s0 |
Important counters include receive/transmit bytes and packets, errors, dropped packets, missed packets, overruns, carrier errors, collisions, and driver-specific CRC or queue counters. Compare the rate of change rather than relying only on the absolute value.
Interactive Bandwidth Tools
|
# apt install -y nload iftop bmon vnstat |
Permissions: Tools that inspect packet headers can require root or packet-capture capabilities. Run with the least privilege required and protect any captured data.
Packet Capture with tcpdump
Capture all packets on an interface without resolving names or ports:
|
# tcpdump -ni enp1s0 -nn |
Useful filters:
|
# tcpdump -ni enp1s0 host 198.51.100.25 |
Write a bounded rotating capture for later Wireshark analysis:
|
# tcpdump -ni enp1s0 -s 0 -C 100 -W 5 \ |
Warning: Packet captures can contain credentials, session tokens, personal data, and confidential payloads. Limit the interface, hosts, ports, duration, and file access; delete captures according to policy.
Monitor Sockets and TCP Health
|
$ ss -s |
ss -ti can display congestion-control state, round-trip time, retransmissions, congestion window, pacing rate, and bytes in flight for TCP sockets. nstat exposes protocol counters such as retransmitted segments and ICMP errors.
Collect Performance Metrics with sysstat
|
# apt install -y sysstat |
|
|
Metric view |
What it helps identify |
|
sar -n DEV |
Packets and throughput per interface. |
|
sar -n EDEV |
Receive/transmit errors, drops, FIFO issues, carrier errors, and collisions. |
|
sar -n TCP |
Active/passive opens, segments, and TCP connection behaviour. |
|
sar -n ETCP |
Retransmissions and TCP failures. |
|
ethtool -S |
NIC and driver-specific queue, CRC, pause, and hardware counters. |
|
ss -ti |
Per-connection RTT, retransmission, congestion, and window details. |
|
tc -s qdisc |
Queue drops, backlog, overlimits, and shaping activity. |
|
vnstat |
Longer-term interface byte totals independent of packet payload capture. |
Create a Simple Baseline
Collect the same measurements during a healthy period and an incident:
|
$ date -Is |
Rate and correlation: One counter is rarely conclusive. Correlate interface errors, TCP retransmissions, queue drops, application latency, CPU load, and timestamps with switch and remote endpoint metrics.
Troubleshooting Workflow
Troubleshooting should produce evidence at each layer rather than a sequence of speculative configuration changes. Record the time, interface, source and destination, protocol, port, expected path, and whether the problem affects one host, one VLAN, one application, or the entire system.
Step-by-Step Network Troubleshooting
- Confirm the symptom with an exact command and record the timestamp.
- Identify the interface owner: Netplan/backend, NetworkManager, systemd-networkd, or ifupdown.
- Check hardware detection, driver, administrative state, carrier, speed, duplex, MTU, and errors.
- Check the expected address and prefix, including duplicate-address state and DHCP lease details.
- Check ARP or IPv6 neighbour state to the local gateway or peer.
- Check route selection with ip route get, including source address and policy tables.
- Test numeric reachability before DNS; then test NSS and direct DNS independently.
- Check the local and remote listening socket and the relevant firewall direction.
- Use traceroute/tracepath to identify the last responding hop and possible MTU changes.
- Capture packets at the closest useful interface and correlate the trace with service and kernel logs.
- Compare counters and performance metrics with a known-good baseline.
- Make one controlled change, retest, and either keep or roll it back.
ping – Reachability, Latency, and Loss
ping sends ICMP echo requests and reports replies, loss, and round-trip time. Some networks filter echo, so a failed ping does not by itself prove the destination application is unavailable.
|
$ ping -c 4 192.0.2.1 |
Test path MTU and prevent IPv4 fragmentation:
|
$ ping -c 3 -M do -s 1472 198.51.100.25 |
|
|
Observation |
Interpretation |
|
Local gateway does not reply |
Investigate link, VLAN, address/prefix, ARP, switch, or gateway filtering. |
|
Gateway replies; remote IP does not |
Investigate routing, upstream filtering, remote host, or return path. |
|
Remote IP replies; name fails |
Investigate NSS/DNS rather than general IP connectivity. |
|
Small payload works; large DF payload fails |
Suspect path-MTU discovery or an MTU mismatch. |
|
Variable high RTT and loss |
Check congestion, Wi-Fi quality, queueing, duplex/errors, and remote load. |
arp, ip neighbour, and arping
ARP maps IPv4 addresses to MAC addresses on the local link. The legacy arp command can display the cache, but ip neighbour is the preferred interface and also covers IPv6 neighbour discovery.
|
$ arp -n |
Delete or flush stale neighbour entries:
|
# ip neighbour del 192.0.2.1 dev enp1s0 |
Probe a peer or check a candidate address:
|
# arping -I enp1s0 -c 4 192.0.2.1 |
|
|
Neighbour state |
Meaning |
|
REACHABLE |
Recently confirmed as reachable. |
|
STALE |
Entry is valid but has not been recently confirmed; normal until used. |
|
DELAY / PROBE |
Kernel is actively confirming reachability. |
|
INCOMPLETE |
Resolution request sent; no MAC learned yet. |
|
FAILED |
Resolution attempts failed. Check subnet, VLAN, peer, and switch path. |
|
PERMANENT |
Static neighbour entry; kernel does not age it normally. |
traceroute and tracepath – Path Discovery
traceroute sends probes with increasing TTL or hop-limit values. Routers can filter or rate-limit the resulting ICMP replies, so asterisks do not always indicate packet loss for real application traffic.
|
$ traceroute -n 198.51.100.25 |
- Use numeric output first to prevent slow or misleading reverse-DNS lookups.
- TCP probes to the application port can traverse paths that filter classic UDP traceroute.
- tracepath reports discovered path MTU and usually does not require root.
- Compare forward and return paths when asymmetric routing is possible; a local trace shows only one direction.
nc – TCP and UDP Port Testing
netcat opens TCP or UDP connections and can create a simple listener. It is a diagnostic tool, not an encrypted or authenticated application protocol.
|
$ nc -vz -w 3 app.example.com 443 |
Create a temporary TCP listener on one host and connect from another:
|
# nc -l 9000 |
For a UDP listener and sender:
|
# nc -u -l 9000 |
Warning: A netcat listener exposes a raw unauthenticated port. Bind only on a controlled test network, add temporary firewall scope, and stop it immediately after testing.
ss – Socket and Connection Inspection
|
$ ss -lntup |
A large SYN-SENT population suggests unanswered connection attempts. A listener bound only to 127.0.0.1 will not accept connections to the external interface. A listener on 0.0.0.0 or [::] can accept on multiple addresses subject to application and firewall policy.
dig, getent, and resolvectl – Name Resolution
|
$ getent ahosts app.example.com |
Inspect DNS response codes and flags:
|
$ dig @192.0.2.53 app.example.com A +comments +answer +authority |
tcpdump – Packet-Level Evidence
A healthy TCP connection begins with SYN, SYN-ACK, ACK. Repeated SYN packets with no SYN-ACK suggest filtering, routing, or an unavailable destination. An immediate RST normally means the host is reachable but the port is closed or actively rejected.
|
# tcpdump -ni enp1s0 -nn “host 198.51.100.25 and tcp port 443” |
Observe ARP, DHCP, DNS, and ICMP separately:
|
# tcpdump -eni enp1s0 arp |
Capture traffic for one VLAN and verify the tag at the parent interface:
|
# tcpdump -eni enp1s0 vlan 100 |
curl and Application-Layer Testing
|
$ curl -v –connect-timeout 5 https://app.example.com/ |
–resolve: curl –resolve separates DNS from the rest of the HTTPS test by forcing one address while retaining the original host name for HTTP Host and TLS SNI.
Optional mtr Continuous Path Testing
|
# apt install -y mtr-tiny |
Warning: Intermediate routers can deprioritise mtr replies while forwarding real traffic normally. Loss at one hop is significant only when it continues to later hops or correlates with endpoint loss.
Troubleshooting Common Scenarios
Interface Missing
|
$ lspci -nnk | grep -A3 -i ethernet |
Check hardware visibility, driver binding, firmware errors, disabled BIOS/UEFI devices, and predictable-name changes. Compare lspci with /sys/class/net to determine whether hardware exists without an interface.
Interface Present but No Carrier
|
$ ip -br link show enp1s0 |
Verify cable/optic, switch port, speed negotiation, transceiver compatibility, radio block, and that the correct physical port corresponds to the Linux name.
DHCP Does Not Obtain an Address
|
$ ip -br link show enp1s0 |
A DHCPDISCOVER with no DHCPOFFER points toward VLAN, switch relay, server scope, or path filtering. An OFFER without a completed ACK can indicate policy, duplicate addresses, or client/server state mismatch.
Local Subnet Peer Is Unreachable
|
$ ip address show dev enp1s0 |
Focus on prefix length, VLAN, ARP, bridge/bond membership, peer state, duplicate addresses, and local firewall. A gateway is not normally involved for peers in the same prefix.
Internet Works by Address but Not by Name
|
$ ping -c 3 198.51.100.25 |
Inspect the resolv.conf symlink, per-link DNS server, route to that server, search domains, DNSSEC status, VPN split-DNS, and UDP/TCP port 53 filtering.
Remote Service Is Unreachable
|
$ ip route get 198.51.100.20 |
On the server, confirm the listening address, process, local firewall, and service logs:
|
$ ss -ltnp sport = :443 |
Intermittent Freezes or MTU Black Hole
|
$ tracepath 198.51.100.25 |
Look for ICMP fragmentation-needed or ICMPv6 packet-too-big messages, TCP retransmissions after larger packets, VPN/tunnel overhead, and inconsistent jumbo-frame settings.
Slow Throughput
|
$ ethtool enp1s0 |
Check negotiated speed/duplex, CRC and pause counters, packet loss, retransmissions, qdisc drops, Wi-Fi signal/airtime, CPU saturation, encryption, application limits, and whether one LACP flow is constrained to a single member.
VLAN Traffic Fails
|
$ ip -d link show vlan100 |
Confirm parent state, VLAN ID, tagged versus untagged switch configuration, allowed VLAN list, native VLAN, bridge VLAN filtering, and address placement.
Bond or LACP Fails Over Incorrectly
|
$ cat /proc/net/bonding/bond0 |
For active-backup, check the active member, MII state, primary policy, MAC movement, and gratuitous ARP. For LACP, check actor/partner state, aggregator IDs, switch port-channel membership, VLAN parity, and multi-chassis support.
Common Errors and Focused Fixes
|
Problem |
Likely explanation |
Focused action |
|
Network is unreachable |
No matching route or interface has no usable address. |
ip route get; inspect address, link route, and default route. |
|
Destination Host Unreachable from local host |
Neighbour resolution or local route failed. |
ip neigh, arping, VLAN, prefix, peer state. |
|
Connection refused |
Destination replied with TCP RST or firewall reject. |
Check server listener, bind address, service status, reject rules. |
|
Connection timeout |
Silent drop, route failure, loss, or application not responding. |
tcpdump both ends, traceroute TCP, firewall and return path. |
|
RTNETLINK: File exists |
Conflicting existing object. |
ip address/route/rule show; remove exact duplicate or use replace. |
|
Temporary failure in name resolution |
Resolver unavailable or misconfigured. |
getent, resolvectl, resolv.conf symlink, dig @server. |
|
Address already in use |
Duplicate address or local bind conflict. |
arping -D, ip address, ss -lntup, address inventory. |
|
No such device |
Wrong/renamed interface or missing driver. |
ip link, udevadm, lspci -k, kernel logs. |
|
Operation not supported |
Driver/hardware lacks requested feature. |
ethtool -i/-k, kernel/driver docs, alternate mode. |
|
Netplan rollback or apply failure |
YAML/backend conflict or remote confirmation timeout. |
netplan generate –debug, journal, one manager per interface. |
|
NFS server not responding |
Path, firewall, DNS, route, or server outage. |
getent, nc 2049, mount -v, nfsstat, capture. |
|
LDAP certificate verify failed |
CA/name/time mismatch. |
openssl s_client, CA trust, DNS name, timedatectl. |
Collect a Network Diagnostic Snapshot
The following example creates a text bundle without packet payloads. Review it for secrets and internal details before sharing:
|
# out=/var/tmp/netdiag-$(date +%F-%H%M%S) |
Warning: Diagnostic bundles can expose addresses, routes, DNS domains, firewall policy, process names, and host identifiers. Store and transfer them securely.
Command Reference Summary
|
Task |
Command |
|
List interfaces and addresses |
ip -br link; ip -br address |
|
Show detailed interface state |
ip -s -d link show dev enp1s0 |
|
Show Ethernet link and driver |
ethtool enp1s0; ethtool -i enp1s0 |
|
Show wireless state |
iw dev; iw dev wlp2s0 link; rfkill list |
|
Show MAC address |
ip link show enp1s0; ethtool -P enp1s0 |
|
Temporary address add/delete |
ip addr add PREFIX dev IFACE; ip addr del PREFIX dev IFACE |
|
List routes and rules |
ip route; ip -6 route; ip rule |
|
Explain route choice |
ip route get DEST from SOURCE |
|
Add/replace default route |
ip route replace default via GATEWAY dev IFACE metric N |
|
Add/delete static route |
ip route add PREFIX via GATEWAY; ip route del PREFIX via GATEWAY |
|
Show neighbours |
ip neigh show; ip -6 neigh show |
|
Test duplicate IPv4 address |
arping -D -I IFACE -c 3 ADDRESS |
|
List listening sockets |
ss -lntup |
|
Test TCP port |
nc -vz -w 3 HOST PORT |
|
Trace TCP path |
traceroute -T -p PORT -n HOST |
|
Check path MTU |
tracepath HOST; ping -M do -s SIZE HOST |
|
DNS through NSS |
getent ahosts NAME |
|
Direct DNS query |
dig @SERVER NAME TYPE |
|
Resolver status |
resolvectl status |
|
Capture packets |
tcpdump -ni IFACE FILTER |
|
Netplan validate/test |
netplan generate; netplan try; netplan status –all |
|
NetworkManager profiles |
nmcli con show; nmcli dev status |
|
networkd state |
networkctl list; networkctl status IFACE |
|
Bond state |
cat /proc/net/bonding/bond0 |
|
VLAN details |
ip -d link show type vlan |
|
UFW rules |
ufw status numbered |
|
nftables rules |
nft -a list ruleset |
|
Interface metrics |
ip -s link; ethtool -S IFACE; sar -n DEV,EDEV 1 |
|
TCP metrics |
ss -ti; nstat -az; sar -n TCP,ETCP 1 |
|
Queue metrics |
tc -s qdisc show dev IFACE |
|
NTP status |
chronyc tracking; chronyc sources -v; timedatectl |
|
LDAP identity test |
getent passwd USER; id USER; sssctl user-checks USER |
|
NFS mount state |
findmnt; nfsstat -m; nfsiostat 1 |
|
Follow network logs |
journalctl -f -u NetworkManager -u systemd-networkd |
Quick Layer-to-Tool Reference
|
Layer or service |
Inspect |
Configure or manage |
|
Physical Ethernet |
lspci, lshw, ethtool, journalctl -k |
ethtool -s, .link, driver/module settings |
|
Wireless physical/link |
iw phy, iw dev, rfkill, nmcli wifi |
nmcli, Netplan, iw/rfkill for temporary state |
|
Data link |
ip -s -d link, bridge, ip neigh |
ip link, bridge, Netplan/NM/networkd/ifupdown |
|
VLAN |
ip -d link, bridge vlan, tcpdump -e |
ip link type vlan, Netplan/NM/.netdev/interfaces |
|
Bond/LACP |
/proc/net/bonding, ip -d link |
Netplan/NM/.netdev/ifupdown plus switch LAG |
|
IPv4/IPv6 address |
ip address, manager status |
ip address, persistent manager profile |
|
Routing |
ip route, ip rule, ip route get |
ip route/rule, persistent routes and policies |
|
TCP/UDP |
ss, nc, tcpdump, nstat |
Application bind, firewall, sysctl, tc |
|
DNS |
getent, resolvectl, dig |
Netplan/NM/networkd, resolved, NSS, hosts |
|
NTP |
timedatectl, chronyc |
chrony.conf or timesyncd drop-in |
|
LDAP |
ldapsearch, getent, id, sssctl |
sssd.conf, PAM/NSS, CA trust |
|
NFS |
findmnt, nfsstat, nfsiostat, tcpdump |
mount, fstab, systemd automount |
|
Firewall |
ufw status, nft list ruleset, counters/logs |
ufw commands or /etc/nftables.conf |
|
Performance |
sar, ethtool -S, ss -ti, tc -s, iperf3 |
tc, qdisc/classes, service IP accounting |
Final Notes
Debian and Ubuntu networking is easiest to manage when each interface has one configuration owner, temporary tests are clearly separated from persistent changes, and troubleshooting follows the stack from hardware to application. Save a known-good configuration, keep console recovery available for routing and firewall changes, and validate both IPv4 and IPv6 where they are enabled.
The most valuable operational habit is to capture evidence before changing state: link negotiation, addresses, neighbour entries, route selection, DNS source, listening sockets, firewall counters, packet traces, and time-correlated logs. That evidence distinguishes a local configuration problem from an upstream path or remote service failure and makes the final fix repeatable.
Authoritative References
The following official project and distribution documentation provides current syntax, option definitions, and release-specific detail. Package versions and defaults can differ between Debian and Ubuntu releases, so check the local man pages as well as these references.
- Ubuntu Server: Configuring networks – Netplan-based address, route, bridge, bond, and VLAN configuration.
- Netplan YAML configuration reference – Complete schema for interfaces, routes, policy routing, VLANs, bridges, and bonds.
- Netplan CLI reference – generate, apply, try, get, set, and status operations.
- Debian Reference – Chapter 5: Network setup – Debian network configuration, naming, and troubleshooting overview.
- NetworkManager nmcli examples – Official profile, Ethernet, bridge, bond, and IP examples.
- NetworkManager settings reference – Ethernet autonegotiation, speed, duplex, and related profile properties.
- systemd.network manual – systemd-networkd addresses, routes, DHCP, DNS, and virtual-device attachment.
- systemd.netdev manual – Bonds, bridges, VLANs, tunnels, and other virtual devices.
- systemd.link manual – Persistent link naming and hardware properties.
- Linux kernel networking documentation – Kernel interfaces, drivers, bonding, scaling, and networking internals.
- Ubuntu Server: Firewall and UFW – UFW installation, enablement, rule syntax, and logging.
- nftables project wiki – Ruleset concepts, tables, chains, sets, NAT, and troubleshooting.
- Chrony documentation – chronyd and chronyc configuration and diagnostics.
- Ubuntu Server: SSSD with LDAP – LDAP client setup with SSSD, TLS, NSS, and PAM.
- Ubuntu Server: Network File System (NFS) – NFS client/server installation and mount examples.
- Debian manpages – Release-specific manuals for ip, ss, ethtool, nft, interfaces, systemd, and service tools.
Check out our other Cheat Sheets and Blogs and if you would like us to write a cheat sheet for you, for FREE, (and we find it suitable) Contact Us.