Ticker

6/recent/ticker-posts

Ad Code

Responsive Advertisement

How to set up an OpenVPN client in OPNsense

How to set up an OpenVPN client in OPNsense

OPNsense is an open-source firewall/router that’s actually a fork of pfSense, so like the latter, it’s also based on FreeBSD. You can install OPNsense on older (or newer) hardware, as long as the system has two network cards (WAN & LAN), and use OPNsense as your router. It provides more power, control, and security than most commercial routers you can buy and benefits from frequent OS updates. It’s also got an easy-to-use web-based interface through which you can configure every aspect of your router/firewall.

One thing many users do in OPNsense is configure a client OpenVPN connection to a commercial VPN provider. Doing that allows you to route all the traffic of all connected devices (PCs, tablets, smartphones) through the VPN connection. This enables you to:

  • Connect as many devices as you want to the VPN and bypass the limits on simultaneous connections that your provider may enforce.
  • Connect devices that do not natively support VPN connections, such as gaming consoles and smart TVs
  • Connect to the VPN without using a dedicated VPN application on individual devices

In this post, we’re going to look at how to set up an OpenVPN client connection to a commercial VPN provider in OPNsense. This guide assumes that you have a working OPNsense installation with at least one LAN interface and one WAN interface.

OPNsense - OpenVPNClient - Dashboard

VPN providers

Not all commercial VPN providers support OPNsense – though many do. When a VPN provider officially supports OPNsense, it’s quite easy to find all the files you need to set it up.

Other VPN providers don’t officially support OPNsense but still put the configuration files you need on their websites. Providers that support Linux usually make the necessary configuration files available. The files you need to set up an OpenVPN client connection in Linux are the same ones you would need to set it up on OPNsense.

Here’s a list of providers known to work with OPNsense (officially or unofficially). The list is not exhaustive, so there may be others.

There are different ways to connect to a VPN provider on OPNsense. For this guide, I chose the most straightforward way that works well with a basic OPNsense installation.

What you’ll need

To get this working on OPNsense, you’re going to need to obtain the following from your VPN provider’s website. VPN providers that support OPNsense (officially or unofficially) will make their configuration files available for download.

  • Your credentials: This would be a username & password, a client identifier, an account number – whatever they call it. It varies by provider. It can be any of the above. You simply need your means of identification and authentication for your account.
  • The CA certificate: The VPN provider has a Certificate Authority that validates connections to its VPN servers. To configure OPNsense as a VPN client, you’re going to need your provider’s CA certificate. It looks like this:OPNsense - OpenVPNClient - CA Certificate
  • The CA certificate private key: Some providers require you import the private key of the CA certificate. Not all do. It looks like this:OPNsense - OpenVPNClient - CA Private Key
  • The TLS key: Some VPN providers also require a TLS key to create a client connection to their servers. It is often referred to as a static key. If your VPN provider requires a static key to establish an OpenVPN connection, you’re going to need that as well. It looks like this:OPNsense - OpenVPNClient - Static Key

First, obtain the OpenVPN configuration files from your VPN provider. Once you’ve got them all, then you’re ready to start configuring the client connection in OPNsense.

Importing the CA certificate and (optionally) the key

We’re going to start by importing our VPN provider’s CA certificate.

  1. From the side menus, select System > Trust > Authorities. The Authorities page is displayed.OPNsense - OpenVPNClient - System - Trust - Authorities
  2. Click the + sign to create a new Certificate Authority. The Certificate Authority configuration page is displayed.OPNsense - OpenVPNClient - Authorities - Click Plus
  3. Enter a name for the CA is the Descriptive name field.
  4. Select Import an existing Certificate Authority from the Method drop-down menu.
  5. Paste your VPN provider’s CA certificate in the Certificate data field.
  6. If your VPN provider also includes a CA private key, you can paste it in the Certificate Private Key field. Mine does not, so I left it empty.
  7. Click Save.OPNsense - OpenVPNClient - Import CA
  8. You’re taken back to the Authorities page and we can see that our CA has been imported.OPNsense - OpenVPNClient - CA Imported

Adding an OpenVPN client connection

Now that we’ve imported our CA certificate, we can start configuring our VPN connection.

