type
status
date
slug
summary
tags
category
icon
password
URL
1、修改DNS配置:
方法一(临时修改,重启失效)
修改下面文件:vi /etc/resolv.conf加入想要修改的DNS:nameserver 1.1.1.1nameserver 8.8.8.8
如果多个DNS,就一行一个,修改之后保存退出即可;
此方法修改后即刻生效,但重启后失效
方法二(生成钩子阻止DHCP修改resolv.conf)
Debian/Ubuntu下生成nodnsupdate 文件:
nano /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate
按i 键粘贴以下代码后:wq 保存:
#!/bin/shmake_resolv_conf(){ :}
给文件nodnsupdate 添加可执行权限:
chmod +x /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate
重启系统,现在你就可以修改/etc/resolv.conf 文件而且不会担心被回滚了。
方法三(写保护锁定resolv.conf文件)
rm -f /etc/resolv.confeditor /etc/resolv.conf#填写上指定的DNS服务器:nameserver 1.1.1.1nameserver 1.0.0.1chattr +i /etc/resolv.conf
此时resolv.conf文件的内容就会被锁定不会被重启覆盖,想要解锁的话运行:
chattr -i /etc/resolv.conf
2、使修改的DNS 生效:
修改完保存了并不是立即生效的。输入下面命令使配置生效:
# 使网卡配置生效/etc/init.d/networking restart# 使DNS 生效/etc/init.d/resolvconf restart
查看是否已经生效:
systemd-resolve --status
如果已经变成了你设置的DNS,那就设置成功了。
3、nslookup解析命令:
安装nslookup:
#Ubuntuapt-get install dnsutils#Debianapt-get updateapt-get install dnsutils#Centosyum install bind-utils
使用方法:
nslookup www.baidu.com说明:nslookup 你需要解析的域名
示例:
root@ubuntu:~# nslookup www.baidu.comServer: 8.8.8.8Address: 8.8.8.8#53Non-authoritative answer:www.baidu.com canonical name = www.a.shifen.com.www.a.shifen .com canonical name = www.wshifen.com.Name: www.wshifen.comAddress: 104.193.88.77Name: www.wshifen.comAddress: 104.193.88.123