I’m struggling with setting source NAT(SNAT) on my newly installed AlmaLinux server(8.10, installed by the VPS provider.
I hope this server serve as a router which can forward all my vpn traffic to public network.
There is two network interface on it :
eth0 – ISP network with a static IP a.b.c.d
sh – vpn on this server with IP 192.168.0.1
My setting process:
- enable kernel forwarding:
vim /etc/sysctl.conf
net.ipv4.ip_forward=1
sysctl -p
- set Firewalld:
assign interface to zones
firewall-cmd --zone=public --add-interface=eth0 --permanent
firewall-cmd --zone=trusted --add-interface=sh --permanent
allow forward
firewall-cmd --zone=public --add-forward --permanent
I’ve tried both all source masquerade and specific source masquerade
firewall-cmd --zone=public --add-masquerade --permanent
firewall-cmd --zone=public --add-rich-rule=‘rule family=“ipv4” source address=“192.168.0.0/24” masquerade’ --permanent
reload firewalld
firewall-cmd --complete-reload
output of firewall-cmd --list-all-zones
public (active)
target: ACCEPT
icmp-block-inversion: no
interfaces: eth0
sources:
services: cockpit dhcpv6-client ssh
ports: ***
protocols:
forward: yes
masquerade: yes
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family=“ipv4” source address=“192.168.0.0/24” masquerade
rule family=“ipv4” source address=“8.8.8.8” port port=“53” protocol=“udp” accept
rule family=“ipv4” source address=“8.8.8.8” port port=“53” protocol=“tcp” accept
trusted (active)
target: ACCEPT
icmp-block-inversion: no
interfaces: sh
sources:
services:
ports: ***
protocols:
forward: no
masquerade: no
forward-ports:
port=53:proto=tcp:toport=53:toaddr=8.8.8.8
port=53:proto=udp:toport=53:toaddr=8.8.8.8
source-ports:
icmp-blocks:
rich rules:
The SNAT still not work on my server.
I’ve ping the server from other node like 192.168.0.2 and reversely, both of them works pretty good. So the vpn network is fine and other firewalld port-forward setting(port 53) on this server works too. I don’t know what is wrong. Could anyone help me please?