I've been working on setting up a raspberry pi as a Wifi VPN gateway, and I'm having a bit of trouble with the routing. Basically I have the pi providing a wifi hotspot, and all traffic from machines connected to that hotspot is routed through an openvpn connection to a remote server.
I have all of this working, but only when the pi sets the vpn connection as its default gateway (importing the routes the openvpn server pushes). The trouble is that I have other services running on the raspberry pi that need to access local network resources, so traffic originating from the pi itself can't be routed through the VPN, and other hosts on the wired network need to be able to access the pi as well. If I don't import the routes from the vpn server (eg, make the vpn server the default gateway), no wifi traffic is routed at all.
So, specifically, I want:
All traffic from/for hosts connected to wlan0 (192.168.1.1) routed through tun0 (10.8.0.22, gw 10.8.0.21)
All other traffic routed through eth0 (192.168.0.3, gw 192.168.0.1) as usual.
This is how I have iptables set up:
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
The routes when openvpn is the default gateway are:
Destination Gateway Genmask Flags Metric Ref Use Iface default 10.8.0.21 128.0.0.0 UG 0 0 0 tun0 default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 10.8.0.1 10.8.0.21 255.255.255.255 UGH 0 0 0 tun0 10.8.0.21 * 255.255.255.255 UH 0 0 0 tun0 ###.###.###.156 192.168.0.1 255.255.255.255 UGH 0 0 0 eth0 128.0.0.0 10.8.0.21 128.0.0.0 UG 0 0 0 tun0 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 wlan0
(###.###.###.156 is the openvpn server's public address)
Without importing the routes from openvpn, the routes are as follows:
Destination Gateway Genmask Flags Metric Ref Use Iface default 192.168.0.1 0.0.0.0 UG 0 0 0 eth0 10.8.0.21 * 255.255.255.255 UH 0 0 0 tun0 192.168.0.0 * 255.255.255.0 U 0 0 0 eth0 192.168.1.0 * 255.255.255.0 U 0 0 0 wlan0
Is what I want to do possible? Anyone have an idea how? I haven't been able to find much relevant documentation online.
Thanks in advance!
[link][1 comment]