Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to solve the problem of being unable to access the external network in CentOS

Shulou Source: shulou.com Published: 2022-06-01 23:38:59 09月23日 Update

How to solve the problem of being unable to access the public network in CentOS? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

Phenomenon:

The private network of ping is normal.

Ping public network IP, domain names are not working properly. Error returned: connect: Network is unreachable

Later, I inadvertently saw that the Linux network was configured with the command to add a gateway:

Copy the code

The code is as follows:

Route add default gw 192.168.128.2 dev eth0

Do as above, after adding the default gateway. Everything is fine when you visit the public network again.

From this point of view, the gateway should not be configured in the configuration file, but it is confirmed that the GATEWAY address is configured in / etc/sysconfig/network, and the GATEWAY address is also correct. After restarting network many times, as long as you do not manually add the gateway, you cannot access the public network.

After carefully confirming each network configuration file many times, it is found that there is a NETWORK configuration item in the network card configuration file (ifcfg-eth0). The function of this configuration item is not very clear, so I went to the official website to check the instructions:

Copy the code

The code is as follows:

NETWORK=

Where is the network address. This directive is deprecated, as the value is calculated automatically with ifcalc.

This rhythm tells us that this parameter should not be set (deprecate). This value will be calculated automatically by ifcalc. Since there is no need to set it, it will be removed naturally.

After removing it and restarting the network service, the public network is miraculously able to access it. Use route to check the routing table and find that the message default can be added automatically, but it has not been available all the time:

Copy the code

The code is as follows:

Kernel IP routing table

Destination Gateway Genmask Flags Metric Ref Use Iface

192.168.128.0 * 255.255.255.0 U 000 eth0

Link-local * 255.255.0.0 U 1002 00 eth0

Default 192.168.128.2 0.0.0.0 UG 0 0 0 eth0

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Tags: Configuration code gateway file clear address phenomenon network help magic do not use function information content again parameters commands domain name for this manual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MySQL Huawei vpn Shulou Technology