联系管理员

开通文章发布权限

扫码 添加微信
微信图片
电话:18888888888 QQ:-

虚拟机 ubuntu 22.04 ping不通问题

虚拟机 ubuntu 22.04 下发现没有网络,使用ping百度发现ping不通问题
ping www.baidu.com

输出

ping: www.baidu.com: 域名解析出现暂时性错误

查看网关

route -n

输出 没有IP地址,正常应该会有IP地址的。

内核 IP 路由表
目标            网关            子网掩码        标志  跃点   引用  使用 接口

检查网络连接

ifconfig -a

输出 发现ens33是没有启动的,它是以太网接口。

ens33: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 00:0c:29:81:ef:42  txqueuelen 1000  (以太网)
        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

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  (本地环回)
        RX packets 2249  bytes 161163 (161.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2249  bytes 161163 (161.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

启动以太网接口

sudo ifconfig ens33 up

再查看发现启动是启动了,但是查询 route -n 发现IP还是空白。ping也不通。

ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::20c:29ff:fe81:ef42  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:81:ef:42  txqueuelen 1000  (以太网)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 17  bytes 2375 (2.3 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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  (本地环回)
        RX packets 2889  bytes 206603 (206.6 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2889  bytes 206603 (206.6 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

更新DNS

sudo vim /etc/resolv.conf

在文件中,更新和新增以下内容:

nameserver 8.8.8.8
nameserver 8.8.4.4

使用 DHCP 获取 IP 地址

sudo dhclient -r ens33
sudo dhclient ens33

重启网络服务

sudo service network restart

这个时候重新查询IP,发现有了,直接ping百度也OK了,修好了。

图片#B #S #R #60% #auto

以上问题可以简化为以下两个命令:

sudo ifconfig ens33 up
sudo dhclient ens33

 

评论

快捷导航

把好文章收藏到微信

打开微信,扫码查看

关闭

还没有账号?立即注册