Understanding Linux Networking and DNS Resolution: A Complete Guide

 

Introduction

Networking is a fundamental aspect of Linux system administration and cloud computing. As a DevOps and Cloud Engineer, mastering Linux networking and DNS (Domain Name System) resolution is essential for managing servers, troubleshooting connectivity issues, and optimizing system performance.

In this guide, we’ll cover:
Basic Linux networking commands
How DNS resolution works in Linux
Common networking issues and troubleshooting techniques


1. Basics of Linux Networking

Linux networking is built on TCP/IP, which includes IP addresses, subnet masks, gateways, and DNS servers. Below are the key Linux commands used to manage and troubleshoot networks.

Checking Network Configuration (ip and ifconfig)

To view all network interfaces and IP addresses:

  • ip a → Displays all network interfaces, IP addresses, and MAC addresses.
  • ifconfig → Shows network details (older command, now replaced by ip).

To check only active network interfaces:

  • ip link show up

To find your system's default gateway (router):

  • ip route

Checking Internet Connectivity (ping)

To test if your server can reach an external website:

ping google.com
  • If successful, it shows response times in milliseconds.
  • If it fails, check your network settings or DNS configuration.

Checking Open Ports and Listening Services (netstat and ss)

To check which ports are currently open:

netstat -tulnp
  • -t → TCP connections
  • -u → UDP connections
  • -l → Listening ports
  • -n → Numeric IPs
  • -p → Show process names

Newer alternative using ss:

ss -tulnp

ss is faster and preferred in modern Linux systems.


Testing Network Routes (traceroute)

To see how your request reaches a destination:

traceroute google.com
  • This shows all network hops between your system and Google's servers.
  • If a connection fails, it helps pinpoint where the issue is.

If traceroute is not installed, install it with:

sudo apt install traceroute # Debian/Ubuntu sudo yum install traceroute # RHEL/CentOS


2. DNS Resolution in Linux

What is DNS Resolution?

DNS (Domain Name System) converts human-friendly domain names (e.g., google.com) into IP addresses (e.g., 142.250.64.78).

The DNS resolution process works as follows:

  1. The system checks the local DNS cache.
  2. If not found, it looks in /etc/hosts.
  3. If still unresolved, it queries the configured DNS servers in /etc/resolv.conf.
  4. The DNS servers respond with the IP address.

Checking Your System's DNS Configuration

To see your current DNS servers:

cat /etc/resolv.conf

Example output:

nameserver 8.8.8.8 nameserver 8.8.4.4

This means your system is using Google’s public DNS servers for name resolution.

If your system is using systemd-resolved, check the DNS configuration with:

systemd-resolve --status


Testing DNS Resolution (nslookup and dig)

To manually check a domain’s IP address:

nslookup google.com

Output example:

Server: 8.8.8.8 Address: 8.8.8.8#53 Non-authoritative answer: Name: google.com Address: 142.250.64.78

This shows that google.com resolves to 142.250.64.78 using Google’s DNS server.

A more advanced tool is dig (Domain Information Groper):

dig google.com

dig provides more detailed DNS query information, including TTL (Time To Live) and query times.


Flushing the DNS Cache

If you suspect DNS caching issues, you can flush the DNS cache to force a fresh lookup.

For systemd-resolved (modern Linux distros):

sudo systemd-resolve --flush-caches

For Ubuntu with dnsmasq:

sudo service dnsmasq restart

For Windows (if working with a dual setup):

ipconfig /flushdns


3. Troubleshooting Common Networking Issues

1️⃣ No Internet Connection?

✅ Check if your network interface is up:

ip link show

✅ Restart the network interface:

sudo systemctl restart NetworkManager


2️⃣ Unable to Resolve Domain Names?

✅ Check DNS configuration:

cat /etc/resolv.conf

✅ Manually test with Google’s DNS:

nslookup google.com 8.8.8.8

✅ Change your DNS settings to use Google’s or Cloudflare’s public DNS:

sudo nano /etc/resolv.conf

Replace existing entries with:

nameserver 8.8.8.8 nameserver 1.1.1.1

Save and exit (CTRL+X, then Y, then ENTER).


3️⃣ Network Port Blocked?


✅ Check firewall rules:

sudo iptables -L -n

✅ Temporarily disable the firewall to test:

sudo systemctl stop firewalld

✅ If using ufw (on Ubuntu):

sudo ufw status


Conclusion

Mastering Linux networking and DNS resolution is essential for DevOps engineers, system administrators, and cloud professionals.

📌 Key Takeaways:
✅ Use ip a to check network interfaces
✅ Use ping, traceroute, and netstat/ss for troubleshooting
✅ Understand how /etc/resolv.conf controls DNS resolution
✅ Use nslookup or dig to test domain name lookups
✅ Modify /etc/resolv.conf to change DNS settings
✅ Use firewall rules (iptables/ufw) to check blocked connections


💬 Call-to-Action (CTA):

💡 What are your biggest challenges in Linux networking? Drop a comment below!
📩 Subscribe for more DevOps & Cloud tutorials!

🚀 Next Blog Idea: "How to Set Up a Private DNS Server in Linux" – Stay tuned!



Comments

Popular posts from this blog

🔍 Why You Only See a Private IP Inside an AWS EC2 Instance — Even If It Has a Public IP

A Day in the Life of a DevOps Engineer – Roles & Responsibilities

Docker and Its Usage in DevOps – A Complete Guide