In the Linux system, you can use the ping and telnet commands to test whether the IP address and port are connected

In the Linux system, you can use the ping and telnet commands to test whether the IP address and port are connected.

Use the ping command to test whether the IP is connected:

ping IP地址

For example:

ping 192.168.0.1

If the ping succeeds, output similar to the following will appear:

PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
64 bytes from 192.168.0.1: icmp_seq=1 ttl=64 time=1.34 ms
64 bytes from 192.168.0.1: icmp_seq=2 ttl=64 time=1.41 ms
64 bytes from 192.168.0.1: icmp_seq=3 ttl=64 time=1.35 ms
...

If the ping fails, output similar to the following will appear:

PING 192.168.0.1 (192.168.0.1) 56(84) bytes of data.
From 192.168.0.2 icmp_seq=1 Destination Host Unreachable
From 192.168.0.2 icmp_seq=2 Destination Host Unreachable
From 192.168.0.2 icmp_seq=3 Destination Host Unreachable
...

Use the telnet command to test whether the port is open:

telnet IP地址 端口号

For example:

telnet 192.168.0.1 80

If the port is open, a successful connection message will appear, as shown below:

Trying 192.168.0.1...
Connected to 192.168.0.1.
Escape character is '^]'.

If the port is not open, information similar to the following will appear:

Trying 192.168.0.1...
telnet: Unable to connect to remote host: Connection refused

Guess you like

Origin blog.csdn.net/weixin_41827053/article/details/129398989