大网数据广告活动
服务器运维问答

Forward port 514 to 5514 only from specific source ip with firewalld

· 52CE 我爱测

I've been trying to find a way to forward traffic from a specific ip, eg 10.17.1.3 on port 514 to port 5514 with firewalld on CentOS This works: <masquerade/> <forward-port to-port="5514" protocol="udp" port="514"/> <forward-port…

问题原文

原帖链接 · willemdh · CC BY-SA 4.0

I've been trying to find a way to forward traffic from a specific ip, eg 10.17.1.3 on port 514 to port 5514 with firewalld on CentOS

This works:

  <masquerade/>
  <forward-port to-port="5514" protocol="udp" port="514"/>
  <forward-port to-port="5514" protocol="tcp" port="514"/>

Doesn't work:

  <masquerade/>
  <rule family="ipv4">
    <source address="10.17.1.3"/>
    <forward-port to-port="5514" protocol="udp" port="514"/>
  </rule>

Which was addded with:

sudo firewall-cmd --permanent --zone=public --add-rich-rule="rule family='ipv4' source address='10.17.1.3' forward-port protocol='udp' port='514' to-port=5514"

Is there any way to achieve port forwarding only for a specific source ip with firewalld?

已采纳解答

原帖链接 · Michael Hampton · CC BY-SA 4.0

As always, when selecting traffic by source address, you should avoid using rich rules to select by source address, and instead create a new firewalld zone which matches traffic from the relevant source addresses.

For example:

firewall-cmd --new-zone=syslogsources --permanent
firewall-cmd --reload
firewall-cmd --zone=syslogsources --add-source=10.17.1.3
firewall-cmd --zone=syslogsources --add-forward-port=port=514:proto=udp:toport=5514

And after you have confirmed it works, save it:

firewall-cmd --runtime-to-permanent

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-01-28)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。