If your VPN provider explicitly supports OPNsense, the information you need to set it up will be easy to find. If your VPN provider “unofficially” supports OPNsense by supporting Linux, you can find the required information in one of the .ovpn or .conf files made available for Linux. These can be opened using a standard text editor. It will look something like this (the certificate and key have been shortened for the screenshot):

  1. From the side menus, select VPN > OpenVPN > Clients. The VPN Clients page is displayed. We’ll be configuring our OpenVPN connection section by section.OPNsense - OpenVPNClient - VPN - OpenVPN - Clients
  2. Click the + sign to create a new client connection. The Client Configuration page is displayed.OPNsense - OpenVPNClient - OpenVPN Clients - Click Plus

General Information

  1. Enter a name for your connection in the Description field.
  2. Select Peer to Peer (SSL/TLS) from the Server Mode drop-down menu.
  3. Select UDP from the Protocol drop-down menu. This can also be set to TCP if your provider supports TCP connections. UDP is usually faster and is the preferred choice for OpenVPN.
  4. Make sure the Device mode is set to tun.
  5. Select WAN from the Interface drop-down menu.
  6. Enter the VPN server’s hostname or IP address in the Remote server Host or address field.
  7. Enter the port number for your connection in the Remote server Port field.

    OPNsense - OpenVPNClient - OpenVPN Client - General Information

User Authentication Settings

  1. Enter your username in the Username field
  2. Enter your password in the Password field. If your provider does not require a password, enter anything in the password field, as OPNsense does not accept empty password fields.OPNsense - OpenVPNClient - OpenVPN Client - User Authentication Settings

Cryptographic Settings

  1. Select Enabled – Authentication only from the TLS Authentication drop-down menu. Your VPN provider may support TLS authentication and encryption. If that’s the case, select Enabled – Authentication & encryption.
  2. Paste your provider’s TLS key in the TLS Shared Key field.
  3. Select the CA you imported earlier from the Peer Certificate Authority field.
  4. Select None (Username and Password required) from the Client Certificate drop-down menu.
  5. Select an encryption algorithm that your VPN provider supports from the Encryption algorithm drop-down menu. Common algorithms are AES-CBC, AES-GCM, and CHACHA-POLY1305.
  6. Select the auth digest algorithm supported by your provider from the Auth Digest Algorithm drop-down menu. In my case, this is SHA1.OPNsense - OpenVPNClient - OpenVPN Client - Cryptographic Settings

Tunnel Settings

  1. Select Legacy – Disabled LZO algorithm (–comp-lzo-no) from the Compression drop-down menu. If your VPN provider explicitly supports a different option, you can select that instead.

That’s all we need to do in this section, but I want to highlight two additional settings:

Don’t pull routes: This setting bars the VPN server from pushing routes to the client. Some providers include the routing information in the client configuration and may ask you to enable this option (such as ExpressVPN). If this is specified by your provider, tick this option. Otherwise, leave it unticked.

Don’t add/remove routes: This option can be used to enable selective routing, sending some traffic through the VPN tunnel while sending the rest out of the ISP gateway. This requires setting the VPN interface (which we will create below) as a gateway in OPNsense and specifying some additional firewall and NAT rules to get it working. This is outside the scope of this guide. Also, in your typical commercial VPN scenario, you want all your traffic tunneled through the VPN connection. Leave this setting unticked.

2. Click Save. OPNsense - OpenVPNClient - OpenVPN Client - Tunnel & Advanced Settings

Creating the VPN interface

The next thing we need to do is create the virtual interface that will host the VPN network segment-–the subnet you become a part of after a successful VPN connection—on our OPNsense box.

The interface was automatically created by OPNsense when we hit save after configuring our connection earlier. But we still need to assign and configure it.

  1. From the side menus, select Interfaces > Assignments. The Interface Assignments page is displayed.OPNsense - OpenVPNClient - Interface - Assignments
  2. From the New Interface drop-down menu, select ovpnc1 and click the + button to its right.OPNsense - OpenVPNClient - Interfaces - Clieck Plus
  3. The new interface is added to the list. Click the new interface name to enable it.
  4. Tick Enable interface. Leave all of the other settings untouched.
  5. Click Save.OPNsense - OpenVPNClient - Interfaces - Save
  6. Click Apply Changes. The OpenVPN interface is now enabled.OPNsense - OpenVPNClient - Interfaces - Apply Changes

