常见的查看linux服务器之间网络连通性命令
1、telnet
telnet命令可以测试TCP/IP连接和端口的可用性 命令:telnet [目标服务器IP地址] [端口号]
一般网络通畅会返回一下信息:
Trying 192.168.5.141...
Connected to hostname (IP_address).
Escape character is '^]'.
如果还返回了“Connection closed by foreign host”,这表示网络访问关系是通的,但连接被远程主机关闭
网络不通
Trying 192.168.5.141...
telnet: Unable to connect to remote host: Connection refused
2、ping
ping命令用于测试主机之间的连通性。可以使用ping命令向远程主机发送网络请求,并接收回复。通过检查返回的回复时间和丢包率,可以判断主机是否可达以及网络连接是否正常 命令:ping [IP地址]
一般ping通的情况:
PING 192.168.120.201 (192.168.120.201) 56(84) bytes of data.
64 bytes from 192.168.120.201: icmp_seq=1 ttl=64 time=0.309 ms
64 bytes from 192.168.120.201: icmp_seq=2 ttl=64 time=0.253 ms
一般ping不通的情况:
PING 192.168.5.141 (192.168.5.141) 56(84) bytes of data.
From 192.168.5.49 icmp_seq=1 Destination Host Unreachable
From 192.168.5.49 icmp_seq=2 Destination Host Unreachable
From 192.168.5.49 icmp_seq=3 Destination Host Unreachable
3、curl
curl命令可以测试网络连通性,主要用于发出网络请求并获取数据,然后显示在标准输出上 命令:curl -v [目标服务器IP地址]:[端口号]
网络连通的情况:
* Rebuilt URL to: 192.168.5.141:8848/
* Trying 192.168.5.141...
* TCP_NODELAY set
* Connected to 192.168.5.141 (192.168.5.141) port 8848 (#0)
> GET / HTTP/1.1
> Host: 192.168.5.141:8848
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 404
< Content-Type: text/html;charset=utf-8
< Content-Language: en
< Content-Length: 431
< Date: Tue, 03 Dec 2024 06:44:44 GMT
<
* Connection #0 to host 192.168.5.141 left intact
Connected to 192.168.5.141 (192.168.5.141) port 8848 (#0) 表示curl成功连接到指定的IP地址和端口号。 http返回的404;只能说明服务器无法找到客户端请求的资源,而不能代表网络不通
网络不通的情况
* Rebuilt URL to: 192.168.5.141:8848/
* Trying 192.168.5.141...
* TCP_NODELAY set
* connect to 192.168.5.141 port 8848 failed: Connection timed out
* Failed to connect to 192.168.5.141 port 8848: Connection timed out
* Closing connection 0
curl: (7) Failed to connect to 192.168.5.141 port 8848: Connection timed out
如果是“Connection timed out”,则需要检查网络延迟或者是否存在网络设备(如路由器或防火墙)阻止了连接 如果是“Connection refused”,则需要检查服务器端的服务是否正在运行,或者防火墙设置是否正确
4、nc
nc命令是一个强大的网络工具,用于检查和测试网络连接。 命令:nc -zv [目标IP] [端口号] -z:参数告诉 nc 命令只扫描监听端口 -v:输出交互或出错信息
网络连通的情况下
Connection to 192.168.5.141 8848 port [tcp/*] succeeded!
网络不通
nc: connect to 192.168.5.141 port 80 (tcp) failed: Connection timed out
5、nmap
nmap命令用于网络扫描和安全审计的工具,可以检查主机的开放端口和服务
命令:nmap -p [端口号] [目标IP地址]
一般网络通时返回:
Starting Nmap 7.91 ( https://nmap.org ) at 2024-12-04 10:00 CST
Nmap scan report for 192.168.5.141
Host is up (0.00020s latency).
PORT STATE SERVICE
8080/tcp open http
Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
一般网络不通时:
Starting Nmap 7.91 ( https://nmap.org ) at 2024-12-04 10:01 CST
Nmap scan report for 192.168.5.141
Host is up (0.00025s latency).
PORT STATE SERVICE
8080/tcp closed http
Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
评论前必须登录!
注册