Hello,
I am facing an issue when trying to apply firewall rules on Rocky Linux 8.10, where the traffic redirection (DNAT) rules that work correctly on CentOS 7 using iptables
are not functioning on Rocky Linux 8.10, which uses nftables
by default.
Environment Configuration:
- Operating system: Rocky Linux 8.10
- Firewall:
nftables
(enabled by default on Rocky Linux 8.10) - Firewall rules I am trying to apply:
- Redirect TCP traffic arriving at port 5432 (PostgreSQL) from a specific IP (192.168.0.101) to another IP in the same network (192.168.0.102) and to the destination machine (192.168.0.103).
Problem Description:
On CentOS 7, I am able to apply the rules successfully using iptables
, and the traffic is redirected correctly. However, when I apply the same rules on Rocky Linux, the traffic is not being redirected as expected.
On Rocky Linux, the system is using nftables
, and when I try to apply the rules through iptables
(whether using iptables
or iptables-nft
), they do not seem to work properly.
Steps Iâve taken so far:
-
I enabled IP forwarding with the line
net.ipv4.ip_forward = 1
in the/etc/sysctl.conf
file and applied it withsysctl -p
, ensuring IP forwarding is enabled. -
I made sure the necessary modules for both
iptables
andnftables
are loaded, includingnf_conntrack
,nf_conntrack_ipv4
, andnf_nat
. -
I tested the rules using the
iptables-nft
command and also tried configuring directly withnft
(but with no success). -
I tried disabling
nftables
to use onlyiptables
, but the issue persists. -
firewalld disabled and mask.
Firewall rules I am applying (iptables on CentOS 7):
bash
CopiarEditar
# Enable IP forwarding (if not already done)
sysctl -w net.ipv4.ip_forward=1
# Add rule to redirect traffic from IP 192.168.0.101 on port 5432 to 192.168.0.103 on the same port
iptables -t nat -A PREROUTING -p tcp --dport 5432 -s 192.168.0.101 -j DNAT --to-destination 192.168.0.103:5432
# Ensure that the response to redirected traffic is sent back correctly
iptables -t nat -A POSTROUTING -p tcp --dport 5432 -d 192.168.0.103 -j MASQUERADE
Observed errors:
- No explicit errors in system logs, but the traffic is not being redirected as expected.
Questions:
- Has anyone encountered similar issues when using
nftables
instead ofiptables
on Rocky Linux 8? - Is there any special configuration I should perform to ensure that
iptables
rules work properly withnftables
on Rocky Linux? - Is it possible that the versions of
nftables
andiptables
on Rocky Linux 8 are causing some conflict? How can I resolve this? - Are there any other details or dependencies that might be affecting traffic redirection on Rocky Linux 8?
I would appreciate any guidance or suggestions to resolve this issue.
Best regards,