Configuring NAT rules

The next thing we need to do is to configure our Network Address Translation (NAT) rules to properly route our traffic through the VPN.

  1. From the side menus, select Firewall > NAT > Outbound. The Outbound NAT page is displayed.OPNsense - OpenVPNClient - Firewall - NAT - Outbound
  2. Set the Mode to Manual outbound NAT rule generation, and then click Save.OPNsense - OpenVPNClient - Manual Outbound NAT - Save
  3. Click Apply Changes.OPNsense - OpenVPNClient - Manual Outbound NAT - Apply Changes
  4. Click the + sign to add a new outbound NAT rule. The Outbound NAT Rule Configuration page is displayed.OPNsense - OpenVPNClient - Manual Outbound NAT - Click Plus
  5. From the Interface drop-down menu, select the OpenVPN interface we created earlier.
  6. From the Source address drop-down menu, select LAN.net.
  7. Make sure the Translation/target drop-down menu is set to Interface address.
  8. Enter a name for your NAT rule in the Description field.
  9. Click Save.OPNsense - OpenVPNClient - Manual Outbound NAT - Rule - Save
  10. Click Apply Changes. Our NAT rule has been created and is now listed.OPNsense - OpenVPNClient - Manual Outbound NAT Rule Created - Apply Changes

DNS

The last thing we need to configure is DNS for your VPN client.There are different ways to do this depending on your OPNsense configuration. Even if your VPN provider hardcodes its DNS servers in their .ovpn configuration file, OPNsense still needs to be aware of the DNS servers to be used. We’ll be using the LAN DHCP server to push the VPN provider’s DNS servers to our LAN clients, because this method works in any scenario.

DHCP

  1. From the side menus, select Services > DHCPv4 > LAN. The LAN DHCP Server page is displayed.OPNsense - OpenVPNClient - Services _ DHCP - LAN
  2. Enter your VPN provider’s DNS server IP(s) in the DNS Servers field(s).
  3. Click Save at the bottom of the page.OPNsense - OpenVPNClient - DHCP - Save

Checking the connection

OK, we now have our OpenVPN client connection configured. We’ve created our VPN interface as well as our NAT rules to route our traffic through the VPN tunnel, and we’ve configured our DNS settings to use the VPN provider’s DNS servers. We simply need to check that everything is working correctly and test our connection.

Checking the connection status

  1. From the side menus, select VPN > OpenVPN > Connection Status. The OpenVPN Connection Status page is displayed.OPNsense - OpenVPNClient - Connection Status
  2. We can see Connected, under the Status header. That’s what we want. So far, so good.OPNsense - OpenVPNClient - Check Connection Status

Checking the logs

  1. From the side menus, select Log File (we’re already in the OpenVPN section). The OpenVPN Logs page is displayed.OPNsense - OpenVPNClient - Log File
  2. If the OpenVPN client is set up correctly, you should see Initialization Sequence Completed, somewhere near the top of the OpenVPN logs. We’re good.OPNsense - OpenVPNClient - Check Logs

Making sure our IP address is changed

  1. To make sure your IP address is changed to the IP address of the VPN server, you can use Comparitech’s IP address check tool.OPNsense - OpenVPNClient - Comparitech IP Check
  2. My IP address has been changed to the VPN server’s IP. You can also check for DNS leaks at dnsleaktest.com.

Wrapping up

Congratulations, you’ve successfully configured an OpenVPN client connection on OPNsense.

You can now use your commercial VPN with any device connected to your OPNsense box without a dedicated VPN app. And because you’re not relying on a VPN client app, your chances of randomly disconnecting from the VPN are much smaller. Also, regardless of the limit your VPN provider places on the number of simultaneous connections, your router only counts as one device as far as your VPN provider is concerned. So you can connect as many devices as you like this way.

As always, stay safe.

L’article How to set up an OpenVPN client in OPNsense est apparu en premier sur Comparitech.

Enregistrer un commentaire

0 Commentaires