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

Conversion IPTables rule to Firewalld rule to redirect

· 52CE 我爱测

I'm not very familiar with network stuff and I have difficulties to understand hay firewalld works. I'm developping a REST service, actually listening on port 8080, and I want to be able to send requests on port 80 that would be …

问题原文

原帖链接 · Cheloute · CC BY-SA 3.0

I'm not very familiar with network stuff and I have difficulties to understand hay firewalld works.

I'm developping a REST service, actually listening on port 8080, and I want to be able to send requests on port 80 that would be redirected to 8080.

To do that on CentOS 6, I used iptables and such a rule:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

I migrated on CentOS 7, and even iptables still exists and still works, the fact that firewalld is the default firewall software makes me thinking I should start to use that software... The fact is I can't understand how it works, and how to convert my single iptables rule into a firewalld one. I know that firewalld "understand" iptables rules (in fact, I'm using this rule with firewalld to keep on working), but I want to know how to do, and I would like to make this rule permanent, too.

Thanks

已采纳解答

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

Use --add-forward-port to set up a port forwarding.

From the firewall-cmd man page:

       --add-forward-port=port=portid[-portid]:proto=protocol[:toport=portid[-portid]][:toaddr=address[/mask]]
       [--timeout=timeval]
           Add the IPv4 forward port for zone. If zone is omitted, default
           zone will be used. This option can be specified multiple times. If
           a timeout is supplied, the rule will be active for the specified
           amount of time and will be removed automatically afterwards.
           timeval is either a number (of seconds) or number followed by one
           of characters s (seconds), m (minutes), h (hours), for example 20m
           or 1h.

           The port can either be a single port number portid or a port range
           portid-portid. The protocol can either be tcp, udp, sctp or dccp.
           The destination address is a simple IP address.

So you would do something like:

firewall-cmd --zone=whatever --add-forward-port=port=80:proto=tcp:toport=8080

And if it does what you want, make it permanent.

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

资料来源与适用范围

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

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

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