Proxmox VE 8 with Firewall in Routed Configuration. Netfilter POSTROUTING SNAT not working

Jul 3, 2023
2
0
1
Hi,
since switching to Proxmox VE 8 Postrouting SNAT (Unfortunately I must use NAT) in combination with the Proxmox Firewall is not working anymore even with conntrack zones enabled.
In Proxmox VE 7 it worked after adding


Code:
post-up   iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1 
post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1



to the /etc/network/interfaces.


This is how my /etc/network/interfaces looks like
Code:
auto eno1 
iface eno1 inet static 
        address <Main public IP>/26 
        gateway <Gateway IP> 
 
 
 
 
 
 
auto vmbr0 
iface vmbr0 inet static 
        address <Main public IP>/32 
        bridge-ports none 
        bridge-stp off 
        bridge-fd 0 
        #fix for SNAT and VE Firewall 
        post-up   iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1 
        post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1 
 
 
        #SNAT for Backup 
        post-up iptables -t nat -A POSTROUTING -s <internel IP Backup>/32 -o eno1 -j SNAT --to-source <Main public IP> 
        post-down iptabels -t nat -D  POSTROUTING -s <internel IP Backup>/32 -o eno1 -j SNAT --to-source <Main public IP>


Any feedback is much appreciated.

Best regards
 
This isn't working in my case on 8.2.7 with kernel version 6.8.12-1.
I've just come across this thread after trying to understand what's happening. It's clear that the host simply ignores the SNAT rule when the VM firewall (interface + VM level) and forwards the packet without translation the source IP address, I can clearly see the difference in tcpdump.

Any ideas why this is happening or how it can be solved?
 
I realised that this rule:
-A PREROUTING -i fwbr+ -j CT --zone 1
was missing from the raw chain. After adding it, it worked. The packets need a separate conntrack zone in order for SNAT to work, otherwise they're considered "known" (so not new), and will not travel through the nat (POSTROUTING) table anymore.

Later edit: I've just realised this isn't particularly helpful, given that you're mentioning this from the very beginning :)
 
Last edited:
I face the same problem !

By default there is rules in iptables on iptables -L FORWARD -v -n --line-numbers

You should probably see that package a DROP like this :
Code:
15     513 42597 LOG        0    --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 1/sec burst 5 LOG flags 0 level 4 prefix "DROP UNMATCHED PASS-unknown:"


And to fix just do (adapt to you configuration) :
Code:
iptables -I FORWARD 1 -i vmbr9 -o vmbr0 -s 10.10.10.0/24 -j ACCEPT
iptables -I FORWARD 2 -i vmbr0 -o vmbr9 -d 10.10.10.0/24 -j ACCEPT
 
I don't think that's good advice. The firewall should take care of the FORWARD rules, and as a permanent solution I don't think you should do that. It would be a good test just for debugging purposes to see if it works. Otherwise you're interefering with the logic of the firewall. And if the firewall doesn't work as it's supposed to (of which I wouldn't be surprised), then that should be highlighted as such and brought to the attention of the developers.

If you look at the second rule in the PVEFW-FORWARD chain, which is referenced in the FORWARD chain, you'll see:
Code:
iptables -vnL PVEFW-FORWARD --line
Chain PVEFW-FORWARD (1 references)
num   pkts bytes target     prot opt in     out     source               destination
1    13664  710K DROP       0    --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
2    1509M 1488G ACCEPT     0    --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED

The second rule takes care of the conntrack, so there's no need to interfere with that by accepting and outbound and inbound traffic regardless of the conntrack.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!