I have successfully setup a vpn tunnel with strongswan
within a docker container and want to use that tunneled connection to forward specific ports like SMTP to a host on the other side of the tunnel, in my case host 10.0.0.10
.
The goal would be to be able to use SMTP in my app directly by connecting to strongswan-container
service in the middle like this
(smtp-host)-[IPSec-tunnel]-(strongswan-container [exposes port 25 and forwards everything to tunneled smtp-host])-[some-docker-network]-(my-mail-sending-app-container [calls strongswan-container:25 for smtp])
after reading some docs about this I tried these iptables
commands on the strongswan-container
but with no success:
iptables -t nat -A PREROUTING -p tcp --dport 25 -j DNAT --to-destination 10.0.0.10:25
iptables -t nat -A POSTROUTING -p tcp -d 10.0.0.10 --dport 25 -j MASQUERADE
on the my-mail-sending-app-container
I tried running
telnet strongswan-container 25
but it would simply wait for a response until timeout.
What is the problem with my iptables
command?
iptables-save
output after strongswan has connected to the tunnel:
root@14d43f1e2f55:/# iptables-save
# Generated by iptables-save v1.8.4 on Thu Jul 22 16:25:04 2021
*filter
:INPUT ACCEPT [1:112]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1:112]
-A INPUT -s 10.0.0.0/16 -d 192.168.112.2/32 -i eth0 -m policy --dir in --pol ipsec --reqid 1 --proto esp -j ACCEPT
-A OUTPUT -s 192.168.112.2/32 -d 10.0.0.0/16 -o eth0 -m policy --dir out --pol ipsec --reqid 1 --proto esp -j ACCEPT
COMMIT
# Completed on Thu Jul 22 16:25:04 2021
# Generated by iptables-save v1.8.4 on Thu Jul 22 16:25:04 2021
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [2:1600]
:POSTROUTING ACCEPT [2:1600]
:DOCKER_OUTPUT - [0:0]
:DOCKER_POSTROUTING - [0:0]
-A OUTPUT -d 127.0.0.11/32 -j DOCKER_OUTPUT
-A POSTROUTING -d 127.0.0.11/32 -j DOCKER_POSTROUTING
-A DOCKER_OUTPUT -d 127.0.0.11/32 -p tcp -m tcp --dport 53 -j DNAT --to-destination 127.0.0.11:46701
-A DOCKER_OUTPUT -d 127.0.0.11/32 -p udp -m udp --dport 53 -j DNAT --to-destination 127.0.0.11:58024
-A DOCKER_POSTROUTING -s 127.0.0.11/32 -p tcp -m tcp --sport 46701 -j SNAT --to-source :53
-A DOCKER_POSTROUTING -s 127.0.0.11/32 -p udp -m udp --sport 58024 -j SNAT --to-source :53
COMMIT
# Completed on Thu Jul 22 16:25:04 2021
my ipsec.conf
:
config setup
strictcrlpolicy=no
uniqueids=no
# left is local by default, left and right otherwise dynamically detected
conn %default
conn "ezvpn"
keyexchange=ikev2
aggressive=yes
ike=(some-ciphers) # Phase1 parameters
esp=(some-ciphers) # Phase2 parameters
left=192.168.112.2 # local IP used to connect to IOS
leftid=12.123.123.1 # IKEID (group name) used for IOS
leftfirewall=yes
leftauth=psk
rightauth=psk
fragmentation=yes
right=12.123.123.2 #gateway (IOS) IP
rightsubnet=10.0.0.0/16
rightfirewall=yes
auto=route
type=tunnel
ikelifetime=180m
keylife=60m