Today, after configuring the Linux Nic according to the CentOS network configuration article earlier in the Mitchell blog, we found that the internet cannot be pinged, but the intranet ping is normal. I have been wondering that I haven't got the answer tag for a long time in online search: CentOS
For details about the configuration items of the CentOS network, refer to the article on Mitchell's blog.
Symptom:
Ping intranet
Ping the Internet IP address. the domain name cannot be normal. the error "connect: Network is unreachable" is returned.
The command for adding a gateway to the Linux network configuration is displayed inadvertently later:
Copy codeThe code is as follows:
Route add default gw 192.168.128.2 dev eth0
Follow the steps above to add the default gateway. Accessing the Internet again is normal.
The GATEWAY is not configured in the configuration file, but it is confirmed that the GATEWAY address is configured in/etc/sysconfig/network, and the GATEWAY address is correct, after you restart the network multiple times, you cannot access the Internet without manually adding a gateway.
After carefully checking each NETWORK configuration file, it is found that there is a NETWORK configuration item in the NIC configuration file (ifcfg-eth0), for this configuration item, the role is not very clear, so I checked the instructions on the official website:
Copy codeThe 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 not to set this parameter (deprecate). This value will be automatically calculated by ifcalc. Since you do not need to set it, remove it naturally.
After the removal, after the network service is restarted, the Internet can be accessed magically. You can use route to view the route table and find that the default information can be automatically added. However, the original information does not exist:
Copy codeThe 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 0 0 0 eth0
Link-local * 255.255.0.0 U 1002 0 0 eth0
Default 192.168.128.2 0.0.0.0 UG 0 0 0 eth0
It seems that the problem is caused by this NETWORK parameter setting. As for the specific reason, it is not clear what impact this setting will have.
TIPs: For simplicity, you can also set IPADDR, GATEWAY, and so on to the ifcfg-eth * file, without setting the GATEWAY in the network separately.