DNAT/SNAT via pve-firewall PREROUTING/POSTROUTING

Discussion in 'Proxmox VE: Networking and Firewall' started by tirili, Nov 27, 2018.

  1. tirili

    tirili Member

    Joined:
    Sep 19, 2018
    Messages:
    40
    Likes Received:
    0
    Hello,

    is there any way to configure DNAT, and SNAT to hosts via pve-firewall?

    Currently we use for outgoing connections:

    iptables -t nat -A POSTROUTING -s 192.168.64.0/24 -o vmbr0 -j SNAT --to-source 5.7.9.99
    iptables -t nat -A POSTROUTING -s 192.168.80.102/32 -o vmbr0 -j SNAT --to-source 5.7.9.102

    and for incoming connections:

    iptables -t nat -A PREROUTING -d 5.7.9.102/32 -p tcp -m tcp --dport 443 -j DNAT --to-destination 192.168.80.102:443
    iptables -t nat -A PREROUTING -d 5.7.9.101/32 -p tcp -m tcp --dport 443 -j DNAT --to-destination 192.168.80.101:443

    But when restarting pve-firewall, these are lost.
    Any help is appreciated.

    Best regards
    Thomas
     
  2. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    3,132
    Likes Received:
    479
    pve-firewall should leave the nat table alone.. are you sure it's not something else interfering?
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. tirili

    tirili Member

    Joined:
    Sep 19, 2018
    Messages:
    40
    Likes Received:
    0
    The question is, how could it be done using the pve-firewall completely? I do not want to have 2 locations where I have to change firewall rules.
     
  4. fabian

    fabian Proxmox Staff Member
    Staff Member

    Joined:
    Jan 7, 2016
    Messages:
    3,132
    Likes Received:
    479
    pve-firewall does not support setting up NAT / port forwarding / .. (yet). it would be a nice addition though!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. spirit

    spirit Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 2, 2010
    Messages:
    3,197
    Likes Received:
    111
    Hi,also, if you need to use firewall + nat, it's need conntrack zones :



    iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1
    iptables -t raw -I POSTROUTING -i fwbr+ -j CT --zone 1
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. Mikus

    Mikus New Member

    Joined:
    Apr 13, 2018
    Messages:
    8
    Likes Received:
    0
    Dear Spirit, in case of SNAT/DNAT, do we really need add POSTROUTING rule? In my case PVE firewall works for outgoing rules without POSTROUTING rule (PVE 5.2).

    Code:
    allow-hotplug eth0
    iface eth0 inet static
            address 192.168.XX.XX
            netmask 255.255.255.0
            gateway 192.168.XX.XX
    
    auto vmbr0
    iface vmbr0 inet static
            address  10.10.XX.XX
            netmask  255.255.255.0
            bridge_ports none
            bridge_stp off
            bridge_fd 0
    
            post-up echo 1 > /proc/sys/net/ipv4/ip_forward
    
            post-up   iptables -t nat -A POSTROUTING -s 10.10.xx.x/24 -o eth0 -j SNAT --to-source 192.168.XX.XX
            post-down iptables -t nat -D POSTROUTING -s 10.10.xx.x/24 -o eth0 -j SNAT --to-source 192.168.XX.XX
    
            post-up   iptables -t raw -I PREROUTING  -i fwbr+ -j CT --zone 1
    


    Also I wonder, how pve-firewall works on outgoing traffic rules. For example, if I define blocking outgoing rule on cluster/node level, rule affects host, not VMs. If I define blocking outgoing rule on VM level, everything is fine. Why so? Why outgoing blocking rule on cluster/node level do not affects VMs?
     
  7. spirit

    spirit Well-Known Member
    Proxmox VE Subscriber

    Joined:
    Apr 2, 2010
    Messages:
    3,197
    Likes Received:
    111
    >> If I define blocking outgoing rule on VM level, everything is fine. Why so? Why outgoing blocking rule on cluster/node level do not >>affects VMs?

    because cluster/node level rules are iptables INPUT/OUPUT chain , and vm rules are in FORWARD chain.

    (cluster/node level rules are only used to protected your host , not your vms)
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice