1

I am quite new to linux and Raspberry Pi world and networking in general.

I would like to add a VPN on my Pi, connect my XBOX to my Pi using LAN and have it act as a gateway of sorts so my XBOX is on the same VPN basically, and route all traffic over the Pi's wifi (WLAN).

Now i've got this working with just WLAN at the moment, but I think it's quite inefficient for the XBOX to go over the wifi to the router, to the Pi, and back to the router.

Currently I have this in my /etc/interfaces file:

auto lo
iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet manual

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
    wpa-ssid "XXX"
    wpa-psk "XXXXX"
    address 192.168.2.14
    netmask 255.255.255.0
    gateway 192.168.2.1
    dns-nameservers 192.168.2.1    

And in my /etc/rc.local file I have this:

sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
sudo iptables -A FORWARD -i tun0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o tun0 -j ACCEPT

And it's working. But i think there is quite a bit of latency because it's all happening over wifi.

Is there a way to connect the XBOX directly to my pi using a LAN cable and have the same thing working?

I've tried giving my eth0 a static IP address and trying various configurations for dns and gateway settings, but in all cases either my pi loses internet access, or my xbox (lan device) has no internet access.

I am using expressVPN if it's relevant, as i've read it does not allow level 2 routing or nat-ing.

Any help would be appreciated.

  • Which Raspbian version you have on your pi? – M. Rostami Mar 7 at 11:08
  • For what do you need a virtual private network (VPN)? Is one device outside your local network, e.g. anywhere connected through the internet? – Ingo Mar 7 at 12:42
  • Did you add iptables rules for eth0 like you did for wlan0? – Ljm Dullaart Mar 7 at 19:06
  • I have Raspberry Pi 3. Does it matter? I use VPN because many of my home devices were bought in a different country and I can no longer access the app stores for those countries, same with XBOX. But also plan to setup a Pi-hole later. iptables -> I tried a bunch of other combinations for eth0 but they didn't work. I don't quite understand it to be honest. – Quintonn Mar 7 at 20:40
  • I did try to assign my eth0 a static IP address as well and have my device connect to the Pi over ethernet instead of wifi. That works, but the device then does not have internet. I'm guessing because the pi's internet comes over wifi and i somehow need to forward the ethernet traffic over the tunnel too? I'm hoping i am missing something silly. – Quintonn Mar 7 at 20:42
0

It looks like I got it working. My /etc/network/interfaces file now looks like this auto lo iface lo inet loopback

auto eth0
allow-hotplug eth0
iface eth0 inet static
    address 192.168.0.10
    netmask 255.255.255.0
#    gateway 192.168.2.14
    dns-nameservers 192.168.2.1

auto wlan0
allow-hotplug wlan0
iface wlan0 inet static
    wpa-ssid "XXXXX"
    wpa-psk "XXXXXXXX"
    address 192.168.2.14
    netmask 255.255.255.0
    gateway 192.168.2.1
    dns-nameservers 192.168.2.1

And my /etc/rc.local files looks as follows:

sudo iptables -t nat -A  POSTROUTING -o wlan0 -j MASQUERADE

sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
sudo iptables -A FORWARD -i tun0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o tun0 -j ACCEPT

So now my device (xbox) is connected to the Raspberry Pi only via ethernet, and still has internet with and without the VPN, and my PI also has internet

And for clarity, I set my device to also have a static IP address and DNS as follows:

IP: 192.168.0.60
Subnet: 255.255.255.0
Gateway: 192.168.0.10
DNS: 192.168.2.1

The thing I was stuff with I think is the gateway and dns-nameservers values in the interfaces file, and also the DNS setting on my device.

| improve this answer | |
  • Please accept your own answer with a click on the tick on its left side. Only this will finish the question and it will not pop up again year for year. – Ingo Mar 12 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.