我想将端口 80 上的传入请求重新映射到端口 22 并尝试以下操作:sudo iptables -A PREROUTING -t nat -p tcp --dport 80 -j REDIRECT --to-ports 22
但是,仍然ssh -i key user@host -p 80
不让我连接,我想知道为什么不呢?
编辑1
$ sudo iptables-save -c
sudo: unable to resolve host DevRon
# Generated by iptables-save v1.6.0 on Mon Sep 3 00:23:20 2018
*nat
:PREROUTING ACCEPT [21:1260]
:INPUT ACCEPT [21:1260]
:OUTPUT ACCEPT [254:15716]
:POSTROUTING ACCEPT [254:15716]
[0:0] -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 22
[0:0] -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 22
[0:0] -A PREROUTING -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8080
COMMIT
# Completed on Mon Sep 3 00:23:20 2018
# Generated by iptables-save v1.6.0 on Mon Sep 3 00:23:20 2018
*filter
:INPUT ACCEPT [41307:2896000]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [41123:2886089]
COMMIT
# Completed on Mon Sep 3 00:23:20 2018
如果您的目标是让 SSH 侦听端口 80,您可以在 /etc/ssh/sshd_config 中添加第二个端口选项,例如:
我在以下位置找到了答案:https ://www.howtoforge.com/community/threads/change-ssh-to-listen-on-two-ports.47365/