将端口 80 重新映射到 22

将端口 80 重新映射到 22

我想将端口 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

答案1

如果您的目标是让 SSH 侦听端口 80,您可以在 /etc/ssh/sshd_config 中添加第二个端口选项,如下所示:

Port 22
Port 80

答案2

我找到了答案:https://www.howtoforge.com/community/threads/change-ssh-to-listen-on-two-ports.47365/

SSH 可以侦听多个端口。只需在 sshd_config 中添加其他端口,如下所示:

端口 22
端口 8888

相关内容