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

How to troubleshoot network failures in Linux

Nov 14, 2020 am 10:42 AM
linux

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

How to run java code in notepad How to run java code in notepad Apr 16, 2025 pm 07:39 PM

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

vscode terminal usage tutorial vscode terminal usage tutorial Apr 15, 2025 pm 10:09 PM

vscode built-in terminal is a development tool that allows running commands and scripts within the editor to simplify the development process. How to use vscode terminal: Open the terminal with the shortcut key (Ctrl/Cmd). Enter a command or run the script. Use hotkeys (such as Ctrl L to clear the terminal). Change the working directory (such as the cd command). Advanced features include debug mode, automatic code snippet completion, and interactive command history.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Where to write code in vscode Where to write code in vscode Apr 15, 2025 pm 09:54 PM

Writing code in Visual Studio Code (VSCode) is simple and easy to use. Just install VSCode, create a project, select a language, create a file, write code, save and run it. The advantages of VSCode include cross-platform, free and open source, powerful features, rich extensions, and lightweight and fast.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

See all articles