另外,也是因為處理了這個問題,我才發現原來 DNS 也是有緩存的。Nscd caches libc-issued requests to the Name Service. If retrieving NSS data is fairly expensive, nscd is able to speed up consecutive access to the same data dramatically and increase overall system performance. 也因此,如果修改了 resolv.conf 的話,記得要叫 nscd 做一下重新載入。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# getaddrinfo() | |
[root@cnc-cq-113-207-030-156 tmp]# python -c 'import socket;print socket.getaddrinfo("opsmeta.owlemon.com","http")[0][4][0]' | |
112.121.87.202 | |
# gethostbyname() | |
[root@cnc-cq-113-207-030-156 tmp]# python -c 'import socket;print socket.gethostbyname("opsmeta.owlemon.com")' | |
112.121.87.201 | |
# After calling nscd(name service cache daemon) to reload /etc/hosts /etc/resolv.conf, | |
# getaddrinfo() and gethostbyname() have the same output | |
[root@cnc-cq-113-207-030-156 ~]# service nscd reload | |
Reloading nscd: | |
[root@cnc-cq-113-207-030-156 ~]# python -c 'import socket;print socket.getaddrinfo("opsmeta.owlemon.com","http")[0][4][0]' | |
112.121.87.201 | |
[root@cnc-cq-113-207-030-156 ~]# python -c 'import socket;print socket.gethostbyname("opsmeta.owlemon.com")' | |
112.121.87.201 |