本文摘自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出现ssh登录失败怎么办
如何解决CentOS虚拟机克隆后无法上网问题
详解CentOS安装jdk以及xftp工具使用介绍
CentOS系统如何查看版本信息
CentOS怎么执行脚本
CentOS系统如何查看端口是否开放
CentOS如何安装qt
CentOS 8.0 今天已正式发布!一起看看有哪些新特性
CentOS如何删除文件夹
如何解决CentOS下sudo命令找不到
更多相关阅读请进入《CentOS》频道 >>
转载请注明出处:木庄网络博客 » centos无法访问外网