AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1076450
Accepted
user371793
user371793
Asked: 2021-09-03 09:07:59 +0800 CST2021-09-03 09:07:59 +0800 CST 2021-09-03 09:07:59 +0800 CST

如何使用 firewalld 将特权子 1024 端口转发到非特权 1024+ 端口?

  • 772

问题

如何使用 firewalld 将特权子 1024 端口转发到非特权 1024+ 端口?

原因

我们为什么要这样做?我们希望能够切换网关上的非特权 1050 端口并使用不同的上游邮件服务器。例如,要测试不同的垃圾邮件解决方案,请使用端口 1051 将邮件发送到具有不同垃圾邮件过滤解决方案的不同邮件服务器。

邮件服务器在启动时会自动连接到网关。自动连接只能发生在 1024+ 的非特权端口上。

布局和设置

布局

+--------+         +---------------------+         +----------------+
|  WAN   |         |                1050 | <-      |                |
| Client |         |       Gateway       |    \    |   Mail Server  |
|        |  <--->  | 25                  |      -> | 25             |
+--------+         +---------------------+         +----------------+

设置防火墙

清除防火墙,打开端口,设置端口转发,添加几个服务。

root@gateway:~# firewall-cmd --reload
root@gateway:~# firewall-cmd --zone=public --add-port=25/tcp
root@gateway:~# firewall-cmd --zone=public --add-forward-port=port=25:proto=tcp:toport=1050
root@gateway:~# firewall-cmd --add-service={http,https,smtp}

验证防火墙

确认防火墙设置...

root@gateway:~# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: etho0
  sources: 
  services: dhcpv6-client http https smtp ssh
  ports: 25/tcp
  protocols: 
  masquerade: no
  forward-ports: port=25:proto=tcp:toport=1050:toaddr=
  source-ports: 
  icmp-blocks: 
  rich rules: 

这是我们期望在防火墙规则中看到的。

结果

这是我们在网关上远程登录上游邮件服务器时得到的...

root@gateway:~# telnet localhost 1050
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 debian10email.debian10email ESMTP Postfix (Debian/GNU)

这是我们从远程客户端机器上得到的......

client@client123:~$ telnet gateway.example.org 25
Trying <IP_of_gateway>...
Connected to gateway.example.org.
Escape character is '^]'.

我们期望也能看到这220 debian10email.debian10email ESMTP Postfix (Debian/GNU)条线,但没有。

完整性检查...

考试

只是为了确认正确编写了端口转发规则,我们...

  • 在防火墙上打开端口 1025。
  • 端口转发 1025 到 1050
  • 然后检查我们在远程客户端上看到的内容。

调整防火墙

清除防火墙,打开端口,设置端口转发,以及一些服务。

root@gateway:~# firewall-cmd --reload
root@gateway:~# firewall-cmd --zone=public --add-port=1025/tcp
root@gateway:~# firewall-cmd --zone=public --add-forward-port=port=1025:proto=tcp:toport=1050
root@gateway:~# firewall-cmd --add-service={http,https,smtp}

验证防火墙

root@gateway:~# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: etho0
  sources: 
  services: dhcpv6-client http https smtp ssh
  ports: 1025/tcp
  protocols: 
  masquerade: no
  forward-ports: port=1025:proto=tcp:toport=1050:toaddr=
  source-ports: 
  icmp-blocks: 
  rich rules: 

结果

client@client123:~$ telnet gateway.example.org 1025
Trying <IP_of_gateway>...
Connected to gateway.example.org.
Escape character is '^]'.
220 debian10email.debian10email ESMTP Postfix (Debian/GNU)

我们有预期的220 debian10email.debian10email ESMTP Postfix (Debian/GNU)线路,所以防火墙按预期进行端口转发。

结论

特权端口和非特权端口之间的转发不同于非特权端口之间的转发。

我们如何在 Debian 10 Buster 上使用 firewalld 将特权子 1024 端口转发到非特权 1024+ 端口?如果某处有答案,请指出。我们一直没能找到它。

port-forwarding firewalld debian-buster
  • 1 1 个回答
  • 116 Views

1 个回答

  • Voted
  1. Best Answer
    Michael Hampton
    2021-09-03T11:58:51+08:002021-09-03T11:58:51+08:00

    您的 firewalld 配置看起来正确。您测试的机器是否允许与端口 25 建立传出连接?从其他机器尝试。

    • 1

相关问题

  • 为 Cisco ASA 5510 上的端口 443/80 创建 NAT 规则和安全策略

  • 慢速路由问题

  • 通过其子网内的公共 IP 连接到默认主机是否会导致任何问题?

  • 端口镜像作为 Windows 服务

  • 使用 iptables 和 dhcpd 进行端口转发

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve