I have an IPsec tunnel up and running (pure IPsec, without L2TP/GRE using strongswan 5.5.1) on Debian 9 VPS instance.
Currently it is IPv4 only so net.ipv4.ip_forward
is set to 1
in sysctl.
Clients can successfully connect to remote instance over the internet using public IP of the server.
Remote peer address is set to A.B.C.1
with /etc/network
and clients are getting addresses from subnet A.B.C.0/24
(starting from A.B.C.2
) above which is set in ipsec.conf
.
I am able to ping server from client side using its IP in this subnet.
The thing is that internet traffic can't be routed using tunnel (checking done by sending ICMP to 8.8.8.8
through ipsec tunnel). I am very concerned about my iptables-fu but I really invested tons of time to figure out what's wrong and didn't succeed anyway.
Here's related rules from my filter
iptables chain:
:INPUT DROP [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -m conntrack --ctstate INVALID -j DROP
-A INPUT -p esp -j ACCEPT
-A INPUT -p ah -j ACCEPT
-A INPUT -p udp -m udp --dport 500 -j ACCEPT
-A INPUT -p udp -m udp --dport 4500 -j ACCEPT
-A FORWARD -s A.B.C.0/24 -m policy --dir in --pol ipsec -j ACCEPT
-A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
COMMIT
And the nat
chain:
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A POSTROUTING -s A.B.C.0/24 -o <public interface> -m policy --dir out --pol ipsec -j ACCEPT
-A POSTROUTING -s A.B.C.0/24 -o <public interface> -j MASQUERADE
COMMIT
When I try to pass some requests tcpdump
gives me this consecutive lines:
18:32:21.884250 IP my.local.ip > server.public.ip: ESP(spi=...,seq=...), length 104
18:32:21.884250 IP A.B.C.2 > 8.8.8.8: ICMP echo request, id 34822, seq 1024, length 30
18:32:21.884282 IP server.public.ip > 8.8.8.8: ICMP echo request, id 34822, seq 1024, length 30
Apparently either iptables drops request to 8.8.8.8
or its response gets dropped somewhere because can't be routed back to IPsec client.
How can I route traffic correctly or at least troubleshoot the origin of the issue?
Thanks.