Centos7修改dns的三种方法

我用的第三种方法,简单
一、直接修改文件/etc/sysconfig/network-scripts/ifcfg-***#

[root@localhost ~]# nmcli connection show
NAME   UUID                                  TYPE      DEVICE 
ens33  3cf08c0d-624f-42f0-9e2f-93c06700c0d1  ethernet  ens33  
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=3cf08c0d-624f-42f0-9e2f-93c06700c0d1
DEVICE=ens33
ONBOOT=yes
IPADDR=10.10.10.10
PREFIX=24
GATEWAY=10.10.10.1
DNS1=1.2.4.8
DNS2=1.1.1.1
IPV6_PRIVACY=no

二、nmcli命令修改

[root@localhost ~]# nmcli connection show
NAME   UUID                                  TYPE      DEVICE 
ens33  3cf08c0d-624f-42f0-9e2f-93c06700c0d1  ethernet  ens33  
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=3cf08c0d-624f-42f0-9e2f-93c06700c0d1
DEVICE=ens33
ONBOOT=yes
IPADDR=10.10.10.10
PREFIX=24
GATEWAY=10.10.10.1
DNS1=1.2.4.8
DNS2=1.1.1.1
IPV6_PRIVACY=no
[root@localhost ~]# nmcli connection modify ens33 ipv4.dns "114.114.114.114 8.8.8.8"
[root@localhost ~]# nmcli connection up ens33 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4)
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=3cf08c0d-624f-42f0-9e2f-93c06700c0d1
DEVICE=ens33
ONBOOT=yes
IPADDR=10.10.10.10
PREFIX=24
GATEWAY=10.10.10.1
DNS1=114.114.114.114
DNS2=8.8.8.8
IPV6_PRIVACY=no

三、修改/etc/resolv.conf文件#

[root@localhost ~]# vim /etc/NetworkManager/NetworkManager.conf
修改或添加dns=none
[main]
#plugins=ifcfg-rh,ibft
dns=none
保存后重启服务
[root@localhost ~]# systemctl restart NetworkManager.service
然后修改/etc/resolv.conf文件
[root@localhost ~]# vim /etc/resolv.conf
# Generated by NetworkManager
nameserver 114.114.114.114
nameserver 8.8.8.8
修改后保持即可

转载自:https://www.cnblogs.com/alusss/p/12631133.html

你可能感兴趣的:(chrome,前端)