macOS端口转发远程SSHlogin

我想从我的networking外部远程sshlogin到我局域网上的服务器(macOS Sierra),使用22以外的端口( 我听说它提高了安全性,使用默认端口以外的端口,这是真的吗?

我已经成功configuration了我的路由器( Cisco RV325 ,它有一个固定的WAN IP地址,例如99.99.99.99),以便我可以远程login到端口22上的服务器(静态局域网IP地址12.0.0.123)所以:

$ ssh [email protected] -p 22 

这工作正常。 我现在想要通过另一个端口login(比方说60022),如下所示:

 $ ssh [email protected] -p 60022 

我不知道如何转发从端口60022到22的stream量。这是我应该做的路由器,或在本地服务器? 路由器的“端口范围转发表”configuration允许给定端口范围的数据包转发到一个特定的IP,但它似乎不允许我从一个端口转换到另一个端口。

如果它应该发生在服务器,我不明白如何做到这一点。 我怎么让macOS甚至开始在端口60022上听?

我已经尝试过将这些Ubuntu指令适配到Mac,但没有成功。 我试过使用pfctl来设置转发:

 $ echo " rdr pass inet proto tcp from any to any port 60022 -> 127.0.0.1 port 22 pass in proto tcp from any to any port 60022 " | sudo pfctl -f - pfctl: Use of -f option, could result in flushing of rules present in the main ruleset added by the system at startup. See /etc/pf.conf for further details. No ALTQ support in kernel ALTQ related functions disabled $ 

这似乎没有打开端口60022,因为(1)端口不显示时,我做sudo lsof -i -P | grep LISTEN sudo lsof -i -P | grep LISTEN和(2)当我坐在服务器上并尝试login时,连接被拒绝:

 $ ssh [email protected] -p 60022 -v OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011 debug1: Reading configuration data /Users/USERNAME/.ssh/config debug1: Reading configuration data /etc/ssh_config debug1: /etc/ssh_config line 20: Applying options for * debug1: /etc/ssh_config line 102: Applying options for * debug1: Connecting to 127.0.0.1 [127.0.0.1] port 60022. debug1: connect to address 127.0.0.1 port 60022: Connection refused ssh: connect to host 127.0.0.1 port 60022: Connection refused $ 

而在22端口login工作正常:

 $ ssh [email protected] -p 22 -v OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011 debug1: Reading configuration data /Users/USERNAME/.ssh/config debug1: Reading configuration data /etc/ssh_config debug1: /etc/ssh_config line 20: Applying options for * debug1: /etc/ssh_config line 102: Applying options for * debug1: Connecting to 127.0.0.1 [127.0.0.1] port 22. debug1: Connection established. ... Password: $ 

综上所述:

  1. 我如何告诉macOS开始监听端口60022?
  2. 如何告诉macOS将端口60022转换为22?
  3. 有关如何做到这一点的任何好的介绍/教程?
  4. 我甚至应该打算转发到60022(例如),还是足够安全的使用默认端口22?

正如@yoonix所build议的那样,您可以完全在路由器中完成所需的目标,而不用修改服务器(macOS或其他)。 总结问题#1和#2(甚至是post的标题)可能有点误导。 至于问题#4,请参阅@Gordon Davisson的评论。

为了完成这个目标,build立路由器如下:

  1. 使用浏览器login到RV325configuration页面。 select“设置”>“端口地址转换”。
  2. 在“端口地址转换表”下点击“服务pipe理…”button。 在popup窗口中点击“添加”,然后input服务名称(这个端口地址转换设置的方便的昵称),从popup菜单中select“TCP”,然后input外部端口(60022)和内部端口22)。 点击“保存”,closurespopup窗口。
  3. 回到“端口地址转换表”中,点击“添加”。 从popup菜单中select您的服务名称,input转发IP地址(示例中为12.0.0.123),然后选中状态框以启用它。 点击“保存”。
  4. 进入“防火墙”>“访问规则”,然后点击“服务pipe理…”button。 在popup的窗口中点击“添加”,然后input一个服务名称(您的访问规则的昵称),然后input您希望打开的外部端口号(或端口号范围)(60022-60022)例)。 点击“保存”,closurespopup窗口。
  5. 最后,在“访问规则”中点击“添加”。 select“允许”和上面创build的服务名称。 将“源IP”和“目标IP”保留为“任何”。 点击“保存”。

从现在开始,路由器将负责必要的转发和端口转换,因此执行ssh [email protected] -p 60022会将您的权限发送到12.0.0.113所需的服务器上的login守护程序。