判断端口通不通的几种方法

1、使用telnet判断
telnet是windows标准服务,可以直接用;如果是linux机器,需要安装telnet.
用法: telnet ip port
1)先用telnet连接不存在的端口
[root@localhost ~]# telnet 10.0.250.3 80
Trying 10.0.250.3...
telnet: connect to address 10.0.250.3: Connection refused #直接提示连接被拒绝

2)再连接存在的端口
[root@localhost ~]# telnet localhost 22
Trying ::1...
Connected to localhost. #看到Connected就连接成功了
Escape character is '^]'.
SSH-2.0-OpenSSH_5.3
a
Protocol mismatch.
Connection closed by foreign host.

2、使用ssh判断
ssh是linux的标准配置并且最常用,可以用来判断端口吗?
用法: ssh -v -p port username@ip
-v 调试模式(会打印日志).
-p 指定端口
username可以随意
1)连接不存在端口
[root@localhost ~]# ssh 10.0.250.3 -p 80
ssh: connect to host 10.0.250.3 port 80: Connection refused
[root@localhost ~]# ssh 10.0.250.3 -p 80 -v
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 10.0.250.3 [10.0.250.3] port 80.
debug1: connect to address 10.0.250.3 port 80: Connection refused
ssh: connect to host 10.0.250.3 port 80: Connection refused

2)连接存在的端口
[root@localhost ~]# ssh ... -p
a
^]
^C
[root@localhost ~]# ssh ... -p -v
OpenSSH_.p, OpenSSL ..e-fips Feb
debug: Reading configuration data /etc/ssh/ssh_config
debug: Applying options for *
debug: Connecting to ... [...] port .
debug: Connection established.
debug: permanently_set_uid: /
debug: identity file /root/.ssh/identity type -
debug: identity file /root/.ssh/identity-cert type -
debug: identity file /root/.ssh/id_rsa type -
debug: identity file /root/.ssh/id_rsa-cert type -
debug: identity file /root/.ssh/id_dsa type -
debug: identity file /root/.ssh/id_dsa-cert type -
a
^C

不用-v选项也可以咯
3、使用wget判断
wget是linux下的下载工具,需要先安装.
用法: wget ip:port
1)连接不存在的端口
[root@localhost ~]# wget ...:
---- ::-- http://.../
Connecting to ...:... failed: Connection refused.

2)连接存在的端口
[root@localhost ~]# wget ...:
---- ::-- http://...:/
Connecting to ...:... connected.
HTTP request sent, awaiting response...
### 如何检查端口映射后的连通性 为了验证端口映射配置是否成功,可以过多种方法来进行测试。以下是几种常用的方法: #### 使用 `telnet` 测试特定端口的连接情况 对于TCP协议的服务,可以利用命令行工具`telnet`来检测目标机器上的指定端口是否开放并可被访问。 ```bash telnet <外部IP地址> <映射到外网的端口号> ``` 如果能够建立成功的连接,则说明该端口映射设置无误;反之则可能存在配置错误或其他阻碍因素[^2]。 #### 利用 `nc (Netcat)` 工具进行更灵活的探测 除了传统的`telnet`之外,还可以采用功能更为强大的`nc`(即 Netcat),它不仅支持TCP还兼容UDP等多种传输层协议,并允许发送自定义数据包内容给远程主机监听的任意端口上。 ```bash nc -zv <外部IP地址> <映射到外网的端口号> ``` 此命令中的选项解释如下: - `-z`: 扫描模式, 不实际传送任何数据. - `-v`: 显示详细的输出信息. 当返回结果显示已成功建立了连接时,表明端口映射生效良好[^3]. #### 验证ICMP请求能否穿透至内部网络 尽管某些情况下出于安全性考虑会阻止ICMP类型的流量进入内网环境,但仍有必要确认此类报文是否能顺利抵达目的地。可过执行简单的ping操作初步判断内外网之间的基本可达状态: ```bash ping <外部IP地址> ``` 不过需要注意的是,即使Ping不通也不代表端口映射有问题,因为很多企业级防火墙默认就会屏蔽掉所有的ICMP回显请求消息[^1].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值