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.
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:
- IP addressing – how Linux identifies and communicates with other systems.
- DNS – how human-readable names (like
google.com) are resolved into IP addresses. - 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 eth0
inet 192.168.1.10/24 brd 192.168.1.255 scope global inet6 fe80::20c:29ff:fe12:3456/64 scope link
Here:
eth0→ your network interface192.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→ Ethernetwlan0→ Wi-Filo→ 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:
- The system first checks
/etc/hosts - Then it consults the configured DNS servers in
/etc/resolv.conf - 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 localhost192.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 routedev 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
| Command | Purpose | Example |
|---|---|---|
ping | Test reachability | ping 8.8.8.8 |
traceroute | Show route hops | traceroute google.com |
netstat or ss | View active connections | ss -tuln |
curl | Test HTTP connection | curl -I https://example.com |
ifconfig | Legacy interface command | ifconfig -a |
ip | Modern network command suite | ip addr, ip route |
nmcli | NetworkManager CLI | nmcli device show |
🔍 Example: Debugging Connectivity
- Check local IP:ip a
- Ping gateway:ping 192.168.1.1
- Check DNS:dig google.com
- Test routing path:traceroute 8.8.8.8
- 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:
- Check interface status
ip linkshow eth0
→ must be UP. - Check IP addressip addr show eth0
→ must have a valid IP, like192.168.1.10/24. - Check default routeip route
→ should listdefault via 192.168.1.1. - Ping the gatewayping 192.168.1.1
- Check DNSdig google.com
- 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:
/etc/hosts/etc/resolv.conf- 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:
- Firewall Configuration with UFW and iptables
- How to Secure SSH Access on Your Linux Server
- Monitoring System Performance with top, htop, and iostat
Or explore our full “Linux Networking Essentials” eBook on dargslan.com.