Hosting a VPN

In order to access some parts of my home network from abroad, I decided to host a VPN. I had a few options to begin with:

  1. rent someone else's computer (the cloud)
  2. use a computer of my own
  3. break into a friend's house and plant a computer on which I'd configured a VPN server

A lot of internet tutorials are focused on the first one, but as a cheap person who also likes using my own hardware, I wanted to go with #2: using my own network and computer. I already have hardware that can serve a VPN, and I already have a home network with internet access that I'm paying for, so the marginal cost is tiny. Less, even, than the $4/mo for a Digital Ocean droplet, which is the frontrunner for option #1.

I use pfSense for my router so the setup was actually pretty easy. I set up a certificate authority, configured the OpenVPN directly in pfSense, added the client config export package, distributed the certs and client configs, and then tested my settings to make sure it was working as expected.

First Step: Certificate Authority

Next: OpenVPN Setup in pfSense

Up next: Client Config + Cert Export and Setup

Now that the server is active, you can export settings and test connecting clients. I wanted to make sure that

To export settings, you'll need to go to System -> Package Manager, go to the Available Packages tab, and install openvpn-client-export. Once I got the client files, I set each server up using OpenVPN and made sure that a client not connected to the LAN couldn't see the LAN--thus isolating things like my desktop and steam deck from the VPN machines. It's no VLAN, but it is virtually some kind of LAN.

Setting up Automatic Connection on Boot for Client Servers (wait what)

With the client config working, I set up the OpenVPN systemd service to autoconnect for my servers, which are clients to the VPN. To do that:

  1. Move the client .ovpn file to /etc/openvpn/ and change the file extension to .conf
  2. Edit /etc/default/openvpn to have AUTOSTART="all"
  3. Make a password file with sudo nano /etc/openvpn/vpn.txt and enter:
clientusername
passwordforthisconnection12345

Then, just enable openvpn daemon with sudo enable openvpn. Now the machine should be connected and should auto-connect without you entering a password every time it restarts.

Finishing Touches: Userland Config Changes for Usability

I've been using the VPN for a few days now by using sudo openvpn vpnconfigfile.ovpn then entering my sudo password, username, and cert password. It's been good because at first, my plan was to have the VPN up only when necessary and disconnect it otherwise, but in the interest of making it a more 'permanent' tool, I finally went through the process of setting it up in NetworkManager. For simplicity's sake, I didn't even use NMTUI, I just hit my super key and typed "network" to bring up the GUI frontend my distro (LMDE) provides for NetworkManager (It also does other things, yes, I know).

It was simple, though: Hit plus in the bottom left corner, import from file, select the *.ovpn file, add the username and password--or, in my case, tell it to prompt me for it every time it connects.