Home  >  Article  >  php教程  >  Solution to ping: unknown host error under Linux

Solution to ping: unknown host error under Linux

高洛峰
高洛峰Original
2016-11-23 11:42:181903browse

Sometimes ping command errors occur on Linux servers. Let’s summarize them today

If a Linux server cannot ping the domain name, the following prompts:

[root@localhost ~]# ping www.pythontab.com

ping: unknown host www.pythontab.com

First make sure the router is connected and the router can access the external network. You can confirm 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

If you are sure that there is no problem with the network, you can find a solution 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 go out. The problem is

[root@localhost ~]# cat /etc/resolv.conf

search localdomain

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

[root@localhost ~]# vi /etc/resolv.conf

search localdomain

nameserver 202.98.96.68

nameserver 61.139.2.69

~

2) Make sure the gateway is set

# grep GATEWAY /etc/sysconfig/network-scripts/ifcfg*

--------------------- ---------------------------------------------

/etc/ sysconfig/network-scripts/ifcfg-eth0:GATEWAY=192.168.40.1

--------------------------------- ----------------------------------

If it is not set, add the gateway as follows:

# route add default gw 192.168.40.1

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

# service network restart

3) Make sure dns resolution is available

# grep hosts /etc/nsswitch.conf

---------------------------------- ------------------------------------

hosts: files dns

------ -------------------------------------------------- -----------

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

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