Linux如何查看和设置DNS服务器地址

查看DNS服务器地址

查看DNS配置文件,文件中的nameserver地址就是DNS服务器的地址。DNS配置文件的路径为:/etc/resolv.conf

[root@i-dbb1f0ff network-scripts]# cat /etc/resolv.conf; 
generated by /usr/sbin/dhclient-script
nameserver 192.20.1.1
nameserver 192.20.1.1

设置DNS服务器地址

1.使用ifconfig命令查看网卡信息,确认网卡名。

[root@i-dbb1f0ff network-scripts]# ifconfig
eth0: flags=4163  mtu 1500
        inet 10.105.184.195  netmask 255.255.255.0  broadcast 10.105.184.255
        inet6 fe80::d20d:dbff:feb1:f0ff  prefixlen 64  scopeid 0x20
        ether d0:0d:db:b1:f0:ff  txqueuelen 1000  (Ethernet)
        RX packets 197079202  bytes 21761671766 (20.2 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13200691  bytes 7533972013 (7.0 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1  (Local Loopback)
        RX packets 3365044  bytes 1208000880 (1.1 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3365044  bytes 1208000880 (1.1 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2.将DNS服务器地址配置到网卡配置文件中。网卡配置文件路径:/etc/sysconfig/network-scripts/ifcfg-eth0

[root@i-dbb1f0ff network-scripts]# vi ifcfg-eth0
TYPE=Ethernet
BOOTPROTO=dhcp
DEVICE=eth0
ONBOOT=yes
DNS1="192.168.1.2"

3.设置完以后必须使用service network restart命令重启网卡服务才能生效,注意配置的DNS服务器地址必须要能连上才行。

# vi ifcfg-eth0
[root@i-dbb1f0ff network-scripts]# service network restart
正在关闭接口eth0:
关闭环回接口:
弹出界面eth0:

你可能感兴趣的:(Linux)