DNS caching in linux

前端 未结 4 1889
猫巷女王i
猫巷女王i 2020-12-02 07:51

I am confused about DNS caching. I am writing a small forward proxy server and want to use OS DNS cache on a Linux system.

If I understand correctly, then there is D

4条回答
  •  长情又很酷
    2020-12-02 08:15

    You have here available an example of DNS Caching in Debian using dnsmasq.

    Configuration summary:

    /etc/default/dnsmasq

    # Ensure you add this line
    DNSMASQ_OPTS="-r /etc/resolv.dnsmasq"
    

    /etc/resolv.dnsmasq

    # Your preferred servers
    nameserver 1.1.1.1
    nameserver 8.8.8.8
    nameserver 2001:4860:4860::8888
    

    /etc/resolv.conf

    nameserver 127.0.0.1
    

    Then just restart dnsmasq.

    Benchmark test using DNS 1.1.1.1:

    for i in {1..100}; do time dig slashdot.org @1.1.1.1; done 2>&1 | grep ^real | sed -e s/.*m// | awk '{sum += $1} END {print sum / NR}'
    

    Benchmark test using you local cached DNS:

    for i in {1..100}; do time dig slashdot.org; done 2>&1 | grep ^real | sed -e s/.*m// | awk '{sum += $1} END {print sum / NR}'
    

提交回复
热议问题