Q. How do I change DNS search order in Linux? In order to improve performance I need to make changes.
A. Under Linux you need to use /etc/nsswitch.conf file which is used by system databases and Name Service Switch configuration file
Various functions in the C Library need to be configured to work correctly in the local environment. Tradition ally, this was done by using files (e.g., ‘/etc/passwd’), but other nameservices (like the Network Information Service (NIS) and the Domain Name Service (DNS)) became popular, and were hacked into the C library, usually with a fixed search order.
Step # 1: /etc/nsswitch.conf
Open /etc/nsswitch.conf file using text editor:
# vi /etc/nsswitch.conf
Look for hosts:
hosts: files dns mdns4
Set above order as per your requirement. Close and save the file.
host.conf – resolver configuration file
The file /etc/host.conf contains configuration information specific to the resolver library. It should contain one configuration keyword per line, followed by appropriate configuration information.
Open /etc/host.conf file
# vi /etc/host.conf
Find order line which specifies how host lookups are to be performed. It should be followed by one or more lookup methods, separated by commas. Valid methods are bind (dns server), hosts (/etc/hosts file), and nis (old method).
Save and close the file.
See the nsswitch.conf and host.conf man pages for details.
|Category||List of Unix and Linux commands|
|Firewall||CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04|
|Network Utilities||dig • host • ip • nmap|
|OpenVPN||CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04|
|Package Manager||apk • apt|
|Processes Management||bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time|
|Searching||grep • whereis • which|
|User Information||groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w|
|WireGuard VPN||CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04|