Use dnsmasq to support hosts pan-resolution and DNS acceleration

888u

Last update at :2024-07-07,Edit by888u

1. Installation yum install dnsmasq -y

2. Configuration 1. Make a backup copy of the configuration file first. cp /etc/dnsmasq.conf /etc/dnsmasq.conf_bak

2. The configuration of dnsmasq is described in detail in the configuration file. You can change the configuration you want by reading the comments in the configuration file. I just want to do general analysis, so my configuration is as follows: vim /etc/dnsmasq.conf # Perform DNS resolution strictly in the order in the resolv-file file from top to bottom until the first successful resolution is successful. strict-order

# Monitoring IP address listen-address=127.0.0.1

# Set cache size cache-size=10240

# Pan-domain name resolution, accessing any baidu.com domain name will be resolved to 6.6.6.6 address=/baidu.com/6.6.6.6 By default, domain name resolution reads the /etc/hosts file into the local domain name configuration file (pan-domain names are not supported)

DNS configuration reads the /etc/resolv.conf upstream DNS configuration file by default. If the address resolution of `/etc/hosts` cannot be read, it will be forwarded to resolv.conf for resolution of the address

DNS configuration file vim /etc/resolv.conf # These are commonly used DNS and can be configured in many ways. nameserver 127.0.0.1 # Must be placed first nameserver 8.8.8.8 nameserver 8.8.4.4 nameserver 1.1.1.1

3. Start the service systemctl enable –now dnsmasq

4. Test pingbaidu.com PING baidu.com (6.6.6.6) 56(84) bytes of data. ^C --- baidu.com ping statistics --- 2 packets transmitted, 0 received, 100% packet loss, time 1000ms

$ ping www.baidu.com PING www.baidu.com (6.6.6.6) 56(84) bytes of data. ^C --- www.baidu.com ping statistics --- 2 packets transmitted, 0 received, 100% packet loss, time 999ms

$ ping pan.baidu.com PING pan.baidu.com (6.6.6.6) 56(84) bytes of data. ^C --- pan.baidu.com ping statistics --- 2 packets transmitted, 0 received, 100% packet loss, time 999ms As can be seen from the above, almost any domain name accessed by baidu.com will be resolved to 6.6.6.6, which basically achieves our original purpose.

3. Caching (FQ has bonus) Another very useful function of dnsmasq is that it can cache the domain name that has been resolved. The next time you access this domain name, you can directly return the IP address without going through DNS query. This is for those who support the wall. In fact, it is a bit of optimization. It has been configured by default. We just need to demonstrate the effect of caching

1. Install the dig tool yum install bind-utils -y

2. Demonstration dig www.centos.com | grep "Query time" ;; Query time: 88 msec dig www.centos.com | grep "Query time" ;; Query time: 0 msec dig www.centos.com | grep "Query time" ;; Query time: 0 msec dig www.centos.com | grep "Query time" ;; Query time: 0 msec dig www.youtubi.com | grep "Query time" ;; Query time: 28 msec dig www.youtubi.com | grep "Query time" ;; Query time: 0 msec dig ** | grep "Query time" ;; Query time: 71 msec dig ** | grep "Query time" ;; Query time: 0 msec Looking at the comparison above, the query time has been reduced many times, which shows that the cache has taken effect.

Reprinted from: https://www.hostloc.com/thread-507674-1-1.html

Recommended site searches: Chinese domain name registration query, domain name registration query, Guangdong server rental, dual-line space, best US server, website agency registration, host server rental, Ministry of Industry and Information Technology domain name registration, application for free space and domain name, domain name purchase ,

Use dnsmasq to support hosts pan-resolution and DNS acceleration

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码