I'm trying to add a new rule in the PREROUTING chain in iptables (NAT) using firewall-cmd
on RHEL 7:
$ firewall-cmd --permanent --direct --add-rule ipv4 nat PREROUTING 0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 8161
Then I check the iptables via $ iptables -t nat -L
:
...
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
PREROUTING_direct all -- anywhere anywhere
PREROUTING_ZONES_SOURCE all -- anywhere anywhere
PREROUTING_ZONES all -- anywhere anywhere
...
Chain PREROUTING_direct (1 references)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8161
...
However, if I run an equivalent iptables command as follows:
...
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
PREROUTING_direct all -- anywhere anywhere
PREROUTING_ZONES_SOURCE all -- anywhere anywhere
PREROUTING_ZONES all -- anywhere anywhere
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8161
...
Chain PREROUTING_direct (1 references)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 8161
I get this additional rule in the Chain PREROUTING
and this allows prerouting to work even if the firewall is disabled (i.e., disabling firewall daemon and running the iptables
command).
So, my question is two-fold:
- Is there a
firewall-cmd
command that does exactly the same as theiptables
command above? - Can this rule be added permanently via
firewall-cmd
and stay there even after firewall daemon is disabled?