Home > Operation and Maintenance > Linux Operation and Maintenance > Solve the problem that Linux cannot access the external network

Solve the problem that Linux cannot access the external network

王林
Release: 2019-12-27 09:17:48
Original
10753 people have browsed it

Solve the problem that Linux cannot access the external network

Question:

A certain Linux server cannot ping the domain name, the following prompts:

Solve the problem that Linux cannot access the external network

Preparation :

First make sure the router is connected and the router can access the external network. This can be confirmed by accessing the gateway.

[root@localhost ~]# ping 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=2.96 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=1.75 ms
Copy after login

Free video tutorial sharing: linux video tutorial

If you are sure that there is no problem with the network, you can solve it through the following steps:

1 . Make sure the domain name server is set up. If not, it is recommended to set up Google's public DNS service. It should not cause problems.

[root@localhost ~]# cat /etc/resolv.conf
search localdomain
Copy after login

Because my DNS is not set up, pinging from the external network fails. Add dns to the file

[root@localhost ~]# vi /etc/resolv.conf
search localdomain
nameserver 202.98.96.68
nameserver 61.139.2.69
~
Copy after login

2. Make sure the gateway has been set

# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg* 
/etc/sysconfig/network-scripts/ifcfg-eth0:GATEWAY=192.168.40.1
Copy after login

If not, add the gateway as follows:

# route add default gw 192.168.40.1
Copy after login

Or manually After writing the /etc/sysconfig/network-scripts/ifcfg* file, restart the network service:

# service network restart
Copy after login

3. Ensure that dns resolution is available

# grep hosts /etc/nsswitch.conf 
hosts:      files dns
Copy after login

If there is a problem with any of the above, correct it and test again , it should be no problem:

#ping -c 3 www.baidu.com 
PING www.a.shifen.com (220.181.6.175) 56(84) bytes of data. 
64 bytes from 220.181.6.175: icmp_seq=0 ttl=50 time=9.51 ms 
64 bytes from 220.181.6.175: icmp_seq=1 ttl=50 time=8.45 ms 
64 bytes from 220.181.6.175: icmp_seq=2 ttl=50 time=8.97 ms 
--- www.a.shifen.com ping statistics --- 
3 packets transmitted, 3 received, 0% packet loss, time 2002ms 
rtt min/avg/max/mdev = 8.450/8.977/9.511/0.446 ms, pipe 2
Copy after login

Recommended related articles and tutorials: linux tutorial

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template