大网数据广告活动
服务器运维问答

SSH port filtered on machine only from within local network when using explicit ip address

· 52CE 我爱测

To describe the situation, I need to define three machines. On the local network I have a machine (LAPTOP) and a machine (SERVER) connected over WAN and LAN to the router, respectively. The third machine is an external vps (VPS).…

问题原文

原帖链接 · Pankrates · CC BY-SA 3.0

To describe the situation, I need to define three machines. On the local network I have a machine (LAPTOP) and a machine (SERVER) connected over WAN and LAN to the router, respectively. The third machine is an external vps (VPS).

I am trying to SSH into the SERVER from the LAPTOP using an explicit IP address. To accomplish this, I set up openssh servers (all machines are running Ubuntu) listening to port 22. On the router I gave a reserved IP address to SERVER and added a port forwarding rule for incoming port 22 to port 22 of the SERVER.

What is working: - SSH from VPS to SERVER - SSH from LAPTOP to SERVER using local hostname internal to local network

What is not working: - SSH from LAPTOP to SERVER using explicit IP address.

To try and debug I ran nmap to see if the port is being filtered. I ran the following command on both the VPS and the LAPTOP

nmap -sS -p 22 xx.xx.xx.xx

where the x's denote the literal external IP of the router of the local network. The result is as follows:

VPS: 22/tcp open ssh
LAPTOP: 22/tcp filtered ssh

Just to double check if I use local hostname from the LAPTOP the port is open as it should be. Why is the port filtered when SSH'ing from the LAPTOP when using the explicit external IP? Is the outgoing request being filtered by my router?

已采纳解答

原帖链接 · spongebob · CC BY-SA 3.0

Your problem comes from the fact that your router probably applies the port forwarding rules (DNAT chain in iptables) before the NAT (SNAT chain in iptables).

This stackexchange post explains the problem in details and shows you how to confirm it using tcpdump. Basically you should see that you send your SYN packet to your external IP but receive the SYN/ACK from SERVER's internal IP.

Edit: How to fix it: Do not connect to your external IP from within your internal network. Use SERVER's internal IP directly.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-12-31)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。