Home > Operation and Maintenance > Linux Operation and Maintenance > How to troubleshoot network failures in Linux

How to troubleshoot network failures in Linux

齐天大圣
Release: 2020-11-16 11:13:17
Original
2818 people have browsed it

If the company website cannot be opened, if it is due to network problems, how should you troubleshoot it. For another example, if the remote connection tool cannot connect to the server or the mysql database cannot be connected, may it be due to network problems. In daily work or study, we often encounter various network problems (because computer networks are too complex). Now let's take a look at how to troubleshoot if there is a network problem on the Linux server.

ping

First let’s look at the ping command. This command is a tool used to test whether normal communication can occur between two hosts. The object of ping can be either an IP address or a domain name. This command can be used in the cmd mode of Linux and Windows. The usage methods are the same.

# ping -c 4 8.210.247.5
PING 8.210.247.5 (8.210.247.5) 56(84) bytes of data.
64 bytes from 8.210.247.5: icmp_seq=1 ttl=64 time=1.54 ms
64 bytes from 8.210.247.5: icmp_seq=2 ttl=64 time=1.48 ms
64 bytes from 8.210.247.5: icmp_seq=3 ttl=64 time=1.46 ms
64 bytes from 8.210.247.5: icmp_seq=4 ttl=64 time=1.48 ms
--- 8.210.247.5 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 1.460/1.494/1.548/0.042 ms
 
# ping -c 1 baidu.com 
……
Copy after login

Below is a shell script used to check which IPs on the LAN can communicate

#!/bin/bash
net='192.168.2.'
seqs=`seq 1 254`

for seq in $seqs
do
    ip=$net$seq
    /usr/bin/ping -c 1 -W 1 $ip >/dev/null 2>&1
    
    if [ "$?" == "0" ];then
        echo "$ip is UP"
    fi
done
Copy after login

traceroute

This command is used to check the network status of each node between two hosts. If the speed is slow when you access a website, you can use this command to view the network status of all nodes.

# traceroute -n google.com
traceroute to google.com (172.217.163.238), 30 hops max, 60 byte packets
 1  * * *
 2  11.109.220.61  1.444 ms  1.577 ms 11.109.216.189  1.500 ms
 3  11.109.220.190  5.512 ms * 11.109.220.174  5.382 ms
 4  11.131.180.222  1.660 ms 11.131.180.218  1.519 ms 11.131.180.250  1.365 ms
 ……
Copy after login

nslookup

This command can reversely check the IP address through the domain name, and it is very simple to use.

nslookup 5iqm.com
Server:  100.100.2.136
Address: 100.100.2.136#53

Non-authoritative answer:
Name: 5iqm.com
Address: 121.196.12.64
Copy after login

netstat

. If the website cannot be accessed, the first thing we should do is ping the IP address of the server. If it can be pinged normally, then we should ping the website domain name to see if the dns is resolved normally. If there are no problems and the website still cannot be accessed, then you need to check whether port 80 is open to the outside world. The netstat command is used to check the host port listening status.

# netstat -tlunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      30721/nginx: master 
tcp        0      0 0.0.0.0:21              0.0.0.0:*               LISTEN      1275/pure-ftpd (SER 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1167/sshd           
tcp        0      0 0.0.0.0:888             0.0.0.0:*               LISTEN      30721/nginx: master 
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      2068/python
Copy after login

telnet

This command can be used to test whether the specified port of the server is open to itself.

# telnet 8.210.110.139 22
Trying 8.210.110.139...
Connected to 8.210.110.139.   
Escape character is '^]'.
SSH-2.0-OpenSSH_7.4


# telnet 8.210.110.139 3306
Trying 8.210.110.139...  <=== 一直是这样的状态则
Copy after login

If it is the first situation above, it means that port 22 of 8.210.110.139 is open. If it is the second type and it keeps trying, it means that this port is not open to itself.

The above is the detailed content of How to troubleshoot network failures in Linux. 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