I would like to setup a 1:1 NAT + reflection with iptables, so really forward everything which arrives on that one public IP to my internal VM.
Background Info:
I have a dedicated server running proxmox with a NAT based network configuration (see below). One NIC one public main IP (94.x.x.A
) and an extra ordered second public IP (94.x.x.B
) on the same interface.
I also have a virtualised opnsense/pfsense VM which uses vmbr10 and vmbr11 as WAN and LAN. Spoiler, I tried the 1:1 Nat via opnsense/pfsense already. I really tried everything in here but couldn't make big blue button work. I thought, okay maybe all the nat'ing through vmbr10 (WAN) into vmbr11 (LAN) and through opnsense/pfsense itself causes to much trouble for BBB. Therefore the idea was to make the routing easier.
auto enp0s31f6
iface enp0s31f6 inet static
address 94.x.x.A
netmask 255.255.255.192
gateway 94.x.x.x
mtu 1500
post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up echo 1 > /proc/sys/net/ipv6/conf/all/forwarding
up ip addr add 94.x.x.B/26 dev $IFACE label $IFACE:0
down ip addr del 94.x.x.B/26 dev $IFACE label $IFACE:0
post-up iptables -t nat -A PREROUTING -i enp0s31f6 -p tcp -d 94.x.x.A -m multiport ! --dport 22,8006,179 -j DNAT --to 10.10.10.2
post-up iptables -t nat -A PREROUTING -i enp0s31f6 -p udp -d 94.x.x.A -m multiport ! --dport 5405:5412,4789 -j DNAT --to 10.10.10.2
Now I created another linux bridge (vmbr0) and moved this one VM with Big Blue Button out of vmbr11, not going through opnsense/pfsense anymore and I would really like to forward everything to it. Iptables should absolutely not care about anything, blindly forward everything arriving at that second public IP 94.x.x.B
to my local BBB VM. So like the VM itself is directly connected to the internet. It basically owns that IP.
I tried to do it with 1:1 NAT and reflection, but no chance I could get it to work. I tried every iptables command I could find in the whole www. Simply impossible, there are two commands which simply fail all the time, no Mather what I do. They are executed on that VM itself:
docker exec -it bbb-docker-greenlight-1 bundle exec rake conf:check
Checking environment: Passed
Checking Connection: Failed
Error connecting to BigBlueButton server - Failed to open TCP connection to bbb.my-domain.com:443 (Connection refused - connect(2) for "bbb.domain-domain.com" port 443)
and
curl --trace-ascii - -k https://94.x.x.B:443/bigbluebutton/api
which immediately shows:
== Info: Trying 94.x.x.B:443...
== Info: connect to 94.x.x.B port 443 failed: Connection refused
== Info: Failed to connect to 94.x.x.B port 443: Connection refused
== Info: Closing connection 0
curl: (7) Failed to connect to 94.x.x.B port 443: Connection refused
So I have the feeling when the VM itself tries to connect to that public IP from within local vmbr0, the reflection part is not working, something is wrong. The curl command is failing immediately, like nothing listens on 443. But the nginx docker container is running, I can access the main page of the bbb service when entering the local VM IP in the browser when connected to my VPN.
Can someone with good iptable knowledge please help me to forward everything to that one VM and setup reflection? I don't think that split dns is working, as it seems that in the whole BBB docker construct, they use the public IP and not the domain name.
Collections of commands, I tried mostly whole blocks, commented out, tried a new block etc. plus single commands from each block. This topic gives me already nightmares, so please help me someone.
Thanks
auto vmbr0
iface vmbr0 inet static
address 10.2.1.1/30
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 PREROUTING -i enp0s31f6 -d 94.x.x.B -j DNAT --to 10.2.1.2
post-down iptables -t nat -D PREROUTING -i enp0s31f6 -d 94.x.x.B -j DNAT --to 10.2.1.2
post-up iptables -t nat -A POSTROUTING -o enp0s31f6 -s 10.2.1.2 -j SNAT --to-source 94.x.x.B
post-down iptables -t nat -D POSTROUTING -o enp0s31f6 -s 10.2.1.2 -j SNAT --to-source 94.x.x.B
#post-up iptables -t nat -A PREROUTING -i enp0s31f6 -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
#post-down iptables -t nat -D PREROUTING -i enp0s31f6 -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
#post-up iptables -t nat -A PREROUTING -i vmbr0 -s 10.2.1.0/30 -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
#post-down iptables -t nat -D PREROUTING -i vmbr0 -s 10.2.1.0/30 -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
#post-up iptables -t nat -A POSTROUTING -o vmbr0 -s 10.2.1.0/30 -d 10.2.1.2 -j SNAT --to-source 10.2.1.1
#post-down iptables -t nat -D POSTROUTING -o vmbr0 -s 10.2.1.0/30 -d 10.2.1.2 -j SNAT --to-source 10.2.1.1
#post-up iptables -t nat -A POSTROUTING -o enp0s31f6 -s 10.2.1.2 -j SNAT --to-source 94.x.x.B
#post-down iptables -t nat -D POSTROUTING -o enp0s31f6 -s 10.2.1.2 -j SNAT --to-source 94.x.x.B
#post-up iptables -t nat -A PREROUTING -i enp0s31f6 -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
#post-down iptables -t nat -D PREROUTING -i enp0s31f6 -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
post-up iptables -A FORWARD -s 94.x.x.B -j ACCEPT
post-down iptables -D FORWARD -s 94.x.x.B -j ACCEPT
post-up iptables -A FORWARD -d 10.2.1.2 -j ACCEPT
post-down iptables -D FORWARD -d 10.2.1.2 -j ACCEPT
#post-up iptables -P FORWARD ACCEPT
#post-up iptables -P OUTPUT ACCEPT
#post-up iptables -P INPUT ACCEPT
#post-up iptables -t nat -A POSTROUTING -o enp0s31f6 -s 10.2.1.0/30 ! -d 10.2.1.0/30 -j SNAT --to-source 94.x.x.B
#post-down iptables -t nat -D POSTROUTING -o enp0s31f6 -s 10.2.1.0/30 ! -d 10.2.1.0/30 -j SNAT --to-source 94.x.x.B
#post-up iptables -A FORWARD -i enp0s31f6 -o vmbr0 --syn -m conntrack --ctstate NEW -j ACCEPT
#post-down iptables -D FORWARD -i enp0s31f6 -o vmbr0 --syn -m conntrack --ctstate NEW -j ACCEPT
#post-up iptables -A FORWARD -i enp0s31f6 -o vmbr0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#post-down iptables -D FORWARD -i enp0s31f6 -o vmbr0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#post-up iptables -A FORWARD -i vmbr0 -o enp0s31f6 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#post-down iptables -D FORWARD -i vmbr0 -o enp0s31f6 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
#post-up iptables -A FORWARD -d 10.2.1.2/32 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
#post-down iptables -D FORWARD -d 10.2.1.2/32 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
#post-up iptables -A FORWARD -s 10.2.1.0/30 -j ACCEPT
#post-down iptables -D FORWARD -s 10.2.1.0/30 -j ACCEPT
#post-up iptables -A FORWARD -d 10.2.1.0/30 -j ACCEPT
#post-down iptables -D FORWARD -d 10.2.1.0/30 -j ACCEPT
#post-up iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
#post-down iptables -D INPUT -m state --state ESTABLISHED -j ACCEPT
#post-up iptables -t nat -A PREROUTING -i enp0s31f6 -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
#post-down iptables -t nat -D PREROUTING -i enp0s31f6 -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
#post-up iptables -t nat -A PREROUTING -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
#post-down iptables -t nat -D PREROUTING -d 94.x.x.B -j DNAT --to-destination 10.2.1.2
#post-up iptables -t nat -A POSTROUTING -o vmbr0 -d 10.2.1.2 -j SNAT --to-source 10.2.1.1
#post-down iptables -t nat -D POSTROUTING -o vmbr0 -d 10.2.1.2 -j SNAT --to-source 10.2.1.1
#post-up iptables -t nat -A PREROUTING -d 94.x.x.B -j DNAT --to 10.2.1.2
#post-down iptables -t nat -D PREROUTING -d 94.x.x.B -j DNAT --to 10.2.1.2
#post-up iptables -t nat -A POSTROUTING -s 10.2.1.2 -j SNAT --to 94.x.x.B
#post-down iptables -t nat -D POSTROUTING -s 10.2.1.2 -j SNAT --to 94.x.x.B
#post-up iptables -t nat -A POSTROUTING -s 10.2.1.0/30 -d 10.2.1.2 -j LOG --log-level info
#post-up iptables -t nat -A POSTROUTING -s 10.2.1.0/30 -d 10.2.1.2 -j SNAT --to-source 10.2.1.1
#post-down iptables -t nat -D POSTROUTING -s 10.2.1.0/30 -d 10.2.1.2 -j SNAT --to-source 10.2.1.1
#post-up iptables -t nat -A POSTROUTING -o enp0s31f6 -s 10.2.1.0/30 -j LOG --log-level info
#post-up iptables -t nat -A POSTROUTING -o enp0s31f6 -s 10.2.1.0/30 -j SNAT --to-source 94.x.x.B
#post-down iptables -t nat -D POSTROUTING -o enp0s31f6 -s 10.2.1.0/30 -j SNAT --to-source 94.x.x.B
#post-up iptables -t nat -A POSTROUTING -s 10.2.1.0/30 -j LOG --log-level info
#post-up iptables -t nat -A POSTROUTING -s 10.2.1.0/30 -j MASQUERADE
#post-down iptables -t nat -D POSTROUTING -s 10.2.1.0/30 -j MASQUERADE
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
#post-up iptables -I FORWARD -s 94.x.x.B -j ACCEPT
#post-down iptables -D FORWARD -s 94.x.x.B -j ACCEPT
#post-up iptables -I FORWARD -d 10.2.1.0/30 -j ACCEPT
#post-down iptables -D FORWARD -d 10.2.1.0/30 -j ACCEPT