I am coping with an issue for the past days with which I cannot get my head arround, it addresses routing.
Setup and context:
NetworkDiagram
As depicted in the diagram below, my goal is to call the "Remote Target" from the "Source-VM". The packets need to travel through the "Router-VM" and subsequently through a VPN tunnel (here depicted by the name "GatewaySubnet" to the target 128.20.20.5).
The Router-VM is a Ubuntu machine that has two NICs associated with it.
The tunnel is working fine (the call from the "Router-VM" to the "Remote-Target" is working correctly.
But as far as the Remote-Target is concerned, the packets need to be having the "SRC=" parameter of the Nic in the subnet SNET-AKS (here 10.0.9.0/24) - as this is the only subnet whitelisted there as origin. This cannot be changed.
My question:
How do I need to configure the IPTABLES in the Router-VM so that:
The commands I have executed:
# Public interface
EXTIF="eth1"
EXTIP="10.0.25.20"
# Private interface
VPNIF="eth0"
VPNIFIP="10.0.9.4"
# Target destination
CBTARGETIP="128.20.20.5"
echo "1" > /proc/sys/net/ipv4/ip_forward
$IPTABLES -A FORWARD -i $EXTIF -o $VPNIF -p tcp --syn --dport 9080 -m conntrack --ctstate NEW -j ACCEPT
$IPTABLES -A FORWARD -i $EXTIF -o $VPNIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A FORWARD -i $VPNIF -o $EXTIF -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -t nat -A PREROUTING -i $EXTIF -p tcp --dport 9080 -j DNAT --to-destination $CBTARGETIP
$IPTABLES -t nat -A POSTROUTING -o $VPNIF -p tcp --dport 9080 -d $CBTARGETIP -j SNAT --to-source $VPNIFIP
The iptable:
~$ sudo iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
LOG tcp -- anywhere anywhere LOG level warning prefix "filter INPUT: "
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:9080 flags:FIN,SYN,RST,ACK/SYN ctstate NEW
ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
LOG tcp -- anywhere anywhere LOG level warning prefix "filter FORWARD: "
ACCEPT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
LOG tcp -- anywhere anywhere LOG level warning prefix "filter OUTPUT: "
~$ sudo iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- anywhere anywhere tcp dpt:9080 to:128.20.20.5
LOG tcp -- anywhere anywhere LOG level warning prefix "nat PREROUTING: "
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
SNAT tcp -- anywhere 128.20.20.5 tcp dpt:9080 to:10.0.9.4
LOG tcp -- anywhere anywhere LOG level warning prefix "nat POSTROUTING: "
Current result:
I have tried a lot of Googling - but I am stuck and I really, really appreciate a hint towards any mistakes or trials to debug this process, as I cannot get it to work.
I highly appreciate it - thanks a lot!
Setting up the iptables based on multiple conditions, mostly with the script mentioned above.