教你Linux 临时修改 / 永久修改VPS服务器的DNS
修改DNS配置
查看当前DNS配置:cat /etc/resolv.conf
方法一(临时修改,重启失效)
修改下面文件:
plain
vi /etc/resolv.conf
Plain textCopy
加入想要修改的DNS
plain
nameserver 8.8.8.8
nameserver 8.8.4.4
Plain textCopy
如果多个DNS
,就一行一个,修改之后保存退出即可;
此方法修改后即刻生效,但重启后失效!
方法二(永久修改,持续生效)
修改下面文件:
plain
vi /etc/network/interfaces
Plain textCopy
在文件最后加入:
plain
dns-nameservers 8.8.8.8
Plain textCopy
使修改的 DNS
生效
修改完保存了并不是立即生效的。输入下面命令使配置生效:
plain
# 使网卡配置生效
/etc/init.d/networking restart
# 使 DNS 生效
/etc/init.d/resolvconf restart
Plain textCopy
查看是否已经生效:
plain
cat /etc/resolv.conf
Plain textCopy
如果已经变成了你设置的DNS
,那就设置成功了。
nslookup
解析命令
安装nslookup
plain
#Ubuntu
apt-get install dnsutils
#Debian
apt-get update
apt-get install dnsutils
#Centos
yum install bind-utils
Plain textCopy
使用方法
plain
nslookup www.baidu.com
Plain textCopy
说明
plain
nslookup 你需要解析的域名
Plain textCopy
例:
plain
root@ubuntu:~# nslookup www.baidu.com
Server: 8.8.8.8
Address: 8.8.8.8#53
Non-authoritative answer:
www.baidu.com canonical name = www.a.shifen.com.
www.a.shifen.com canonical name = www.wshifen.com.
Name: www.wshifen.com
Address: 104.193.88.77
Name: www.wshifen.com
Address: 104.193.88.123