averainy's Blog

averainy

19 Jul 2022

Forwarding Ports With Firewalld

1.Enable IPv4 masquerade.

firewall-cmd --add-masquerade --permanent

2.add firewalld rule.

firewall-cmd --add-forward-port=port=80:proto=tcp:toport=8080:toaddr=192.168.10.50 --permanent

This line says to catch packets on port 80 and forward them to port 8080 on 192.168.10.50.

3.reload firewalld rules.

firewall-cmd --reload

4.if the above forward port rule does not work .maybe you need set ’net.ipv4.ip_forward = 1’ in /etc/sysctl.conf.

vi /etc/sysctl.conf

add ’net.ipv4.ip_forward = 1’ at the /etc/sysctl.conf file end.

sysctl -p

the end.