DNS caching in linux

前端 未结 4 1860
猫巷女王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:05

    Here are two other software packages which can be used for DNS caching on Linux:

    • dnsmasq
    • bind

    After configuring the software for DNS forwarding and caching, you then set the system's DNS resolver to 127.0.0.1 in /etc/resolv.conf.

    If your system is using NetworkManager you can either try using the dns=dnsmasq option in /etc/NetworkManager/NetworkManager.conf or you can change your connection settings to Automatic (Address Only) and then use a script in the /etc/NetworkManager/dispatcher.d directory to get the DHCP nameserver, set it as the DNS forwarding server in your DNS cache software and then trigger a configuration reload.

    0 讨论(0)
  • 2020-12-02 08:07

    Firefox contains a dns cache. To disable the DNS cache:

    1. Open your browser
    2. Type in about:config in the address bar
    3. Right click on the list of Properties and select New > Integer in the Context menu
    4. Enter 'network.dnsCacheExpiration' as the preference name and 0 as the integer value

    When disabled, Firefox will use the DNS cache provided by the OS.

    0 讨论(0)
  • 2020-12-02 08:10

    On Linux (and probably most Unix), there is no OS-level DNS caching unless nscd is installed and running. Even then, the DNS caching feature of nscd is disabled by default at least in Debian because it's broken. The practical upshot is that your linux system very very probably does not do any OS-level DNS caching.

    You could implement your own cache in your application (like they did for Squid, according to diegows's comment), but I would recommend against it. It's a lot of work, it's easy to get it wrong (nscd got it wrong!!!), it likely won't be as easily tunable as a dedicated DNS cache, and it duplicates functionality that already exists outside your application.

    If an end user using your software needs to have DNS caching because the DNS query load is large enough to be a problem or the RTT to the external DNS server is long enough to be a problem, they can install a caching DNS server such as Unbound on the same machine as your application, configured to cache responses and forward misses to the regular DNS resolvers.

    0 讨论(0)
  • 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}'
    
    0 讨论(0)
提交回复
热议问题