我使用 ufw 和 iptable 配置将服务器中的端口 25 转发到 53525。
它是通过 telnet 命令测试的端口,所以我尝试测试它。
与本地主机的 25 端口连接良好,但无法从外部计算机连接。
我确实检查过了网络状态监测结果,我的 25 端口没有列出。但端口 53525 列出了。
附上我的 ufw / iptables 配置。请帮忙。
文件:/etc/ufw/before.rules
*nat
:PREROUTING ACCEPT [0:0]
-A OUTPUT -p tcp --dport 25 -j REDIRECT --to-port 53525
-A OUTPUT -p tcp --dport 143 -j REDIRECT --to-port 54143
-A OUTPUT -p tcp --dport 445 -j REDIRECT --to-port 54445
-A OUTPUT -p tcp --dport 139 -j REDIRECT --to-port 54139
-A OUTPUT -p tcp --dport 173 -j REDIRECT --to-port 54173
-A OUTPUT -p tcp --dport 138 -j REDIRECT --to-port 54138
-A OUTPUT -p tcp --dport 1025 -j REDIRECT --to-port 53525
COMMIT
命令:iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-dgm redir ports 54138
REDIRECT tcp -- anywhere anywhere tcp dpt:173 redir ports 54173
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-ssn redir ports 54139
REDIRECT tcp -- anywhere anywhere tcp dpt:microsoft-ds redir ports 54445
REDIRECT tcp -- anywhere anywhere tcp dpt:imap2 redir ports 54143
REDIRECT tcp -- anywhere anywhere tcp dpt:smtp redir ports 53525
DOCKER all -- anywhere anywhere ADDRTYPE match dst-type LOCAL
REDIRECT tcp -- anywhere anywhere tcp dpt:imap2 redir ports 54143
REDIRECT tcp -- anywhere anywhere tcp dpt:smtp redir ports 53525
REDIRECT tcp -- anywhere anywhere tcp dpt:microsoft-ds redir ports 54445
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-ssn redir ports 54139
REDIRECT tcp -- anywhere anywhere tcp dpt:173 redir ports 54173
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-dgm redir ports 54138
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-dgm redir ports 54138
REDIRECT tcp -- anywhere anywhere tcp dpt:173 redir ports 54173
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-ssn redir ports 54139
REDIRECT tcp -- anywhere anywhere tcp dpt:microsoft-ds redir ports 54445
REDIRECT tcp -- anywhere anywhere tcp dpt:imap2 redir ports 54143
REDIRECT tcp -- anywhere anywhere tcp dpt:smtp redir ports 53525
DOCKER all -- anywhere !loopback/8 ADDRTYPE match dst-type LOCAL
REDIRECT tcp -- anywhere anywhere tcp dpt:smtp redir ports 53525
REDIRECT tcp -- anywhere anywhere tcp dpt:smtp redir ports 53525
REDIRECT tcp -- anywhere anywhere tcp dpt:imap2 redir ports 54143
REDIRECT tcp -- anywhere anywhere tcp dpt:microsoft-ds redir ports 54445
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-ssn redir ports 54139
REDIRECT tcp -- anywhere anywhere tcp dpt:173 redir ports 54173
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-dgm redir ports 54138
REDIRECT tcp -- anywhere anywhere tcp dpt:smtp redir ports 53525
REDIRECT tcp -- anywhere anywhere tcp dpt:imap2 redir ports 54143
REDIRECT tcp -- anywhere anywhere tcp dpt:microsoft-ds redir ports 54445
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-ssn redir ports 54139
REDIRECT tcp -- anywhere anywhere tcp dpt:173 redir ports 54173
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-dgm redir ports 54138
REDIRECT tcp -- anywhere anywhere tcp dpt:smtp redir ports 53525
REDIRECT tcp -- anywhere anywhere tcp dpt:imap2 redir ports 54143
REDIRECT tcp -- anywhere anywhere tcp dpt:microsoft-ds redir ports 54445
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-ssn redir ports 54139
REDIRECT tcp -- anywhere anywhere tcp dpt:173 redir ports 54173
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-dgm redir ports 54138
REDIRECT tcp -- anywhere anywhere tcp dpt:1025 redir ports 53525
REDIRECT tcp -- anywhere anywhere tcp dpt:smtp redir ports 53525
REDIRECT tcp -- anywhere anywhere tcp dpt:imap2 redir ports 54143
REDIRECT tcp -- anywhere anywhere tcp dpt:microsoft-ds redir ports 54445
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-ssn redir ports 54139
REDIRECT tcp -- anywhere anywhere tcp dpt:173 redir ports 54173
REDIRECT tcp -- anywhere anywhere tcp dpt:netbios-dgm redir ports 54138
REDIRECT tcp -- anywhere anywhere tcp dpt:1025 redir ports 53525
命令:ufw status
22 ALLOW Anywhere
80 ALLOW Anywhere
25 ALLOW Anywhere
110 ALLOW Anywhere
143 ALLOW Anywhere
443 ALLOW Anywhere
465 ALLOW Anywhere
587 ALLOW Anywhere
993 ALLOW Anywhere
995 ALLOW Anywhere
4190 ALLOW Anywhere
3389 ALLOW Anywhere
8083 ALLOW Anywhere
22 (v6) ALLOW Anywhere (v6)
80 (v6) ALLOW Anywhere (v6)
25 (v6) ALLOW Anywhere (v6)
110 (v6) ALLOW Anywhere (v6)
143 (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)
465 (v6) ALLOW Anywhere (v6)
587 (v6) ALLOW Anywhere (v6)
993 (v6) ALLOW Anywhere (v6)
995 (v6) ALLOW Anywhere (v6)
4190 (v6) ALLOW Anywhere (v6)
3389 (v6) ALLOW Anywhere (v6)
8083 (v6) ALLOW Anywhere (v6)
答案1
我找到了解决方案。
在 UFW 中预路由端口时,您必须添加目标端口以允许规则。
例如,如果你想将源端口 22 转发到目标端口 1922,
您必须运行命令“ufw allow 22”和“ufw allow port 1922”。
如果没有开放源端口或目标端口,预路由将不起作用。