Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 23. Using different DNS servers for different domains
By default, Red Hat Enterprise Linux (RHEL) sends all DNS requests to the first DNS server specified in the /etc/resolv.conf file. If this server does not reply, RHEL tries the next server in this file until it finds a working one. In environments where one DNS server cannot resolve all domains, administrators can configure RHEL to send DNS requests for a specific domain to a selected DNS server.
For example, you connect a server to a Virtual Private Network (VPN), and hosts in the VPN use the example.com domain. In this case, you can configure RHEL to process DNS queries in the following way:
-
Send only DNS requests for
example.comto the DNS server in the VPN network. - Send all other requests to the DNS server that is configured in the connection profile with the default gateway.
23.1. Using dnsmasq in NetworkManager to send DNS requests for a specific domain to a selected DNS server Copier lienLien copié sur presse-papiers!
On hosts with multiple network interfaces and where one DNS server cannot resolve all domains, you can configure RHEL to send DNS requests for a specific domain to a selected DNS server.
You can configure NetworkManager to start an instance of dnsmasq. This DNS caching server then listens on port 53 on the loopback device. Consequently, this service is only reachable from the local system and not from the network.
With this configuration, NetworkManager adds the nameserver 127.0.0.1 entry to the /etc/resolv.conf file, and dnsmasq dynamically routes DNS requests to the corresponding DNS servers specified in the NetworkManager connection profiles.
Prerequisites
- The system has multiple NetworkManager connections configured.
A DNS server and search domain are configured for the connection that is responsible for resolving a specific domain.
For example, to ensure that the DNS server specified in a VPN connection resolves queries for the
example.comdomain, the following settings must be available:-
A DNS server that can resolve
example.com. A DHCP server can provide this information dynamically or you set theipv4.dnsandipv6.dnsparameters in the VPN connection profile. -
A search domain set to
example.com. A DHCP server can provide this information dynamically or you set theipv4.dns-searchandipv6.dns-searchparameters in the VPN connection profile.
-
A DNS server that can resolve
-
The
dnsmasqservice is not running or configured to listen on a different interface thanlocalhost.
Procedure
Install the
dnsmasqpackage:yum install dnsmasq
# yum install dnsmasqCopy to Clipboard Copied! Toggle word wrap Toggle overflow Edit the
/etc/NetworkManager/NetworkManager.conffile, and set the following entry in the[main]section:dns=dnsmasq
dns=dnsmasqCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the
NetworkManagerservice:systemctl reload NetworkManager
# systemctl reload NetworkManagerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Search in the
systemdjournal of theNetworkManagerunit for which domains the service uses a different DNS server:journalctl -xeu NetworkManager
# journalctl -xeu NetworkManager ... Jun 02 13:30:17 <client_hostname>_ dnsmasq[5298]: using nameserver 198.51.100.7#53 for domain example.com ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
tcpdumppacket sniffer to verify the correct route of DNS requests:Install the
tcpdumppackage:yum install tcpdump
# yum install tcpdumpCopy to Clipboard Copied! Toggle word wrap Toggle overflow On one terminal, start
tcpdumpto capture DNS traffic on all interfaces:tcpdump -i any port 53
# tcpdump -i any port 53Copy to Clipboard Copied! Toggle word wrap Toggle overflow On a different terminal, resolve host names for a domain for which an exception exists and another domain, for example:
host -t A www.example.com host -t A www.redhat.com
# host -t A www.example.com # host -t A www.redhat.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify in the
tcpdumpoutput that Red Hat Enterprise Linux sends only DNS queries for theexample.comdomain to the designated DNS server and through the corresponding interface:... 13:52:42.234533 IP server.43534 > 198.51.100.7.domain: 50121+ [1au] A? www.example.com. (33) ... 13:52:57.753235 IP server.40864 > 192.0.2.1.domain: 6906+ A? www.redhat.com. (33) ...
... 13:52:42.234533 IP server.43534 > 198.51.100.7.domain: 50121+ [1au] A? www.example.com. (33) ... 13:52:57.753235 IP server.40864 > 192.0.2.1.domain: 6906+ A? www.redhat.com. (33) ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Red Hat Enterprise Linux sends the DNS query for
www.example.comto the DNS server on198.51.100.7and the query forwww.redhat.comto192.0.2.1.
Troubleshooting
Verify that the
nameserverentry in the/etc/resolv.conffile refers to127.0.0.1:cat /etc/resolv.conf nameserver 127.0.0.1
# cat /etc/resolv.conf nameserver 127.0.0.1Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the entry is missing, check the
dnsparameter in the/etc/NetworkManager/NetworkManager.conffile.Verify that the
dnsmasqservice listens on port53on theloopbackdevice:ss -tulpn | grep "127.0.0.1:53"
# ss -tulpn | grep "127.0.0.1:53" udp UNCONN 0 0 127.0.0.1:53 0.0.0.0:* users:(("dnsmasq",pid=7340,fd=18)) tcp LISTEN 0 32 127.0.0.1:53 0.0.0.0:* users:(("dnsmasq",pid=7340,fd=19))Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the service does not listen on
127.0.0.1:53, check the journal entries of theNetworkManagerunit:journalctl -u NetworkManager
# journalctl -u NetworkManagerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
23.2. Using systemd-resolved in NetworkManager to send DNS requests for a specific domain to a selected DNS server Copier lienLien copié sur presse-papiers!
On hosts with multiple network interfaces and where one DNS server cannot resolve all domains, you can configure RHEL to send DNS requests for a specific domain to a selected DNS server.
You can configure NetworkManager to start an instance of systemd-resolved. This DNS stub resolver then listens on port 53 on IP address 127.0.0.53. Consequently, this stub resolver is only reachable from the local system and not from the network.
With this configuration, NetworkManager adds the nameserver 127.0.0.53 entry to the /etc/resolv.conf file, and systemd-resolved dynamically routes DNS requests to the corresponding DNS servers specified in the NetworkManager connection profiles.
The systemd-resolved service is provided as a Technology Preview only. Technology Preview features are not supported with Red Hat production Service Level Agreements (SLAs), might not be functionally complete, and Red Hat does not recommend using them for production. These previews provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
See Technology Preview Features Support Scope on the Red Hat Customer Portal for information about the support scope for Technology Preview features.
For a supported solution, see Using dnsmasq in NetworkManager to send DNS requests for a specific domain to a selected DNS server.
Prerequisites
- The system has multiple NetworkManager connections configured.
A DNS server and search domain are configured for the connection that is responsible for resolving a specific domain.
For example, to ensure that the DNS server specified in a VPN connection resolves queries for the
example.comdomain, the following settings must be available:-
A DNS server that can resolve
example.com. A DHCP server can provide this information dynamically or you set theipv4.dnsandipv6.dnsparameters in the VPN connection profile. -
A search domain set to
example.com. A DHCP server can provide this information dynamically or you set theipv4.dns-searchandipv6.dns-searchparameters in the VPN connection profile.
-
A DNS server that can resolve
Procedure
Install the
systemd-resolvedpackage:dnf install systemd-resolved
# dnf install systemd-resolvedCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable and start the
systemd-resolvedservice:systemctl --now enable systemd-resolved
# systemctl --now enable systemd-resolvedCopy to Clipboard Copied! Toggle word wrap Toggle overflow Edit the
/etc/NetworkManager/NetworkManager.conffile, and set the following entry in the[main]section:dns=systemd-resolved
dns=systemd-resolvedCopy to Clipboard Copied! Toggle word wrap Toggle overflow Reload the
NetworkManagerservice:systemctl reload NetworkManager
# systemctl reload NetworkManagerCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Display the DNS servers
systemd-resolveduses and for which domains the service uses a different DNS server:Copy to Clipboard Copied! Toggle word wrap Toggle overflow The output confirms that
systemd-resolveduses different DNS servers for theexample.comdomain.Use the
tcpdumppacket sniffer to verify the correct route of DNS requests:Install the
tcpdumppackage:yum install tcpdump
# yum install tcpdumpCopy to Clipboard Copied! Toggle word wrap Toggle overflow On one terminal, start
tcpdumpto capture DNS traffic on all interfaces:tcpdump -i any port 53
# tcpdump -i any port 53Copy to Clipboard Copied! Toggle word wrap Toggle overflow On a different terminal, resolve host names for a domain for which an exception exists and another domain, for example:
host -t A www.example.com host -t A www.redhat.com
# host -t A www.example.com # host -t A www.redhat.comCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify in the
tcpdumpoutput that Red Hat Enterprise Linux sends only DNS queries for theexample.comdomain to the designated DNS server and through the corresponding interface:... 13:52:42.234533 IP server.43534 > 198.51.100.7.domain: 50121+ [1au] A? www.example.com. (33) ... 13:52:57.753235 IP server.40864 > 192.0.2.1.domain: 6906+ A? www.redhat.com. (33) ...
... 13:52:42.234533 IP server.43534 > 198.51.100.7.domain: 50121+ [1au] A? www.example.com. (33) ... 13:52:57.753235 IP server.40864 > 192.0.2.1.domain: 6906+ A? www.redhat.com. (33) ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow Red Hat Enterprise Linux sends the DNS query for
www.example.comto the DNS server on198.51.100.7and the query forwww.redhat.comto192.0.2.1.
Troubleshooting
Verify that the
nameserverentry in the/etc/resolv.conffile refers to127.0.0.53:cat /etc/resolv.conf nameserver 127.0.0.53
# cat /etc/resolv.conf nameserver 127.0.0.53Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the entry is missing, check the
dnsparameter in the/etc/NetworkManager/NetworkManager.conffile.Verify that the
systemd-resolvedservice listens on port53on the local IP address127.0.0.53:ss -tulpn | grep "127.0.0.53"
# ss -tulpn | grep "127.0.0.53" udp UNCONN 0 0 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=1050,fd=12)) tcp LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* users:(("systemd-resolve",pid=1050,fd=13))Copy to Clipboard Copied! Toggle word wrap Toggle overflow If the service does not listen on
127.0.0.53:53, check if thesystemd-resolvedservice is running.