ubuntu18.04不能联网解决办法,网络显示问号,内网可以访问,外网不能访问,用windows访问外网可以

本文详细描述了Windows和Ubuntu 18.04环境下网络连接差异,重点在于Ubuntu上无法访问外网但能ping通内网网关的问题。通过排查发现是由于网关识别问题,最终通过修改resolv.conf文件解决。关键词包括:Ubuntu 18.04、网络故障、内网访问、网关、DNS解析。
摘要由CSDN通过智能技术生成

问题描述

提示:这里描述具体问题:同一根网线,在windows上可以访问外网,在ubuntu18.04上不能访问外网,访问内网是可以。正常也可以ping通内网的网关。
在ubuntu18.04右上角显示网络是问号,正常不能访问外网。
在这里插入图片描述

ping 内网网关是可以的

PING 10.23.56.254 (10.23.56.254) 56(84) bytes of data.
64 bytes from 10.23.56.254: icmp_seq=1 ttl=254 time=0.497 ms
64 bytes from 10.23.56.254: icmp_seq=2 ttl=254 time=0.553 ms
64 bytes from 10.23.56.254: icmp_seq=3 ttl=254 time=0.491 ms
64 bytes from 10.23.56.254: icmp_seq=4 ttl=254 time=0.558 ms
64 bytes from 10.23.56.254: icmp_seq=5 ttl=254 time=0.456 ms
64 bytes from 10.23.56.254: icmp_seq=6 ttl=254 time=0.524 ms
64 bytes from 10.23.56.254: icmp_seq=7 ttl=254 time=0.541 ms
64 bytes from 10.23.56.254: icmp_seq=8 ttl=254 time=0.540 ms
64 bytes from 10.23.56.254: icmp_seq=9 ttl=254 time=0.456 ms
64 bytes from 10.23.56.254: icmp_seq=10 ttl=254 time=0.486 ms
64 bytes from 10.23.56.254: icmp_seq=11 ttl=254 time=0.439 ms
64 bytes from 10.23.56.254: icmp_seq=12 ttl=254 time=0.454 ms
64 bytes from 10.23.56.254: icmp_seq=13 ttl=254 time=0.504 ms
64 bytes from 10.23.56.254: icmp_seq=14 ttl=254 time=0.563 ms

但是ping www.baidu.com 不通

ping: www.baidu.com: Temporary failure in name resolution

ping 8.8.8.8 不通

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From 10.23.56.254 icmp_seq=1 Destination Net Unreachable
^C
--- 8.8.8.8 ping statistics ---
3 packets transmitted, 0 received, +1 errors, 100% packet loss, time 2035ms

修改/etc/resolv.conf文件中增加网关即可。

$ sudo vim /etc/resolv.conf 
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
nameserver 114.114.114.114
nameserver 8.8.8.8
nameserver 自己的网关
options edns0 trust-ad

本机网关查询route命令或netstat -rn命令

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         bogon           0.0.0.0         UG    20100  0        0 enp4s0
10.23.56.0      0.0.0.0         255.255.255.0   U     100    0        0 enp4s0
link-local      0.0.0.0         255.255.0.0     U     1000   0        0 docker0
189.15.0.0      0.0.0.0         255.255.0.0     U     0      0        0 docker0

把10.23.56.0填到/etc/resolv.conf 文件中即可。


在ping就可以了。

PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=20 ttl=114 time=42.4 ms
64 bytes from 8.8.8.8: icmp_seq=21 ttl=114 time=42.5 ms
64 bytes from 8.8.8.8: icmp_seq=22 ttl=114 time=43.4 ms
64 bytes from 8.8.8.8: icmp_seq=23 ttl=114 time=42.5 ms
64 bytes from 8.8.8.8: icmp_seq=31 ttl=114 time=42.1 ms
64 bytes from 8.8.8.8: icmp_seq=32 ttl=114 time=42.3 ms
64 bytes from 8.8.8.8: icmp_seq=33 ttl=114 time=42.0 ms
64 bytes from 8.8.8.8: icmp_seq=34 ttl=114 time=42.9 ms
64 bytes from 8.8.8.8: icmp_seq=35 ttl=114 time=42.0 ms
64 bytes from 8.8.8.8: icmp_seq=36 ttl=114 time=42.1 ms

原因分析:

提示:这里填写问题的分析:由与网络中网关不能识别导致的。


解决方案:

提示:这里填写该问题的具体解决方案:如上。

欢迎评论:

提示:欢迎大家在评论区讨论相关问题。
可以关注博主,我会持续更新工作中遇到的技术小砖头,供大家使用。
也可以在评论区告知好的小砖头或技术,我会收录。
还可以指出本博文错误,希望大家不吝赐教。

  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端小白到专家

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值