当前位置:网站首页>Deploy DNS server using dnsmasq

Deploy DNS server using dnsmasq

2022-06-24 06:34:00 zero000

brief introduction

dnsmasq It is often used for simple deployment DNS The server and DHCP The server , Here's how to use dnsmasq Deploy a simple DNS The server

install dnsamsq

Reference resources here

To configure dnsmasq

sudo vi /etc/dnsmasq.conf
domain-needed
bogus-priv
no-resolv          
server=8.8.8.8    # forward  Server for 
server=8.8.4.4    # forward  Server for 
local=/mydomain.org/ # mydomain.org  Use local resolution , Don't make forward
listen-address=::1,127.0.0.1,192.168.1.10 #  Bind the specified network interface 
expand-hosts      #  Use the following domain Automatic completion of domain name resolution , for example /etc/hosts  Configured with  "test 127.0.0.1" ,  At this time, the client queries  "dig test.mydomain.org"  The corresponding resolution can be obtained 

#  below  DHCP  relevant ,domain  Above field  DNS  Configuration will use 
domain=mydomain.org
dhcp-range=192.168.1.100,192.168.1.200,24h
dhcp-option=option:router,192.168.1.1
dhcp-authoritative
dhcp-leasefile=/var/lib/dnsmasq/dnsmasq.leases

Add records

Use it directly /etc/hosts Records of are used as dns analysis

sudo vi /etc/hosts

Add the following record

127.0.0.1   localhost localhost.localdomain
::1         localhost localhost.localdomain
192.168.1.1    router
192.168.1.10   dnsmasq
192.168.1.20   server1
192.168.1.30   server2

start-up dnsamsq

sudo systemctl restart dnsmasq

test

Forward parsing test

$ nslookup server1
Server:       127.0.0.1
Address:      127.0.0.1#53
Name:         server1.mydomain.org
Address:      192.168.1.20

Reverse test

$ nslookup 192.168.1.20
20.1.168.192.in-addr.arpa    name = server1.mydomain.org.

Test external domain name resolution

$ nslookup fedoramagazine.org
Server:       127.0.0.1
Address:      127.0.0.1#53
Non-authoritative answer:
Name:    fedoramagazine.org
Address: 35.196.109.67

Realization DNS Round Robin

Query some historical data ,dnsmasq It doesn't support DNS Round Robin Of , But subsequent versions seem to have supported this feature

The key is addn-hosts This configuration

Take the configuration just now as an example , Add the following configuration

domain-needed
bogus-priv
no-resolv          
server=8.8.8.8    # forward  Server for 
server=8.8.4.4    # forward  Server for 
local=/mydomain.org/ # mydomain.org  Use local resolution , Don't make forward
listen-address=::1,127.0.0.1,192.168.1.10 #  Bind the specified network interface 
expand-hosts      #  Use the following domain Automatic completion of domain name resolution , for example /etc/hosts  Configured with  "test 127.0.0.1" ,  At this time, the client queries  "dig test.mydomain.org"  The corresponding resolution can be obtained 

....

addn-hosts=/etc/dnsmasq.addn-hosts/

Create the corresponding file , Store domain name A Parsing records

$ mkdir -p /etc/dnsmasq.addn-hosts/

$ vi /etc/dnsmasq.addn-hosts/test.domain

#  Be careful , You need to add  FQDN(Fully Qualified Domain Name)  domain name 
192.168.1.30   server2.test.com
192.168.1.31   server2.test.com
192.168.1.32   server2.test.com

The last restart dnsamsq

sudo systemctl restart dnsmasq

Now , Test record

$ dig server2.test.com +short
192.168.1.30
192.168.1.31
192.168.1.32

Reference resources :

  1. https://fedoramagazine.org/dnsmasq-provide-dns-dhcp-services/
原网站

版权声明
本文为[zero000]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/07/20210714191125408L.html