本文摘自PHP中文网,作者V,侵删。

问题:
centos7 虚拟机不能访问外网
1 2 | [root@localhost ~]# curl www.baidu.com
curl: (6) Could not resolve host: www.baidu.com; 未知的错误
|
(推荐教程:centos使用教程)
解决方法:
1 2 3 4 5 6 | [root@localhost ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 ens192
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 ens192
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
|
然后编辑resolv.conf文件,添加内容如下:
1 | [root@localhost ~]# vim /etc/resolv.conf
|
1 2 3 4 5 | # Generated by NetworkManager
nameserver 218.30.19.50
nameserver 8.8.8.8
~
~
|
添加路由:
1 | [root@localhost ~]# route add default gw 192.168.1.1
|
再测是否可以访问百度
1 2 3 | [root@localhost ~]# curl www.baidu.com
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http:
|
OK,可以正常访问了。
相关视频教程推荐:linux视频教程
以上就是centos无法访问外网的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
CentOS如何进入系统的主界面?
CentOS7下无法ping通外网
linux无法连接外网
CentOS怎么安装deb格式软件包
CentOS如何切换root用户
如何找到CentOS中的iptables文件
CentOS如何查看是否安装了某个软件
CentOS怎么退出图形界面
CentOS7无法开机怎么解决
CentOS如何安装图形界面
更多相关阅读请进入《CentOS》频道 >>
转载请注明出处:木庄网络博客 » centos无法访问外网