Skip to main content

Linux Networking: Viewing and Configuring Your Network

·1190 words·6 mins
Linux Learning Lab
Author
Linux Learning Lab
Writing about code, tools, and workflows.
linux-networking - This article is part of a series.
Part 1: This Article

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 show

Output:

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
FieldMeaning
loLoopback (localhost, always present)
eth0First Ethernet interface
wlan0Wireless interface
UPInterface is enabled
DOWNInterface is disabled
state UPLink is connected
mtu 1500Maximum packet size (bytes)
link/etherMAC 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 eth0

Output:

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
FieldMeaning
inet 192.168.1.50/24IPv4 address and subnet mask (CIDR notation)
/24Subnet mask = 255.255.255.0 (first 24 bits are the network)
brd 192.168.1.255Broadcast address
dynamicAssigned by DHCP
inet6 fe80::...IPv6 link-local address
scope globalRoutable address
scope linkOnly valid on this network segment

CIDR to subnet mask reference
#

CIDRSubnet MaskUsable Hosts
/8255.0.0.016,777,214
/16255.255.0.065,534
/24255.255.255.0254
/25255.255.255.128126
/30255.255.255.2522

Quick one-liner for just the IP
#

ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'

Or more readably:

hostname -I

Finding Your Default Gateway
#

The gateway is the router that forwards traffic to other networks (the internet):

ip route show

Output:

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
LineMeaning
default via 192.168.1.1Default gateway — all traffic not matching other routes goes here
dev eth0Via this interface
192.168.1.0/24 dev eth0The 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.8

On 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.1

The -c 4 flag sends 4 packets and stops. Without it, ping runs until you press Ctrl-c.

Troubleshooting with ping:

ResultLikely problem
Gateway responds, internet doesn’tRouting or ISP issue
Nothing respondsInterface down, wrong IP, cable unplugged
IP works, hostname doesn’tDNS 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.com

Each 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
FlagMeaning
-tTCP
-uUDP
-lListening only
-nNumeric (don’t resolve names)
-pShow 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 eth0

Set 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 default

Persistent 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.1

Apply:

sudo netplan apply

DHCP vs Static
#

DHCPStatic
How it worksRouter assigns IP automaticallyYou configure IP manually
Use whenDesktops, laptops, most workstationsServers, printers, infrastructure
ProsZero config, no conflictsPredictable, won’t change
ConsIP may change over timeMust 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 eth0

With NetworkManager:

nmcli device disconnect eth0
nmcli device connect eth0

Viewing Your MAC Address
#

ip link show eth0 | grep link/ether
# link/ether 52:54:00:ab:cd:ef

Change 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 up

Quick Reference
#

TaskCommand
Show all interfacesip link show
Show IP addressesip addr show
Show default gatewayip route show default
Show DNS serversresolvectl status
Ping a hostping -c 4 host
Trace route to hosttracepath host
Check open portsss -tlnp
Test a portnc -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 upsudo ip link set IFACE up

Best Practices
#

  • Use ip commands instead of ifconfig and route — they’re deprecated on modern systems
  • Always test with ping to your gateway first — if that fails, the problem is local
  • Use -c with 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.1 or 8.8.8.8 as a fallback
  • Remember that ip addr add is temporary — use nmcli or netplan for changes that survive reboot
  • Check ss -tlnp when troubleshooting services — if nothing is listening, the service isn’t running
linux-networking - This article is part of a series.
Part 1: This Article