pfsense with Always-On Load Balanced OpenVPN Connections for all your Internet Traffic

pfsense with Always-On Load Balanced OpenVPN Connections for all your Internet Traffic

Following this guide will allow you to create always-on load-balanced OpenVPN connections to your favorite VPN provider and force all your Internet traffic through the OpenVPN connections.

This guide was developed using Newshosting VPN account. The information contained will probably work with most other VPN providers with little or no modifications.

This guide is written for the privacy conscious who do not want their activities monitored by their ISP or other entities since the OpenVPN traffic is encrypted.

This guide is NOT written in order to assist you in conducting nefarious activities on the Internet undetected. A simple VPN connection is not enough to completely hide your digital tracks. Be warned!!

Import VPN Provider CA Certificate

  1. Obtain the CA Certificate from the VPN Provider. 
  2. Navigate to System --> Cert. Manager.
  3. Click the Add button.
  4. Under the Descriptive name field, enter a description for the CA certificate your are importing.
  5. Under the Certificate data, paste the certificate contents including the -----BEGIN CERTIFICATE----- and the -----END CERTIFICATE----- parts.
  6. Click the Save button (Figure 1).

Figure 1

 

Create OpenVPN client connections

  1. Navigate to VPN --> OpenVPN --> Clients.
  2. Click the Add button.
  3. In the Server Mode field, ensure Peer to Peer (SSL/TLS) is selected.
  4. In the Protocol field, select either UDP on IPv4 Only or TCP on IPv4 Only depending on your VPN provider's requirements. Most of the time, UDP on port 1194 is used.
  5. In the Device mode field, ensure tun - Layer 3 Tunnel Mode is selected.
  6. In the Interface field, ensure WAN is selected.
  7. In the Server host or address field, enter the address to your VPN provider's OpenVPN server.
  8. In the Server port field, enter the port number to your VPN provider's OpenVPN server (most likely 1194).
  9. In the Description field, enter a description for this connection if desired (Figure 2).

Figure 2

  1. In the Username field, enter the username for your VPN Provider.
  2. In the Password field, enter the password for your VPN Provider.
  3. Ensure the Use a TLS Key field is unchecked.
  4. In the Peer Certificate Authority field, ensure you select the CA that you created in the import VPN Provider CA Certificate section above.
  5. In the Client Certificate field, ensure that None (Username and/or Password required) is selected. Please note that this field may need to be adjusted to your VPN provider's requirements, however most of the VPN providers I've used, Username/Password has been sufficient.
  6. In the Encryption Algorithm field, select the highest encryption that your VPN provider supports. I've used AES-256-CBC (256 bit key, 128 bit block) with no problems (Figure 3).

Figure 3

  1. Ensure the Enable NCP field is unchecked.
  2. In the Auth digest algorithm field, select the auth digest algorithm supported by your VPN provider. I've used SHA256 (256-bit) with no problems.
  3. In the Hardware Crypto field, ensure No Hardware Crypto Acceleration is selected (Figure 4).

Figure 4

  1. In the Compression field, ensure that Adaptive LZO Compression [Legacy style, comp-lzo adaptive] is selected.
  2. Ensure Don't add or remove routes field is checked.
  3. In the Custom options field, paste the following options (Figure 5):
persist-key;
persist-tun;
persist-remote-ip;
resolv-retry infinite;

Figure 5

  1. Click the Save button.
  2. Create additional OpenVPN client connections as needed.

Verify OpenVPN Client Connections are Up

  1. Navigate to Status --> OpenVPN. Under the Client Instance Statistics section, you should be able to see the connections you created and ideally if configured correctly, the status for each connections should be up (Figure 6).

Figure 6

 

Assign Interfaces to each OpenVPN Connection

  1. Navigate to Interfaces --> Assignments.
  2. Next to the Available network ports field, select each of the OpenVPN connections you created earlier from the Network port drop-down field and click the Add button to assign the network port. The OpenVPN connections are named ovpncX where X is number assigned by the system. In this example, I created two OpenVPN connections and they are named ovpnc4 for newshosting.com OpenVPN 1 connection and ovpnc5 for newshosting.com OpenVPN 2 connection (Figure 7).

Figure 7

  1. Assign all the OpenVPN connections you created and you will end up with your OpenVPN connections having been assigned an OPTX interface name where X is a number assigned by the system. Ensure you click the Save button at the bottom of the screen to save your changes. (Figure 8).

