#!/bin/sh # --------- # VARIABLES # ---------## Proxmox bridge holding Public IPPrxPubVBR="vmbr0"## Proxmox bridge on VmWanNET (OPNsense WAN side)PrxVmWanVBR="vmbr1"## Proxmox bridge on PrivNET (OPNsense LAN side)PrxVmPrivVBR="vmbr2"## Network/Mask of VmWanNETVmWanNET="10.0.0.0/30"VmWanNET6="2a00:c70:1:xxx:xxx:xxx:xxx:1000/127"## Network/Mmask of PrivNETPrivNET="192.168.9.0/24"PrivNET6="2a00:0c70:0001:0xxx:0xxx:0xxx:0xxx:a000/116"## Network/Mmask of VpnNETVpnNET="10.2.2.0/24"## Public IP => Your own public IP addressPublicIP="xxx.xxx.xxx.xxx"PublicIP6="2a00:c70:1:xxx:xxx:xxx:xxx:1"## Proxmox IP on the same network than OPNsense WAN (VmWanNET)ProxVmWanIP="10.0.0.1"ProxVmWanIP6="2a00:c70:1:xxx:xxx:xxx:xxx:1000"## Proxmox IP on the same network than VMsProxVmPrivIP="192.168.9.1"## OPNsense IP used by the firewall (inside VM)OpnVmWanIP="10.0.0.2"OpnVmWanIP6="2a00:c70:1:xxx:xxx:xxx:xxx:1001" # --------------------- # CLEAN ALL & DROP IPV6 # ---------------------### Delete all existing rules.iptables -Fip6tables -Fiptables -t nat -Fiptables -t mangle -Fiptables -Xip6tables -X### This policy does not handle IPv6 traffic except to drop it.ip6tables -P INPUT DROPip6tables -P OUTPUT DROPip6tables -P FORWARD DROP # -------------- # DEFAULT POLICY # --------------### Block ALL !iptables -P OUTPUT DROPiptables -P INPUT DROPiptables -P FORWARD DROP # ------ # CHAINS # ------### Creating chainsiptables -N TCPiptables -N UDPip6tables -N TCPip6tables -N UDP# UDP = ACCEPT / SEND TO THIS CHAINiptables -A INPUT -p udp -m conntrack --ctstate NEW -j UDPip6tables -A INPUT -p udp -m conntrack --ctstate NEW -j UDP# TCP = ACCEPT / SEND TO THIS CHAINiptables -A INPUT -p tcp --syn -m conntrack --ctstate NEW -j TCPip6tables -A INPUT -p tcp --syn -m conntrack --ctstate NEW -j TCP # ------------ # GLOBAL RULES # ------------# Allow localhostiptables -A INPUT -i lo -j ACCEPTip6tables -A INPUT -i lo -j ACCEPTiptables -A OUTPUT -o lo -j ACCEPTip6tables -A OUTPUT -o lo -j ACCEPT# Don't break the current/active connectionsiptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPTip6tables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPTiptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPTip6tables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT# Allow Ping - Comment this to return timeout to ping request#iptables -A INPUT -p icmp --icmp-type 8 -m conntrack --ctstate NEW -j ACCEPTip6tables -A INPUT -p ipv6-icmp -j ACCEPT # -------------------- # RULES FOR PrxPubVBR # --------------------### INPUT RULES# ---------------# Allow SSH serveriptables -A TCP -i $PrxPubVBR -d $PublicIP -p tcp --dport ${SSHPORT} -j ACCEPTip6tables -A TCP -i $PrxPubVBR -d $PublicIP6 -p tcp --dport ${SSHPORT} -j ACCEPT# Allow Proxmox WebUI fromVPNiptables -A TCP -i $PrxVmWanVBR -d $ProxVmWanIP -p tcp --dport 8006 -j ACCEPTip6tables -A TCP -i $PrxVmWanVBR -d $ProxVmWanIP6 -p tcp --dport 8006 -j ACCEPT### OUTPUT RULES# ---------------# Allow ping outiptables -A OUTPUT -p icmp -j ACCEPTip6tables -A OUTPUT -p ipv6-icmp -j ACCEPT### Proxmox Host as CLIENT# Allow HTTP/HTTPSiptables -A OUTPUT -o $PrxPubVBR -s $PublicIP -p tcp --dport 80 -j ACCEPTip6tables -A OUTPUT -o $PrxPubVBR -s $PublicIP6 -p tcp --dport 80 -j ACCEPTiptables -A OUTPUT -o $PrxPubVBR -s $PublicIP -p tcp --dport 443 -j ACCEPTip6tables -A OUTPUT -o $PrxPubVBR -s $PublicIP6 -p tcp --dport 443 -j ACCEPT# Allow DNSiptables -A OUTPUT -o $PrxPubVBR -s $PublicIP -p udp --dport 53 -j ACCEPTip6tables -A OUTPUT -o $PrxPubVBR -s $PublicIP6 -p udp --dport 53 -j ACCEPT### Proxmox Host as SERVER# Allow SSHiptables -A OUTPUT -o $PrxPubVBR -s $PublicIP -p tcp --sport ${SSHPORT} -j ACCEPTip6tables -A OUTPUT -o $PrxPubVBR -s $PublicIP6 -p tcp --sport ${SSHPORT} -j ACCEPT# Allow PROXMOX WebUI output to VPNiptables -A OUTPUT -o $PrxVmWanVBR -s $ProxVmWanIP -p tcp --sport 8006 -j ACCEPTip6tables -A OUTPUT -o $PrxVmWanVBR -s $ProxVmWanIP6 -p tcp --sport 8006 -j ACCEPT### FORWARD RULES# ----------------### Redirect (NAT) traffic from internet# All tcp to OPNsense WAN except ${SSHPORT}iptables -A PREROUTING -t nat -i $PrxPubVBR -p tcp --match multiport ! --dports ${SSHPORT} -j DNAT --to $OpnVmWanIPip6tables -A PREROUTING -t nat -i $PrxPubVBR -p tcp --match multiport ! --dports ${SSHPORT} -j DNAT --to $OpnVmWanIP6# All udp to OPNsense WANiptables -A PREROUTING -t nat -i $PrxPubVBR -p udp -j DNAT --to $OpnVmWanIPip6tables -A PREROUTING -t nat -i $PrxPubVBR -p udp -j DNAT --to $OpnVmWanIP6# Allow request forwarding to OPNsense WAN interfaceiptables -A FORWARD -i $PrxPubVBR -d $OpnVmWanIP -o $PrxVmWanVBR -p tcp -j ACCEPTip6tables -A FORWARD -i $PrxPubVBR -d $OpnVmWanIP6 -o $PrxVmWanVBR -p tcp -j ACCEPTiptables -A FORWARD -i $PrxPubVBR -d $OpnVmWanIP -o $PrxVmWanVBR -p udp -j ACCEPTip6tables -A FORWARD -i $PrxPubVBR -d $OpnVmWanIP6 -o $PrxVmWanVBR -p udp -j ACCEPT# Allow request forwarding from LANiptables -A FORWARD -i $PrxVmWanVBR -s $VmWanNET -j ACCEPT#ip6tables -A FORWARD -i $PrxVmWanVBR -s $VmWanNET -j ACCEPT### MASQUERADE MANDATORY# Allow WAN network (OPNsense) to use vmbr0 public adress to go outiptables -t nat -A POSTROUTING -s $VmWanNET -o $PrxPubVBR -j MASQUERADE#ip6tables -t nat -A POSTROUTING -s $VmWanNET -o $PrxPubVBR -j MASQUERADEservice fail2ban restart
PublicIP6="2a00:c70:1:xxx:xxx:xxx:xxx:1"
auto loiface lo inet loopbackiface eth0 inet manualauto vmbr0iface vmbr0 inet staticaddress xxx.xxx.xxx.yyy/32gateway zzz.zzz.zzz.zzzbridge-ports eth0bridge-stp offbridge-fd 0network xxx.xxx.xxx.0dns-nameservers nnnnnnnnnnnnnnnnnnnnnnnnnnnnn#Internetiface vmbr0 inet6 staticaddress 2a00:c70:1:xxxx:xxxx:xxxx:yyyy:1/96gateway 2a00:c70:1:xxxx:xxxx:xxxx::1auto vmbr1iface vmbr1 inet staticaddress 10.0.0.1/30bridge-ports nonebridge-stp offbridge-fd 0#WANiface vmbr1 inet6 staticaddress 2a00:c70:1:xxxx:xxxx:xxxx:yyyy:a001/116auto vmbr2iface vmbr2 inet staticaddress 192.168.9.1/24bridge-ports nonebridge-stp offbridge-fd 0post-up /root/opnsense-route.shpost-up /root/iptables.sh#LANiface vmbr2 inet6 staticaddress 2a00:c70:1:xxxx:xxxx:xxxx:yyyy:ae01/120
$ ip -6 route::1 dev lo proto kernel metric 256 pref medium2a00:c70:1:xxxx:xxxx:xxxx:yyyy:ae00/120 via 2a00:c70:1:xxxx:xxxx:xxxx:yyyy:a002 dev vmbr1 metric 1024 pref medium2a00:c70:1:xxxx:xxxx:xxxx:yyyy:a000/116 dev vmbr1 proto kernel metric 256 pref medium2a00:c70:1:xxxx:xxxx:xxxx::/96 dev vmbr0 proto kernel metric 256 pref mediumfe80::/64 dev vmbr1 proto kernel metric 256 pref mediumfe80::/64 dev vmbr2 proto kernel metric 256 pref mediumfe80::/64 dev vmbr0 proto kernel metric 256 pref mediumdefault via 2a00:c70:1:xxxx:xxxx:xxxx:0:1 dev vmbr0 proto kernel metric 1024 onlink pref medium
#!/bin/sh## IP forwarding activationecho 1 > /proc/sys/net/ipv4/ip_forwardecho 1 > /proc/sys/net/ipv6/conf/all/forwarding## Rediriger les paquets destinés au LAN pour l'interface WAN de la PFSenseip route change 192.168.9.0/24 via 10.0.0.2 dev vmbr1ip -6 route add 2a00:c70:1:xxxx:xxxx:xxxx:yyyy:ae00/120 via 2a00:c70:1:xxxx:xxxx:xxxx:yyyy:a002 dev vmbr1ip -6 route del 2a00:c70:1:xxxx:xxxx:xxxx:yyyy:ae00/120 dev vmbr2## Rediriger les paquets destinés au VPN pour l'interface WAN de la PFsenseip route add 10.2.2.0/24 via 10.0.0.2 dev vmbr1
$ sudo ip6tables -S-P INPUT ACCEPT-P FORWARD ACCEPT-P OUTPUT ACCEPT