Tunneling your LAN into your private OpenVPN network
Intro:
In this post I want to show you my OpenVPN LAN tunneling solution 📶. I wanted to access my homeserver and NAS from outside my LAN. There are many options for this problem. You could setup a dynamic DNS service or write a script to report a changing public ip from your router. But you had to rely on for e.g. your DynDNS provider and.. yeah a public ip reporting script is shitty. Cool stuff you could do? Accessing your NAS, using your piHole to block ads or just remote control local computers and printers.
requirements
- you need a small VPS
- I’m using the stardust instance at scaleway.com (I am not getting paid by scaleway, it is just cheap)
- raspi, odroid or a small LXC container to run a OpenVPN client for 24/7
- may adjust your LAN network address
setup
- install and configure the openvpn server on your VPS instance
- create the VPN users
- configure VPN client at your raspi or LXC container
install and configure the openvpn server on your VPS instance
Well. I’m lazy and others have create some pretty nice installation scripts. I’ve used this: OpenVPN Install from Angristan at github.com
- there is many techical stuff if you want setup a secured openvpn server
- if you don’t have any knowledge about openvpn setups I recommend use this script
|
|
This command download the installation script and make it executeable.
The next step is to run it.
|
|
It will install and configure your openvpn server automatically. The setup is interactive and you could change many stuff if you want. We will adjust some settings later.
create the VPN users
|
|
Now just download your .ovpn files to your client maschines. For example with:
|
|
(you need to exchange ssh keys with ssh-copy-id before)
Then just import the .ovpn file and test the connection.
configure your LAN to VPN client
In my case I’m using an LXC container at my proxmox homeserver. I’m using a Ubuntu template for the container so..
to setup openvpn in my lxc container
|
|
than we copy our created and downloaded .ovpn file to the server and move it to:
|
|
now we activate ip-forwarding and some NAT-rules for iptables
|
|
for loading this settings after reboot create a /etc/rc.local textfile and insert:
|
|
now we start and enable our openVPN client service with:
|
|
adjust the openvpn server settings
add the following lines to your /etc/openvpn/server.conf
|
|
also we have to create the directory /etc/openvpn/ccd
|
|
now we only restart the openvpn server
|
|