I want to use my raspberry pi 3 as a wireless AP that I could connect to via my laptop or cell phone for use with my VPN subscription (PIA).
Simultaneously, I want to keep my static eth0 IP address 192.168.0.222 so that I can keep SSHing from my main PC over my LAN.
I have already set up an access point that allowed my phone to connect to the pi via wlan0 and bridge through to eth0 but not tun0. This setup kept my 192.168.0.222 for local SSH, and provided internet to my laptop and phone. But this setup didn't route traffic over wlan0 to my VPN.
I also set up the access point such that it successfully sent traffic coming into wlan0 to tun0 (tested by going to ipinfo.io on my phone while connected to raspberry pi wifi network and seeing that i was indeed connected to a VPN server somewhere far far away). But when I got this successfully set up, it stopped me from being able to SSH over LAN at all: no more 192.168.0.222 static ip, and the assigned IP didn't work in putty either.
How can I get this set up to work? I followed these guides for AP and VPN AP respectively: Raspberry Pi Wireless Access Point
https://pimylifeup.com/raspberry-pi-vpn-access-point/
I also used a script stored in /etc/ipstartup file, that is run using crontab @reboot:
ip address flush dev eth0
ip address add 192.168.0.222 dev eth0
ip link set eth0 up
ip route add default via 192.168.0.1
printf "nameserver 8.8.8.8\nnameserver 8.8.4.4" > /etc/resolv.conf
Note: The above script worked to get my eth0 connection going for the access point without vpn, but no longer kept my static ip (did it's job) when I went forward with trying to set up a VPN wireless AP.
Thanks in advance, and sorry if my unix/ networking lingo is bad!
EDIT: It works now. For anyone that might run into this issue themselves, here's what I did:
reverted all networking files to defaults (dhcpcd.conf, wpa_supplicant, etc.)
Followed this guide on setting up an access point except, and here's the important part, instead of doing step 18 I followed the troubleshooting provided by Ingo in the selected best answer below. Namely the flushing of the iptables section, and the iptables rules they provided.
- I then continued with the AP guide through to the end.
- To maintain my static IP of 192.168.0.222, I continued to use my crontab script that runs at boot.
iptables -A FORWARD -i wlan0 -o tun0 -j ACCEPT iptables -A FORWARD -i tun0 -o wlan0 -j ACCEPT iptables -t nat -A POSTROUTING -s 192.168.4.2,192.168.4.20 -o tun0 -j MASQUERADE
as suggested by this: https://www.reddit.com/r/linuxadmin/comments/34yof6/route_wlan0_traffic_trought_openvpn/ – codeNoob May 20 '18 at 16:06[worked] laptop:~ $ ping 192.168.4.1. [worked] laptop:~ $ ping 192.168.0.222. [failed] rpi3 ~$ ping -I 192.168.0.222 -nc1 8.8.8.8. [failed] rpi3 ~$ ping -I 192.168.4.1 -nc1 8.8.8.8. [failed] laptop:~ $ ping 8.8.8.8. Didn't bother trying to ping vpn tunnel. VPN confirmed to be up though on my pi. rpi3~$ ping 8.8.8.8 works fine.
– codeNoob May 27 '18 at 17:14