Your Network at a Glance#
Before troubleshooting or configuring anything, you need to know what your current network setup looks like. Linux provides the ip command as the primary tool for this — it replaces the older ifconfig and route commands.
Viewing Network Interfaces#
An interface is a connection point to a network — physical (Ethernet, Wi-Fi) or virtual (loopback, VPN tunnels).
# List all interfaces and their state
ip link showOutput:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP
link/ether 52:54:00:ab:cd:ef brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 state DOWN
link/ether a0:b1:c2:d3:e4:f5 brd ff:ff:ff:ff:ff:ff| Field | Meaning |
|---|---|
lo | Loopback (localhost, always present) |
eth0 | First Ethernet interface |
wlan0 | Wireless interface |
UP | Interface is enabled |
DOWN | Interface is disabled |
state UP | Link is connected |
mtu 1500 | Maximum packet size (bytes) |
link/ether | MAC address |
Finding Your IP Address#
# Show all addresses on all interfaces
ip addr show
# Short form
ip a
# Show addresses for a specific interface
ip addr show eth0Output:
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
link/ether 52:54:00:ab:cd:ef brd ff:ff:ff:ff:ff:ff
inet 192.168.1.50/24 brd 192.168.1.255 scope global dynamic eth0
inet6 fe80::5054:ff:feab:cdef/64 scope link| Field | Meaning |
|---|---|
inet 192.168.1.50/24 | IPv4 address and subnet mask (CIDR notation) |
/24 | Subnet mask = 255.255.255.0 (first 24 bits are the network) |
brd 192.168.1.255 | Broadcast address |
dynamic | Assigned by DHCP |
inet6 fe80::... | IPv6 link-local address |
scope global | Routable address |
scope link | Only valid on this network segment |
CIDR to subnet mask reference#
| CIDR | Subnet Mask | Usable Hosts |
|---|---|---|
/8 | 255.0.0.0 | 16,777,214 |
/16 | 255.255.0.0 | 65,534 |
/24 | 255.255.255.0 | 254 |
/25 | 255.255.255.128 | 126 |
/30 | 255.255.255.252 | 2 |
Quick one-liner for just the IP#
ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'Or more readably:
hostname -IFinding Your Default Gateway#
The gateway is the router that forwards traffic to other networks (the internet):
ip route showOutput:
default via 192.168.1.1 dev eth0 proto dhcp metric 100
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.50| Line | Meaning |
|---|---|
default via 192.168.1.1 | Default gateway — all traffic not matching other routes goes here |
dev eth0 | Via this interface |
192.168.1.0/24 dev eth0 | The local subnet is directly connected |
Just the gateway IP#
ip route show default | awk '{print $3}'Finding Your DNS Servers#
DNS servers translate domain names to IP addresses. Check your configuration:
# Modern systems using systemd-resolved
resolvectl status
# Or check the traditional file
cat /etc/resolv.conf/etc/resolv.conf output:
nameserver 192.168.1.1
nameserver 8.8.8.8On systems with systemd-resolved, the actual resolvers may differ from what’s in /etc/resolv.conf. Use resolvectl status for the truth.
Testing Connectivity#
ping — Can you reach a host?#
# Ping by IP (tests Layer 3 — routing)
ping -c 4 8.8.8.8
# Ping by hostname (tests DNS + routing)
ping -c 4 google.com
# Ping your gateway (first thing to check when things break)
ping -c 4 192.168.1.1The -c 4 flag sends 4 packets and stops. Without it, ping runs until you press Ctrl-c.
Troubleshooting with ping:
| Result | Likely problem |
|---|---|
| Gateway responds, internet doesn’t | Routing or ISP issue |
| Nothing responds | Interface down, wrong IP, cable unplugged |
| IP works, hostname doesn’t | DNS problem |
traceroute / tracepath — What path do packets take?#
# Show every hop between you and the destination
traceroute google.com
# tracepath (doesn't require root)
tracepath google.comEach line is a router between you and the target. Useful for finding where connectivity breaks.
nc (netcat) — Is a specific port reachable?#
# Test if port 443 is open on a host
nc -zv google.com 443
# Test SSH on a server
nc -zv 192.168.1.100 22-z scans without sending data, -v gives verbose output.
ss — What’s listening on your machine?#
# Show all listening TCP ports
ss -tlnp
# Show all listening UDP ports
ss -ulnp
# Show all established connections
ss -tunap| Flag | Meaning |
|---|---|
-t | TCP |
-u | UDP |
-l | Listening only |
-n | Numeric (don’t resolve names) |
-p | Show process using the port |
Configuring a Static IP Address#
Temporary (until reboot)#
# Add an IP address to an interface
sudo ip addr add 192.168.1.100/24 dev eth0
# Remove an IP address
sudo ip addr del 192.168.1.100/24 dev eth0Set the default gateway#
# Add a default route
sudo ip route add default via 192.168.1.1 dev eth0
# Remove the default route
sudo ip route del defaultPersistent with NetworkManager (nmcli)#
Most desktop and server distributions use NetworkManager. Use nmcli for persistent changes:
# Show connections
nmcli connection show
# Set a static IP
nmcli connection modify "Wired connection 1" \
ipv4.method manual \
ipv4.addresses 192.168.1.100/24 \
ipv4.gateway 192.168.1.1 \
ipv4.dns "8.8.8.8,1.1.1.1"
# Apply the changes
nmcli connection up "Wired connection 1"Switch back to DHCP#
nmcli connection modify "Wired connection 1" \
ipv4.method auto
nmcli connection up "Wired connection 1"Persistent with netplan (Ubuntu server)#
Ubuntu servers often use netplan. Edit /etc/netplan/01-config.yaml:
network:
version: 2
ethernets:
eth0:
addresses:
- 192.168.1.100/24
routes:
- to: default
via: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 1.1.1.1Apply:
sudo netplan applyDHCP vs Static#
| DHCP | Static | |
|---|---|---|
| How it works | Router assigns IP automatically | You configure IP manually |
| Use when | Desktops, laptops, most workstations | Servers, printers, infrastructure |
| Pros | Zero config, no conflicts | Predictable, won’t change |
| Cons | IP may change over time | Must track assignments yourself |
Most machines use DHCP by default. Switch to static when you need a predictable address — for SSH access, running a web server, or DNS records.
Bringing Interfaces Up and Down#
# Disable an interface
sudo ip link set eth0 down
# Enable an interface
sudo ip link set eth0 up
# Check state
ip link show eth0With NetworkManager:
nmcli device disconnect eth0
nmcli device connect eth0Viewing Your MAC Address#
ip link show eth0 | grep link/ether
# link/ether 52:54:00:ab:cd:efChange it temporarily (useful for testing):
sudo ip link set eth0 down
sudo ip link set eth0 address 02:01:02:03:04:05
sudo ip link set eth0 upQuick Reference#
| Task | Command |
|---|---|
| Show all interfaces | ip link show |
| Show IP addresses | ip addr show |
| Show default gateway | ip route show default |
| Show DNS servers | resolvectl status |
| Ping a host | ping -c 4 host |
| Trace route to host | tracepath host |
| Check open ports | ss -tlnp |
| Test a port | nc -zv host port |
| Set static IP (temp) | sudo ip addr add IP/MASK dev IFACE |
| Set gateway (temp) | sudo ip route add default via GW |
| Set static IP (permanent) | nmcli connection modify ... |
| Bring interface up | sudo ip link set IFACE up |
Best Practices#
- Use
ipcommands instead ofifconfigandroute— they’re deprecated on modern systems - Always test with
pingto your gateway first — if that fails, the problem is local - Use
-cwith ping to avoid running forever - Set static IPs on servers so they don’t change when DHCP leases expire
- Keep DNS settings separate from your router when possible — use
1.1.1.1or8.8.8.8as a fallback - Remember that
ip addr addis temporary — usenmclior netplan for changes that survive reboot - Check
ss -tlnpwhen troubleshooting services — if nothing is listening, the service isn’t running