Figure 8

  1. Next, click on each of the OPTX interfaces that were assigned to your OpenVPN connections and you will be re-directed to the Interfaces / OPTX configuration page where X is the interface number assigned by the system.
  2. Ensure the Enable field is checked.
  3. In the Description field enter a name for this connection (Ex: NewsHostingOpenVPN1).
  4. Ensure IPv4 Configuration Type is set to None.
  5. Ensure IPv6 Configuration Type is set to None (Figure 9).

    Figure 9

    1. Click the Save button at the bottom of the page and then click the Apply Changes that appears on the top of the page after clicking the Save button.
    2. Navigate back to Interfaces --> Assignments and repeat Steps 9 through 14 from above to assign the rest of the OpenVPN connections.
    3. In the end you should end  up with a listing like below under Interfaces -->Assignments (Figure 10).

    Figure 10

    Create OpenVPN Gateway Group

    In this section, we are going to be creating a Gateway Group that's going to include all the OpenVPN gateways that were automatcially created by the system when we assigned the OpenVPN connections to Interfaces in the previous section. Using this method, we willl be having more than one connection available for load balancing as well as failover in case one of the OpenVPN connections goes down. You will notice below that we will give both OpenVPN gateways the same priority (Tier 1) which will effectively create a load-balanced connection using multiple OpenVPN gateways.

    1. Navigate to System --> Routing and ensure the Gateways tab is selected. You should be able to IPv4 gateways, denoted by a _VPNV4 suffix and IPv6 gateways, denoted by a _VPNV6 suffix entries for each interface you assigned to an OpenVPN connection from the section above. (Figure 11).

    Figure 11

    1. Next, click on the Gateway Groups tab and then click the Add button (Figure 12).

    Figure 12

    1. You will be re-directed to the Edit Gateway Group Entry page
    2. In the Group Name field, enter a name for your Gateway Group (Ex: OpenVPNGatewayGroup).
    3. Under the Gateway Priority section, ensure your main WAN gateway is set to Never.
    4. Ensure all the OpenVPN IPv4 gateways denoted with a _VPNV4 suffix are set to Tier 1. Ensure that any OpenVPN IPv6 gateways denoted with a _VPNV6 suffix are NOT set to Tier 1 and if necessary be set to Never just like the main WAN gateway.
    5. Ensure the Trigger Level field is set to Member down
    6. Optionally, enter a description in the Description field.
    7. Click the Save button (Figure 13).

    Figure 13

    1. You will be re-directed back to Gateway Groups page where the you will be able to see the Gateway Group you just created. Click on the Apply Changes button on the top of the page to apply your changes (Figure 14).

    Figure 14

    Create Firewall Rules

    In this section, we are going to create a floating firewall rule to Reject any LAN outbound packets that are tagged as NO_WAN_OUTBOUND and then we are going to create a LAN rule that will tag all traffic as NO_WAN_OUTBOUND as well as use the OpenVPNGatewayGroup we created in the section above as the default gateway for that traffic. Using this method, we are going to ensure that ALL LAN traffic will ONLY go through the OpenVPN connections. 

    1. Navigate to Firewall --> Rules and ensure the Floating tab is selected. (Figure 15).

    Figure 15

    1. Click the Add button with the down arrow on the bottom of the page to add a rule to the end of the list (Figure 16).

    Figure 16

    1. You will be re-directed to the Edit firewall Rule page.
    2. In the Action field ensure Reject is selected.
    3. In the Interface field ensure the WAN interface is selected.
    4. In the Direction field ensure out is selected.
    5. In the Address Family ensure IPv4 is selected.
    6. In the Protocol field ensure Any is selected(Figure 17).

    Figure 17

    1. In the Log field, check the Log packets that are handled by this rule.
    2. In the Description field, enter the following description: Reject Packets tagged with NO_WAN_OUTBOUND.
    3. In the Advanced Options field, click Display Advanced button (Figure 18).

    Figure 18

    1. Clicking the Advanced Options button from the previous step, will display the Advanced Options section.
    2. In the Tagged field, enter the following: NO_WAN_OUTBOUND (Figure 19)Ensure you make a note of the NO_WAN_OUTBOUND tag because we are going to be using it in LAN rule we are going to be creating next.

    Figure 19

    1. Click the Save button at the bottom of the page.
    2. You will be re-directed back to the Floating rules tab page.
    3. Click on the Apply Changes button on the top of the page to apply the changes (Figure 20).

    Figure 20

    1. Next click on the LAN tab (Figure 21).

    Figure 21

    1. Click the Add button with the down arrow on the bottom of the page to add a rule to the end of the list (Figure 22).

    Figure 22

    1. You will be re-directed to the Edit firewall Rule page.
    2. In the Action field ensure Pass is selected.
    3. In the Disabled field ensure Disable this rule is Unchecked.
    4. In the Interface field ensure the LAN interface is selected.
    5. In the Address Family ensure IPv4 is selected.
    6. In the Protocol field ensure Any is selected (Figure 23).

    Figure 23

    1. Under the Source section, in the Source field, ensure LAN net is selected.
    2. Under the Destination section, in the Destination field, ensure any is selected.
    3. Under the Extra Options section, in the Log field, ensure Log packets that are handled by this rule is checked.
    4. Under the Extra Options section, in the Description field, enter a description for this rule (Ex: Allow LAN to any via VPN Only).
    5. Under the Extra Options section, in the Advanced Options field, click the Display Advanced button (Figure 24).

    Figure 24

    1. Clicking the Advanced Options button from the previous step, will display the Advanced Options section.
    2. Under the Advanced Options section, in the Tag field, enter NO_WAN_OUTBOUND (Figure 25).

    Figure 25

    1. Under the Advanced Options section, in the Gateway field, ensure the OpenVPNGatewayGroup gateway is selected (Figure 26).

    Figure 26

    1. Click the Save button at the bottom of the page.
    2. You will be re-directed back to the LAN rules tab page.
    3. Click on the Apply Changes button on the top of the page to apply the changes (Figure 27).

    Figure 27

    Create a Rule to Bypass OpenVPN Connections

    If you have a need for certain IPs inside your LAN to bypass the OpenVPN connections and go through the WAN gateway like normally, you would simply create a LAN rule and place it ABOVE the Allow LAN to any via VPN Only rule we created above.

    1. Navigate to Firewall --> Aliases and ensure IP tab is selected (Figure 28).

    Figure 28

    1. Click the Add button at the bottom of the page.
    2. You will be re-directed to the Firewall / Aliases / Edit page.
    3. Under the Properties section, in the Name field, enter a name for this alias (Ex: Outbound_Direct_NO_VPN). Ensure you take note of the alias name you assigned because we are going to use it in the LAN rule we will be creating below.
    4. Under the Properties section, in the Type field, ensure Host(s) is selected (Figure 29).

    Figure 29

    1. Under the Host(s) section, enter any LAN IPs (one per line) that you want to bypass the OpenVPN connections (You can add more lines by clicking the Add Host button at the bottom of the page). 
    2. When finished, click the Save button at the bottom of the page (Figure 30). 

    Figure 30

    1. You will be re-directed back to the Aliases IP tab page.
    2. Click on the Apply Changes button on the top of the page to apply the changes (Figure 31).

    Figure 31

    1. Next, navigate to Firewall --> Rules and ensure the LAN tab is selected. (Figure 32).

    Figure 32

    1. Click the Add button with the up arrow on the bottom of the page to add a rule to the top of the list (Figure 33).

    Figure 33

    1. You will be re-directed to the Edit firewall Rule page.
    2. In the Action field ensure Pass is selected.
    3. In the Disabled field ensure Disable this rule is Unchecked.
    4. In the Interface field ensure the LAN interface is selected.
    5. In the Address Family ensure IPv4 is selected.
    6. In the Protocol field ensure Any is selected.
    7. Uder the Source section, in the Source field, ensure Single host or alias is selected and then enter the name of the alias you created above (Outbound_Direct_NO_VPN).
    8. Under the Destination section, in the Destination field, ensure any is selected (Figure 34).

    Figure 34

     

    1. Under the Extra Options section, in the Log field, ensure Log packets that are handled by this rule is checked.
    2. Under the Extra Options section, in the Description field, enter a description for this rule (Ex: Allow LAN to any rule NO VPN) (Figure 35).

    Figure 35

     

    1. Click the Save button at the bottom of the page.
    2. You will be re-directed back to the LAN rules tab page.
    3. Click on the Apply Changes button on the top of the page to apply the changes (Figure 36).

    Figure 36

    This concludes our guide. Questions or feedback are always welcome. Feel free to post them below.


    Hermes Secure Email Gateway - Free Open Source Unified Secure Email Gateway