Difference between revisions of "DNS"
(→AWS) |
|||
Line 121: | Line 121: | ||
</source> | </source> | ||
= | == DNS Management in Ubuntu 24.04: systemd-resolved vs. resolvconf == | ||
On modern Ubuntu systems, including 24.04, <code>systemd-resolved</code> has become the primary service for managing DNS resolution. It replaces the legacy <code>resolvconf</code> framework as the default, offering a more robust and integrated solution. For advanced users, the key takeaway is the shift in tooling and configuration from the traditional <code>/etc/resolv.conf</code> file to the <code>resolvectl</code> command and its integration with systemd. | |||
=== The Modern Default: systemd-resolved === | |||
<code>systemd-resolved</code> acts as a local caching DNS stub resolver. It intercepts DNS queries from local applications and handles them intelligently, providing advanced features and better integration with modern network configurations. | |||
'''Core Function:''' Provides local DNS caching, DNSSEC validation, and Link-Local Multicast Name Resolution (LLMNR). | |||
'''How it Works:''' By default, <code>/etc/resolv.conf</code> is a symlink to a file managed by <code>systemd-resolved</code> (e.g., <code>/run/systemd/resolve/stub-resolv.conf</code>). This file typically points to the local stub resolver at <code>127.0.0.53</code>. Applications can also query <code>systemd-resolved</code> directly via D-Bus, bypassing <code>/etc/resolv.conf</code> entirely. | |||
'''Key Features:''' | |||
'''DNS Caching:''' Improves performance by caching previous lookups. | |||
'''DNSSEC:''' Validates DNS records to protect against spoofing. | |||
'''Per-Link Configuration:''' Intelligently handles DNS servers for multiple network interfaces (e.g., Ethernet, Wi-Fi, and a VPN connection simultaneously). | |||
'''Management:''' The primary tool for interacting with this service is <code>resolvectl</code>. You can use <code>resolvectl status</code> to view current DNS servers and <code>resolvectl query <domain></code> to test resolution. | |||
'''Integration:''' It integrates seamlessly with network management tools like Netplan and NetworkManager, which automatically feed it DNS server information received via DHCP or static configurations. | |||
=== The Legacy Framework: resolvconf === | |||
<code>resolvconf</code> is a script-based framework designed to manage the contents of <code>/etc/resolv.conf</code>. It acts as an intermediary, collecting DNS information from various sources and writing it to the configuration file. | |||
'''Core Function:''' To dynamically generate <code>/etc/resolv.conf</code> by aggregating DNS information from sources like DHCP clients, VPN software, and static network configurations. | |||
'''Status on Modern Ubuntu:''' While the <code>resolvconf</code> package may still be installed for compatibility with older software, it is no longer the default manager of DNS resolution. On a standard Ubuntu 24.04 installation, <code>systemd-resolved</code> handles its responsibilities. If both are present, <code>systemd-resolved</code> typically takes precedence. | |||
= References = | = References = | ||
*[https://en.wikipedia.org/wiki/List_of_DNS_record_types List of DNS record types] Wikipedia | *[https://en.wikipedia.org/wiki/List_of_DNS_record_types List of DNS record types] Wikipedia |
Latest revision as of 23:09, 26 August 2025
This is a source of general information about Domain Name System aka DNS.
The DNS server stores different types of resource records used to resolve names, records like:
- A - Address record - returns a 32-bit IPv4 address, most commonly used to map hostnames to an IP address of the host
- NS - Name server record - an authoritative name server, delegates a DNS zone to use the given authoritative name servers
- CNAME - Canonical name record - the canonical name (or Fully Qualified Domain Name) for an alias; Alias of one name to another: the DNS lookup will continue by retrying the lookup with the new name. Used when multiple services have the single network address, but each service has its own entry in DNS
- MX - mail exchange record; maps a domain name to a list of mail exchange servers (MTA) for that domain
- SRV - Service Locator, multi line record of form of eg in AWS
[priority] [weight] [port] [server host name]
, multiline must start with_
a new line delimiter - SOA - Start of [a zone of] authority record - Specifies authoritative information about a DNS zone, including the primary name server, the email of the domain administrator, the domain serial number, and several timers relating to refreshing the zone.
- PTR - Pointer record - pointer to a canonical name. Unlike a CNAME, DNS processing stops and just the name is returned. The most common use is for implementing reverse DNS lookups
The ipconfig /displaydns
command displays all of the cached DNS entries on a Windows computer system.
/etc/hosts
dig
(domain information groper) and nslookup
(query Internet name servers interactively) are tools that query name servers. Unless a specific name server is specified as a commandline argument they will query the name server(s) found in /etc/resolv.conf
. They simply don't look at alternative sources of host information such as the /etc/hosts
file or other sources specified in /etc/nsswitch.conf
.
To force all dns queries through dnsmasq on your host, the /etc/resolv.conf
there should point to dnsmasq, i.e. it should look like:
#/etc/resolv.conf on sun nameserver 127.0.0.1
Hosts file is part of Name Service Switch. Configured at
$ cat /etc/nsswitch.conf # /etc/nsswitch.conf # # Example configuration of GNU Name Service Switch functionality. # If you have the `glibc-doc-reference' and `info' packages installed, try: # `info libc "Name Service Switch"' for information about this file. passwd: compat systemd group: compat systemd shadow: compat gshadow: files hosts: files mdns4_minimal [NOTFOUND=return] dns myhostname networks: files protocols: db files services: db files ethers: db files rpc: db files
Example entries in /etc/hosts
10.10.11.11 echo-1.service.k8s.acme.cloud # via app-service LoadBalancer 10.10.22.22 k8s.acme.cloud echo-1.ingress.k8s.acme.cloud # via ingress-service (k8s entry point)
can be verified using getent
utility, to get entries from Name Service Switch libraries
$ getent hosts 10.10.11.11 10.10.11.11 echo-1.service.k8s.acme.cloud $ getent hosts echo-1.ingress.k8s.acme.cloud 10.10.22.22 k8s.acme.cloud echo-1.ingress.k8s.acme.cloud
flush dns
sudo systemctl is-active systemd-resolved.service # -> active # Ubuntu 18.04, 20.04 resolvectl statistics # show statistics, the same output as 'systemd-resolve --statistics' sudo systemd-resolve --statistics # or --reset-statistics - resets resolver statistics sudo systemd-resolve --flush-caches # Flush Ubuntu DNS Cache - Ubuntu <22.04 (old) resolvectl flush-caches # Flush Ubuntu DNS Cache - Ubuntu 22.04 sudo systemctl restart nscd # Other distros, eg arch Linux # Resolve a name without using local cache sudo systemd-resolve --flush-caches resolvectl flush-caches systemd-resolve --statistics | grep 'Current Cache Size' # -> Current Cache Size: 0 dig +short tvp.info @8.8.8.8 systemd-resolve --statistics | grep 'Current Cache Size' # -> Current Cache Size: 0 dig +short tvp.info systemd-resolve --statistics | grep 'Current Cache Size' # -> Current Cache Size: 1 # Display cached dns entries sudo killall -USR1 systemd-resolved # it doesn't stop the service, it tells systemd-resolved to write all the current cache entries to the system log journalctl -u systemd-resolved # list the cached entries from the log ## Oneliner sudo killall -USR1 systemd-resolved; journalctl -u systemd-resolved --since "5s ago"
Netplan
Netplan is the default network management tool on Ubuntu 18.04, replacing the /etc/resolv.conf and /etc/network/interfaces configuration files that have been used to configure the network in the previous Ubuntu versions.
Back in the days, whenever you wanted to configure DNS resolvers in Linux you would simply open the /etc/resolv.conf file, edit the entries, save the file and you are good to go. This file still exists but it is a symlink controlled by the systemd-resolved service and should not be edited manually.
Note: Info As of 18/05/2020 Network Manager doesn’t respect the Netplan option nameservers: addresses [8.8.8.8,8.8.4.4] option even when you specify dhcp4-overrides: use-dns: false it still uses (and give priority to) the default DHCP DNS servers. This renders any custom DNS servers redundant. The only way around this AFAIK is to specify the Ethernet connection as static.
sudo vi /etc/netplan/enp0s3.yaml network: version: 2 renderer: NetworkManager ethernets: enp0s3: dhcp4: false addresses: [192.168.1.114/24] gateway4: 192.168.1.1 nameservers: addresses: [8.8.8.8, 8.8.4.4] # Using this method you’ll lose the Network Manager GUI and network icon and let Netplan to manage all devices sudo netplan apply systemd-resolve --status | grep 'DNS Servers' -A2
DNS Management in Ubuntu 24.04: systemd-resolved vs. resolvconf
On modern Ubuntu systems, including 24.04, systemd-resolved
has become the primary service for managing DNS resolution. It replaces the legacy resolvconf
framework as the default, offering a more robust and integrated solution. For advanced users, the key takeaway is the shift in tooling and configuration from the traditional /etc/resolv.conf
file to the resolvectl
command and its integration with systemd.
The Modern Default: systemd-resolved
systemd-resolved
acts as a local caching DNS stub resolver. It intercepts DNS queries from local applications and handles them intelligently, providing advanced features and better integration with modern network configurations.
Core Function: Provides local DNS caching, DNSSEC validation, and Link-Local Multicast Name Resolution (LLMNR).
How it Works: By default, /etc/resolv.conf
is a symlink to a file managed by systemd-resolved
(e.g., /run/systemd/resolve/stub-resolv.conf
). This file typically points to the local stub resolver at 127.0.0.53
. Applications can also query systemd-resolved
directly via D-Bus, bypassing /etc/resolv.conf
entirely.
Key Features:
DNS Caching: Improves performance by caching previous lookups.
DNSSEC: Validates DNS records to protect against spoofing.
Per-Link Configuration: Intelligently handles DNS servers for multiple network interfaces (e.g., Ethernet, Wi-Fi, and a VPN connection simultaneously).
Management: The primary tool for interacting with this service is resolvectl
. You can use resolvectl status
to view current DNS servers and resolvectl query <domain>
to test resolution.
Integration: It integrates seamlessly with network management tools like Netplan and NetworkManager, which automatically feed it DNS server information received via DHCP or static configurations.
The Legacy Framework: resolvconf
resolvconf
is a script-based framework designed to manage the contents of /etc/resolv.conf
. It acts as an intermediary, collecting DNS information from various sources and writing it to the configuration file.
Core Function: To dynamically generate /etc/resolv.conf
by aggregating DNS information from sources like DHCP clients, VPN software, and static network configurations.
Status on Modern Ubuntu: While the resolvconf
package may still be installed for compatibility with older software, it is no longer the default manager of DNS resolution. On a standard Ubuntu 24.04 installation, systemd-resolved
handles its responsibilities. If both are present, systemd-resolved
typically takes precedence.
References
- List of DNS record types Wikipedia