DNS configuration and network testing

4.4 Your Computer on the Network (Weight: 2)

📘Linux Essentials (LPI 010-160)


1. What is DNS?

DNS (Domain Name System) is a service that translates domain names into IP addresses.

Computers communicate using IP addresses, but humans prefer to use names. DNS acts as a directory that converts names into addresses.

Example in an IT environment:

  • A system administrator connects to a server using the hostname fileserver.company.local
  • The system uses DNS to convert this hostname into an IP address such as 192.168.10.25

Without DNS, administrators would need to remember the IP address of every server.


2. How DNS Works

When a Linux system needs to access a remote system using a hostname, the following process happens:

  1. The user enters a hostname (for example, a web server name).
  2. The system checks local configuration files.
  3. If the address is not found locally, the system queries a DNS server.
  4. The DNS server returns the correct IP address.
  5. The system connects using that IP address.

Example:

A user runs a command to connect to a server:

ssh backupserver.company.local

The system first resolves backupserver.company.local into its IP address through DNS.


3. Local Name Resolution Files

Linux systems can resolve hostnames locally using configuration files.

The two most important files are:

  • /etc/hosts
  • /etc/resolv.conf

3.1 The /etc/hosts File

The /etc/hosts file is a local hostname database.

It allows administrators to manually define hostname-to-IP mappings.

Example:

127.0.0.1     localhost
192.168.1.20 fileserver
192.168.1.21 backupserver

Meaning:

IP AddressHostname
127.0.0.1localhost
192.168.1.20fileserver
192.168.1.21backupserver

When the system looks up fileserver, it finds the IP address directly in this file.

When /etc/hosts is used

This file is useful in IT environments when:

  • Testing new servers before DNS is configured
  • Creating temporary hostname mappings
  • Working in isolated networks without DNS

However, this file must be manually maintained.


3.2 The /etc/resolv.conf File

The /etc/resolv.conf file defines which DNS servers the system should use.

Example configuration:

nameserver 8.8.8.8
nameserver 1.1.1.1
search company.local

Explanation:

DirectiveMeaning
nameserverSpecifies a DNS server
searchDefines a domain search suffix

Example usage:

If a user types:

ssh fileserver

The system automatically tries:

fileserver.company.local

because of the search domain configuration.


4. Name Service Switch Configuration

Linux determines how to resolve hostnames using the file:

/etc/nsswitch.conf

Example configuration:

hosts: files dns

Meaning:

  1. First check local files (/etc/hosts)
  2. If not found, query DNS servers

Other sources may include:

SourceDescription
files/etc/hosts
dnsDNS servers
mdnsmulticast DNS

This file controls the order of name resolution.


5. DNS Lookup Utilities

Linux provides commands to manually query DNS servers.

These tools help administrators verify DNS configuration.


5.1 The host Command

The host command performs DNS lookups.

Example:

host example.com

Output:

example.com has address 93.184.216.34

This confirms that DNS is working and returns the IP address.

Another example:

host 8.8.8.8

This performs a reverse lookup, converting an IP address back to a hostname.


5.2 The dig Command

The dig (Domain Information Groper) command provides detailed DNS information.

Example:

dig example.com

Typical output includes:

  • DNS server used
  • IP addresses
  • Query time
  • DNS record types

Important information shown:

FieldDescription
QUESTION SECTIONThe query being asked
ANSWER SECTIONThe DNS response
Query timeTime needed to complete lookup

Example answer:

example.com.   300   IN   A   93.184.216.34

Meaning:

FieldMeaning
example.comDomain
300TTL (time to live)
INInternet class
AIPv4 address record
93.184.216.34IP address

5.3 The nslookup Command

The nslookup command is another DNS query tool.

Example:

nslookup example.com

Output shows:

  • DNS server used
  • IP address returned

Example:

Server: 8.8.8.8
Address: 8.8.8.8#53Name: example.com
Address: 93.184.216.34

Although still used, dig is generally preferred by administrators.


6. Network Testing Commands

Network testing commands help verify whether systems can communicate across the network.

Common Linux testing tools include:

  • ping
  • traceroute
  • tracepath
  • ss
  • netstat

6.1 The ping Command

The ping command tests network connectivity between two systems.

Example:

ping example.com

Ping sends ICMP echo request packets and waits for responses.

Example output:

64 bytes from 93.184.216.34: icmp_seq=1 ttl=57 time=10 ms

Explanation:

FieldMeaning
icmp_seqPacket sequence number
ttlTime to live
timeResponse time

Stopping ping:

Ctrl + C

Ping summary:

4 packets transmitted, 4 received, 0% packet loss

Packet loss indicates network problems.


6.2 The traceroute Command

The traceroute command shows the path packets take to reach a destination.

Example:

traceroute example.com

Output example:

1 192.168.1.1
2 10.10.1.1
3 203.0.113.5
4 example.com

Each line represents a network hop.

This helps administrators identify where network delays or failures occur.


6.3 The tracepath Command

tracepath is similar to traceroute but simpler and often installed by default.

Example:

tracepath example.com

It shows:

  • network path
  • MTU size
  • hop information

6.4 The ss Command

The ss (socket statistics) command displays network connections.

Example:

ss -t

Shows TCP connections.

Example:

ss -l

Shows listening ports.

Example:

ss -tuln

Displays:

  • TCP
  • UDP
  • listening ports
  • numeric addresses

This helps administrators verify which services are accepting connections.


6.5 The netstat Command

The netstat command also displays network connections.

Example:

netstat -tuln

Shows:

  • open ports
  • listening services
  • active connections

However, ss is the modern replacement.


7. Testing DNS Resolution

Administrators often perform DNS tests in the following order.

Step 1 — Test IP connectivity

ping 8.8.8.8

If this works, the network connection is functioning.


Step 2 — Test DNS resolution

ping google.com

If the hostname does not resolve, DNS configuration may be incorrect.


Step 3 — Query DNS server

dig google.com

or

host google.com

This confirms whether DNS servers are responding.


8. Common DNS Troubleshooting Checks

Administrators typically verify:

DNS server configuration

Check:

/etc/resolv.conf

Make sure valid nameservers are listed.


Local host entries

Check:

/etc/hosts

Ensure no incorrect mappings exist.


Name resolution order

Check:

/etc/nsswitch.conf

Confirm that DNS is included in the hosts line.


Connectivity to DNS server

Test using:

ping DNS_server_IP

9. Key Points for the LPI Linux Essentials Exam

Students should understand the following concepts:

DNS configuration files

  • /etc/hosts
  • /etc/resolv.conf
  • /etc/nsswitch.conf

DNS lookup tools

  • host
  • dig
  • nslookup

Network testing commands

  • ping
  • traceroute
  • tracepath
  • ss
  • netstat

Important skills

Students should be able to:

  • Verify DNS configuration
  • Test hostname resolution
  • Check network connectivity
  • Identify network routes
  • Inspect open ports and connections

10. Summary

DNS allows Linux systems to translate hostnames into IP addresses so systems can communicate across networks. DNS configuration in Linux mainly involves /etc/hosts, /etc/resolv.conf, and /etc/nsswitch.conf.

Administrators use tools like dig, host, and nslookup to test DNS resolution. They use commands such as ping, traceroute, and ss to verify network connectivity and diagnose problems.

Understanding these commands and configuration files is essential for managing Linux systems and troubleshooting network issues.

Buy Me a Coffee