Linux Networking Basics: Understanding IP, DNS, and Routing

Networking is the backbone of every Linux system. In this guide, you’ll learn the essentials of IP addressing, DNS resolution, and routing — everything you need to understand how your Linux system communicates with the world.

Linux Networking Basics: Understanding IP, DNS, and Routing
Learn the fundamentals of Linux networking — IP addressing, DNS resolution, and routing. Understand how Linux connects, resolves, and routes traffic efficiently.

Introduction: Why Networking Matters in Linux

Every server, workstation, and container running Linux depends on networking.
Whether you’re connecting to the internet, transferring files, or running web services — networking is the invisible thread that makes it all possible.

Linux provides powerful tools to inspect, configure, and troubleshoot networks, giving administrators full control over how data flows.

In this guide, we’ll explore three foundational components:

  1. IP addressing – how Linux identifies and communicates with other systems.
  2. DNS – how human-readable names (like google.com) are resolved into IP addresses.
  3. Routing – how packets find their path through networks.

Let’s get connected. 🔌


🧩 1. IP Addressing: The Identity of a Linux Machine

Every device in a network needs an IP address — a unique identifier that allows it to send and receive data.

Linux supports both IPv4 (e.g., 192.168.1.10) and IPv6 (e.g., fe80::1ff:fe23:4567:890a).


📘 Check Your Current IP Address

Use one of the following commands:

ip addr show

or shorter:

ip a

Example output:

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500
inet 192.168.1.10/24 brd 192.168.1.255 scope global
eth0
inet6 fe80::20c:29ff:fe12:3456/64 scope link

Here:

  • eth0 → your network interface
  • 192.168.1.10/24 → your IPv4 address
  • /24 → subnet mask (255.255.255.0)

🧱 Assign a Static IP Address

You can assign an IP manually for testing:

sudo ip addr add 192.168.1.50/24 dev eth0

Or remove it:

sudo ip addr del 192.168.1.50/24 dev eth0

These changes are temporary — they reset on reboot.
For permanent configuration, edit your distro’s network config file (e.g. /etc/netplan/*.yaml or /etc/network/interfaces).


🧠 View Network Interfaces

To list all interfaces:

ip link show

Typical interface names:

  • eth0, ens33 → Ethernet
  • wlan0 → Wi-Fi
  • lo → Loopback interface (127.0.0.1)
The loopback interface (lo) is how a Linux system communicates with itself — essential for testing local applications and services.

🌐 2. DNS: How Linux Resolves Names

Humans use names like example.com; computers use IPs like 93.184.216.34.
The Domain Name System (DNS) converts between the two.


🔍 How DNS Resolution Works in Linux

When you access a website:

  1. The system first checks /etc/hosts
  2. Then it consults the configured DNS servers in /etc/resolv.conf
  3. If still unresolved, it may consult caching services like systemd-resolved

📂 /etc/hosts File

This file maps hostnames to IPs manually — useful for local overrides.

Example:

127.0.0.1 localhost
192.168.1.5 webserver.local

Try pinging:

ping webserver.local


⚙️ /etc/resolv.conf File

Defines DNS servers for your system:

nameserver 8.8.8.8
nameserver 1.1.1.1

You can test DNS resolution:

dig google.com

or

nslookup linux.org

These commands show which DNS server was used and what IP address was returned.


🧰 Using systemd-resolve

Modern distributions (Ubuntu 20+, Debian 12+) use systemd-resolved for DNS management.

Check your DNS servers:

systemd-resolve --status

Flush DNS cache:

sudo systemd-resolve --flush-caches

💡 Tip: If websites fail to load but pinging IPs works, your DNS configuration is likely broken.

🚦 3. Routing: How Linux Sends Data

Routing determines where packets go once they leave your system.
Every Linux machine has a routing table that defines which interface to use for each network.


📋 View Routing Table

Use the ip route command:

ip route

Example 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.10

Here:

  • default via 192.168.1.1 → the default gateway (your router)
  • 192.168.1.0/24 → local network route
  • dev eth0 → interface used for that route

🧭 Add or Remove Routes

Add a new route:

sudo ip route add 10.0.0.0/24 via 192.168.1.1 dev eth0

Delete a route:

sudo ip route del 10.0.0.0/24


🧩 Set a Default Gateway

To manually set your main route:

sudo ip route add default via 192.168.1.1

Now, any traffic not destined for your local network goes through 192.168.1.1.


🧰 4. Essential Networking Commands for Troubleshooting

CommandPurposeExample
pingTest reachabilityping 8.8.8.8
tracerouteShow route hopstraceroute google.com
netstat or ssView active connectionsss -tuln
curlTest HTTP connectioncurl -I https://example.com
ifconfigLegacy interface commandifconfig -a
ipModern network command suiteip addr, ip route
nmcliNetworkManager CLInmcli device show

🔍 Example: Debugging Connectivity

  1. Check local IP:ip a
  2. Ping gateway:ping 192.168.1.1
  3. Check DNS:dig google.com
  4. Test routing path:traceroute 8.8.8.8
  5. Verify port availability:ss -tuln
If ping works but DNS fails → check /etc/resolv.conf.
If DNS works but websites fail → check firewall rules or default route.

🧱 5. Practical Example: Linux Server Connectivity

Let’s say you have a server with IP 192.168.1.10 that can’t reach the internet.
Here’s how you’d troubleshoot it step-by-step:

  1. Check interface statusip link show eth0
    → must be UP.
  2. Check IP addressip addr show eth0
    → must have a valid IP, like 192.168.1.10/24.
  3. Check default routeip route
    → should list default via 192.168.1.1.
  4. Ping the gatewayping 192.168.1.1
  5. Check DNSdig google.com
  6. If all else fails
    → Restart the network service:sudo systemctl restart NetworkManager
    orsudo systemctl restart networking

🧠 6. Bonus: Understanding the /etc/hosts and /etc/resolv.conf Priority

When you type ping server.local, Linux resolves names in this order:

  1. /etc/hosts
  2. /etc/resolv.conf
  3. Any caching resolver (like systemd-resolved)

This means you can override DNS names locally by adding entries to /etc/hosts.
It’s useful for testing websites before updating DNS globally.


🚀 7. Best Practices for Linux Networking

✅ Always verify IP, gateway, and DNS after reboot.
✅ Keep /etc/resolv.conf consistent — NetworkManager may overwrite it.
✅ Use ip instead of deprecated ifconfig.
✅ Log networking changes using journalctl -u NetworkManager.
✅ Test both IPv4 and IPv6 connectivity regularly.


🧭 Summary

Linux networking might seem complex, but once you understand its building blocks —
IP, DNS, and Routing — you gain the power to configure, debug, and automate network setups efficiently.

You now know how to:

  • Assign and view IP addresses
  • Configure DNS servers and test resolution
  • Inspect and edit routing tables
  • Diagnose connectivity step by step
Networking is the language Linux uses to speak to the world — and now, you speak it too. 🌐

🔗 Next Steps

Continue learning:

Or explore our full “Linux Networking Essentials” eBook on dargslan.com.