• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Configure dnsmasq to use different DNS Servers for some Domains (CentOS/RHEL)

by admin

By default, the operating system uses the dns servers configured in /etc/resolv.conf and for each lookup it will ask the same set of dns servers. It is possible to configure dnsmasq to use different dns servers for specific domains.

When looking for entries in xyz.com dnsmasq should ask dns server 192.168.1.1, and when using abc.com, it should ask dns server 192.168.100.1.

1. Install dnsmasq:

# yum install dnsmasq

2. Enable it to start at boot:

# systemctl start dnsmasq

3. Take a backup of the original configuration:

# cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

4. Adjust the default configuration:

# vi /etc/dnsmasq.conf

and set the following basics:

listen-address=::1,127.0.0.1,[your nics ip]
interface=[your nic, eg eth0 and lo]
expand-hosts
domain=[your default domain name]

Then configure xyz.com and abc.com:

server=/xyz.com/192.168.1.1
server=/1.168.192.in-addr.arpa/192.168.1.1

server=/abc.com/192.168.100.1
server=/100.168.192.in-addr.arpa/192.168.100.1

and set the default dns server:

server=169.254.169.254

so all lookups for xyz.com and the reverse lookups 1.168.192.in-addr.arpa go to 192.168.1.1, while abc.com and the reverse lookups go to 192.168.100.1. All other lookups go to 169.254.169.254.

5. Then start dnsmasq:

# systemctl start dnsmasq

6. Replace the current nameserver in /etc/resolv.conf with 127.0.0.1 (dnsmasq is listening there):

# vi /etc/resolv.conf
search [your default domain].com abc.com xvz.com
nameserver 127.0.0.1

Filed Under: CentOS/RHEL, CentOS/RHEL 6, CentOS/RHEL 7, CentOS/RHEL 8, Linux

Some more articles you might also be interested in …

  1. rsync: command not found
  2. numactl: command not found
  3. ulimit: command not found
  4. How to use ldconfig Command in Linux
  5. nslookup Command Examples in Linux
  6. chattr: command not found
  7. How to Disable “alt+ctrl+Del” Key Combination causing reboot in CentOS/RHEL 4,5
  8. Linux OS Service ‘network’
  9. cpufreq-aperf Command Examples in Linux
  10. How To Auto Mount a FileSystem Using Systemd

You May Also Like

Primary Sidebar

Recent Posts

  • protonvpn-cli Command Examples in Linux
  • protonvpn-cli connect Command Examples
  • procs Command Examples in Linux
  • prlimit: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright