Home>Article>Operation and Maintenance> centos cannot access external network

centos cannot access external network

王林
王林 Original
2020-03-18 16:43:21 2541browse

centos cannot access external network

Problem:

centos7 virtual machine cannot access the external network

[root@localhost ~]# curl www.baidu.com curl: (6) Could not resolve host: www.baidu.com; 未知的错误

(Recommended tutorial:centos usage tutorial)

Solution:

[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

Then edit the resolv.conf file and add the following content:

[root@localhost ~]# vim /etc/resolv.conf
# Generated by NetworkManager nameserver 218.30.19.50 nameserver 8.8.8.8 ~ ~

Add route:

[root@localhost ~]# route add default gw 192.168.1.1

Test again Can you access Baidu?

[root@localhost ~]# curl www.baidu.com   百度一下,你就知道
  

OK, you can access it normally.

Recommended related video tutorials:linux video tutorial

The above is the detailed content of centos cannot access external network. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn