DNS and Hosts Resolution
====================================================================================
DNS and Hosts Testing
------------------------------------------------------------------------------------------------------------------------------------------------
dig domainname
dig from a specific DNS server
dig domainname @DNS_ServerIP
====================================================================================
DNS and Host Resolution
------------------------------------------------------------------------------------------------------------------------------------------------
/etc/resolv.conf
The /etc/resolv.conf file is used to configure DNS server that your server will use for DNS lookups.
Important Note; The below documentation is related to the /etc/resolve.conf file. This is not the primary file that Linux machines will use for the resolution configuration. Instead, this file is symlinked to /run/systemd/resolve/stub-resolve.conf which is referenced by systemd-resolvd. The primary configuration file used by systemd-resolvd is /run/systemd/resolve/resolve.conf, but stub-resolv.conf is also referenced. TLDR; /etc/resolve.conf is still used, but it's not the primary place referenced by systemd-resolvd.
root@test:~# ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Aug 10 2023 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
The systemd-resolved service listens on port 53 locally: this port needs to be open in order for DNS resolution to function.
root@test:~# lsof -i:53
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 127318 systemd-resolve 13u IPv4 1028696 0t0 UDP localhost:domain
systemd-r 127318 systemd-resolve 14u IPv4 1028697 0t0 TCP localhost:domain (LISTEN)
/etc/Resolve.conf config:
Below is a typical default configuration you might see on a Linux system:
# This file configures your system's DNS resolution.
nameserver 127.0.0.53 # Local DNS server (systemd-resolved)
options edns0 trust-ad # Enables EDNS for performance
search b4sed.xyz # Search domain to append to incomplete names
nameserver - specifies where the system looks for DNS resolution
search - This is the default search domain. For example, if a lookup is made to google, this option would append .b4sed.xyz to the end: google.b4sed.xyz
options:
edns0 - enables a potentially performance-enhancing feature.
trust-ad - instructs your resolver to accept and potentially use the information in the Additional Records section without further verification.
View current DNS configuration:
resolvectl status
------------------------------------------------------------------------------------------------------------------------------------------------
/etc/hosts
The /etc/hosts file can be thought of as essentially a local DNS configuration. This means that DNS entries can be mapped here, overwriting any DNS entries provided by an external service.
Entries into the /etc/hosts file can be formatted as follows:
IP domainname
------------------------------------------------------------------------------------------------------------------------------------------------
No Comments