前言
在Linux系統裏查詢DNS使用如下命令
dig baidu.com @114.114.114.114
或者使用系統默認的DNS服務器查詢
nslookup baidu.com
下文中的方法不一定全管用,但你總能找到管用的一個
1.network-manager and networking
在一些Linux操作系統裏,如ubuntu的特定版本,DNS是由network-manager這個系統服務管理的。 在這些系統裏,需要運行命令:
sudo service network-manager restart
在其他系統中可以使用命令:
sudo service networking restart
2.ubuntu
在Ubuntu12.04中可以嘗試如下命令:
sudo kill -HUP $(pgrep dnsmasq)
在Ubuntu 16.04和debian 9中,你可以使用如下命令刷新DNS
sudo systemd-resolve statistics
在Ubuntu17.04和更高版本上,使用如下命令:
sudo systemd-resolve flush-caches
3 /etc/resolv.conf
/etc/resolv.conf這個文件裏存放的是DNS服務器的地址,直接修改這個文件只能暫時改變默認DNS的地址,重啟後恢複設置。 你可以直接修改這個文件用來臨時使用:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
修改完成後重新ping或者nslookup就會從新的DNS服務器那裏得到IP地址 永久修改的方法見:How do I add a DNS server via resolv.conf?
4.nscd
nscd是一個很好用的DNS緩存服務,使用如下命令安裝:
apt install nscd #debian ubuntu
如果你的Linux系統安裝了nscd ,那麼可以使用如下命令刷新DNS:
sudo /etc/init.d/nscd restart
參考資料: How do I clear the DNS cache? Flush DNS Cache in Ubuntu