CentOS配置DNS方法

2021-10-22 10:14:28 字數 3011 閱讀 4043

yum安裝軟體出現無法安裝,排查網路配置確認是否能訪問外網,首先ping 8.8.8.8確認可以訪問網路,然後ping www.baidu.com確認是否配置dns解析**;

如果出現可以ping通ip,但是無法訪問**的情況,說明dns解析有問題,需要排查配置;

[root@localhost etc]# ping mirrors.tuna.tsinghua.edu.cn

ping: mirrors.tuna.tsinghua.edu.cn: name or service not known

[root@localhost ~]# ping mirrors.tuna.tsinghua.edu.cn

ping cdnmirrors.s.tuna.tsinghua.edu.cn (101.6.8.193) 56(84) bytes of data.

64 bytes from 101.6.8.193 (101.6.8.193): icmp_seq=1 ttl=239 time=43.1 ms

64 bytes from 101.6.8.193 (101.6.8.193): icmp_seq=2 ttl=239 time=45.0 ms

一、直接修改檔案/etc/sysconfig/network-scripts/ifcfg-***

[root@localhost ~]# nmcli connection show 檢視配置的網口名稱

name uuid type device

enp0s31f6 4e827d4e-04d0-4113-849e-1647c693080b 802-3-ethernet enp0s31f6

[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s31f6

type=ethernet

bootproto=none

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=enp0s31f6

uuid=4e827d4e-04d0-4113-849e-1647c693080b

device=enp0s31f6

onboot=yes

ipaddr=192.169.8.199

prefix=24

gateway=192.169.8.254

dns1=114.114.114.114

dns2=8.8.8.8

ipv6_peerdns=yes

ipv6_peerroutes=yes

二、nmcli命令修改

[root@localhost etc]# nmcli connection modify enp0s31f6 ipv4.dns 「114.114.114.114 8.8.8.8」

[root@localhost etc]# nmcli connection up enp0s31f6

connection successfully activated (d-bus active path: /org/freedesktop/networkmanager/activeconnection/4451)

[root@localhost etc]#

[root@localhost etc]#

[root@localhost etc]# cat /etc/sysconfig/network-scripts/ifcfg-enp0s31f6

type=ethernet

bootproto=none

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=enp0s31f6

uuid=4e827d4e-04d0-4113-849e-1647c693080b

device=enp0s31f6

onboot=yes

ipaddr=192.169.8.199

prefix=24

gateway=192.169.8.254

dns1=114.114.114.114

dns2=8.8.8.8

ipv6_peerdns=yes

ipv6_peerroutes=yes

三、修改/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

修改後保持即可

談談CentOS 上的DNS配置

這裡看到很多朋友都分享了自己在centos redhat 上安裝配置dns的文章,非常不錯,很詳細。但是我想說,有乙個小小的地方不太注意,這裡提出,希望可以有所幫助。文中寫安裝dns 服務,用了bind服務,yum y install bind bind utils bind libs bind c...

CentOS 7 DNS服務配置

這裡已將對應的依賴關係的元件都安裝好了 進入etc資料夾中查詢named檔案 root localhost etc ls named named chroot.files named.iscdlv.key named.root.key named.conf named.rfc1912.zones n...

centos手動配置IP和DNS

手動設定ip位址 如果虛擬機器不能自動獲取ip,只能手動配置,配置方法如下 輸入命令 vi etc sysconfig network scripts ifcfg eth0 編輯網絡卡的配置檔案 ipaddr 192.168.4.10 netmask 255.255.255.0 gateway 19...