Strongswan: clients can connect to server but no internet access
I've set up an ipsec server and after a while I could connect to it from my android device. but there is no internet connection in client side. I have also added NAT rules to forward traffics from virtual IPs but still problem exists. how can I find and solve the problem? :(
server: /etc/ipsec.conf
conn android
keyexchange=ikev2
ike=aes256-sha1-modp1024,aes128-sha256-ecp256,aes256-sha384-ecp384,aes128-sha256-modp2048,aes128-sha1-modp2048,aes256-sha384-modp4096,aes256-sha256-modp4096,aes256-sha1-modp4096,aes128-sha256-modp1536,aes128-sha1-modp1536,aes256-sha384-modp2048,aes256-sha256-modp2048,aes256-sha1-modp2048,aes128-sha256-modp1024,aes128-sha1-modp1024,aes256-sha384-modp1536,aes256-sha256-modp1536,aes256-sha1-modp1536,aes256-sha384-modp1024,aes256-sha256-modp1024!
esp=aes256-sha1,aes128gcm16-ecp256,aes256gcm16-ecp384,aes128-sha256-ecp256,aes256-sha384-ecp384,aes128-sha256-modp2048,aes128-sha1-modp2048,aes256-sha384-modp4096,aes256-sha256-modp4096,aes256-sha1-modp4096,aes128-sha256-modp1536,aes128-sha1-modp1536,aes256-sha384-modp2048,aes256-sha256-modp2048,aes256-sha1-modp2048,aes128-sha256-modp1024,aes128-sha1-modp1024,aes256-sha384-modp1536,aes256-sha256-modp1536,aes256-sha1-modp1536,aes256-sha384-modp1024,aes256-sha256-modp1024,aes256-sha1-modp1024,aes128gcm16,aes256gcm16,aes128-sha256,aes128-sha1,aes256-sha384,aes256-sha256!
dpdaction=clear
dpddelay=300s
rekey=no
left=example.com
leftfirewall=yes
leftauth=pubkey
leftsubnet=0.0.0.0/0
leftcert=example.com.crt
lefthostaccess=yes
right=%any
rightfirewall=yes
rightauth=eap-mschapv2
rightsendcert=never
rightsubnet=192.168.31.0/24
rightsourceip=192.168.31.0/24
rightdns=8.8.8.8
eap_identity=%any
type=tunnel
auto=add
ip xfrm policy
src 192.168.31.0/24 dst 0.0.0.0/0
dir fwd priority 1955
tmpl src x.x.x.x dst y.y.y.y
proto esp reqid 2 mode tunnel
src 192.168.31.0/24 dst 0.0.0.0/0
dir in priority 1955
tmpl src x.x.x.x dst y.y.y.y
proto esp reqid 2 mode tunnel
src 0.0.0.0/0 dst 192.168.31.0/24
dir out priority 1955
tmpl src y.y.y.y dst x.x.x.x
proto esp reqid 2 mode tunnel
src 0.0.0.0/0 dst 0.0.0.0/0
socket in priority 0
src 0.0.0.0/0 dst 0.0.0.0/0
socket out priority 0
src 0.0.0.0/0 dst 0.0.0.0/0
socket in priority 0
src 0.0.0.0/0 dst 0.0.0.0/0
socket out priority 0
src ::/0 dst ::/0
socket in priority 0
src ::/0 dst ::/0
socket out priority 0
src ::/0 dst ::/0
socket in priority 0
src ::/0 dst ::/0
socket out priority 0
client: strongswan vpn client for android
Solution 1:
Finally I found the problem. adding FORWARD rule to iptables
solved my problem.
Solution 2:
You may need to set up NAT, and enable forwarding in the kernel. The following two commands do this:
sudo iptables -t nat -A POSTROUTING -o YOUR_INTERFACE_NAME -j MASQUERADE
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv4.conf.all.forwarding=1
The first adds a NAT rule to the POSTROUTING chain (more info here), the second/third turns on the setting that allows the server to do any forwarding.
Note that these won't persist through a reboot without changes to sysctl.conf
. More info here