Ubuntu 18.04 DNS配置解决域名无法访问或者访问很慢的问题

之前在公司自己弄了个OP的路由器,之前一直都跑的好好的(经常在公司内网和自己的OP之间切换),但是这周发现内网网口的时候上网无问题,但是用自己OP的时候无法访问外网,ping的通IP,但是域名无法解析,网站也无法打开,确定是DNS配置出了问题,花了点时间查了下资料,修复了此问题,省的重新装机了,下面记录下踩到的坑,以及解决的方法.

其实整体思路就是配置好DNS服务器就可以了,找到相关配置文件修改下其实就行,但是下面这几种方式,我试过了,不行.

修改/etc/resolv.conf配置,但是一旦重启,就恢复默认值了。有个博主推荐安装下resolvconf,然后修改/etc/resolvconf/resolv.conf.d/ 目录下head文件(head就是在/etc/resolv.conf头部添加配置,tail就是在尾部)

sudo apt install resolvconf 
sudo vim /etc/resolvconf/resolv.conf.d/head 

在head中添加一行,

nameserver 114.114.114.114 

注意,一定要在最后回车换行.重启后,可以看到/etc/resolv.conf里面配置变成了

nameserver 114.114.114.114 nameserver 127.0.0.53 

其实可以关闭本地DNS的,如下操作即可,

sudo systemctl disable systemd-resolved.service sudo systemctl stop systemd-resolved 

重启后,发现/etc/resolv.conf里面只剩下114的DNS配置了.
但是这个方式并没有解决我切换到自己的OP时无法联网的问题,并且这么操作后,公司内网也打不开了,这种方式失败.

另一种方式,其实这这个类似,修改/etc/systemd/resolved.conf配置文件,修改成

# This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Entries in this file show the compile time defaults. # You can change settings by editing this file. # Defaults can be restored by simply deleting this file. # # See resolved.conf(5) for details [Resolve] DNS=8.8.8.8 FallbackDNS=1.1.1.1 #Domains= #LLMNR=no #MulticastDNS=no #DNSSEC=no #Cache=yes #DNSStubListener=yes 

如此修改后,/etc/resolv.conf重启后会默认设置DNS服务器为DNS=8.8.8.8,思路是和第一种方式一致的,但是还是没用.

还有修改/etc/NetworkManager下面的配置文件的,但是依然没用.

修改/etc/netplan/01-network-manager-all.yaml配置文件,具体操作方法如下:

先看下电脑的网卡配置信息,

ifconfig 

拿我的电脑举栗子,显示如下,

docker0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500 inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255 ether 02:42:5a:e8:db:2b txqueuelen 0 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.16.15.69 netmask 255.255.255.0 broadcast 172.16.15.255 inet6 fe80::7f3e:10c5:5cbb:fdee prefixlen 64 scopeid 0x20<link> ether 1c:a0:b8:77:a1:3c txqueuelen 1000 (Ethernet) RX packets 35475 bytes 15108483 (15.1 MB) RX errors 0 dropped 16447 overruns 0 frame 0 TX packets 7396 bytes 1520156 (1.5 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 device interrupt 23 memory 0xa3300000-a3320000 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 9045 bytes 8238003 (8.2 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 9045 bytes 8238003 (8.2 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 wlx502b73c9007e: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.8.129 netmask 255.255.255.0 broadcast 192.168.8.255 inet6 fe80::3c12:8ccf:3ad7:3978 prefixlen 64 scopeid 0x20<link> ether 50:2b:73:c9:00:7e txqueuelen 1000 (Ethernet) RX packets 14476 bytes 14118753 (14.1 MB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 11756 bytes 2047466 (2.0 MB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 

从中可以看出,我这边是两个网卡的,一个是eno1(本地有线连接),另一个是wlx502b73c9007e(自己加的无线网卡),记下来这两个网卡的名称和IP,下面用得上.

然后开始配置/etc/netplan/01-network-manager-all.yaml

sudo gedit /etc/netplan/01-network-manager-all.yaml 

修改后,显示为

# Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager #renderer: networkd ethernets: wlx502b73c9007e : addresses: [192.168.8.129/24] dhcp4: yes optional: true gateway4: 192.168.8.1 nameservers: addresses: [8.8.8.8,8.8.4.4,114.114.114.114] 

然后执行下面命令:

sudo netplan apply sudo systemctl start systemd-networkd.service 

应用所做修改就可以了.

我这里只修改了,我自己添加的网卡配置,eno1网卡按照默认的配置运行,当然大家也可以按照自己的需求去修改DNS的服务器,我这里用的就是Google和114,大部分场景我这边都可以覆盖了.

好的,打完收工,最后查了下,好像从18.04开始,都是使用netplan配置网卡了,所以之前的方式通通失效.

原文链接:https://blog.csdn.net/qq_24649627/article/details/129155599?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522168466843816800197047861%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=168466843816800197047861&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-3-129155599-null-null.blog_rank_default&utm_term=NAS%E3%80%81%E7%BE%A4%E6%99%96%E3%80%81%E9%98%BF%E9%87%8C%E4%BA%91%E3%80%81%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90%E3%80%81%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F%E3%80%81ipv6%E3%80%81ddns%E3%80%81%E8%BD%BB%E9%87%8F%E7%BA%A7%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E3%80%81%E9%93%81%E5%A8%81%E9%A9%AC%E3%80%81%E5%A8%81%E8%81%94%E9%80%9A%E3%80%81DSM%E3%80%81DSM6.0%E3%80%81%E7%BE%A4%E6%99%96nas%E3%80%81%E4%BA%91%E6%9C%8D%E5%8A%A1%E5%99%A8%E3%80%81%E8%9C%97%E7%89%9B%E6%98%9F%E9%99%85%E3%80%81%E9%BB%91%E7%BE%A4%E6%99%96%E3%80%81docker%E3%80%81%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E3%80%81%E5%9F%9F%E5%90%8D%E6%B3%A8%E5%86%8C%E3%80%81%E5%AE%9D%E5%A1%94%E3%80%81%E5%8F%8D%E5%90%91%E4%BB%A3%E7%90%86%E3%80%81nginx%E3%80%81frp%E3%80%81%E5%8A%A8%E6%80%81%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享