# OpenVPN in pfSense on Yandex Cloud

> Configure OpenVPN server on pfSense in Yandex Cloud - certificate generation, tunnel setup, firewall rules, and remote client access to private network

Source: https://opennix.org/en/docs/yc/pfsense/openvpn-setup/


## Configure OpenVPN to access the private network.

1. First, the user needs to install the "openvpn-client-export package". They should go to the web interface "System --> Package manager --> Available packages" to do this. In the search bar, they should type openvpn-client-export and click install (see Figure 1).

![Installing openvpn-client-export package in pfSense](/img/openvpn-client-export.webp)
<p style="text-align: center;">Figure 1. Install the openvpn-client-export</p>

The user must wait for the installation to complete.

2. After the installation finishes the user can proceed to the settings. Click on VPN --> OpenVPN and select Wizards.
In our example, we will use local users (see Figure 2).

![OpenVPN wizard configuration in pfSense](/img/openvpn-server-st1.webp)
<p style="text-align: center;">Figure 2. Configuring openVPN-client-export</p>

The user should click the “Next” button and create a Certification Authority (CA) on the next screen. The certificate parameters are shown in Table 1.

| Name | Description |
| ------------------- | --------------------------------------------------------------------- |
| Descriptive name | Descriptive name |
| Common Name | Internal name, if empty, Descriptive name will be used |
| Country Code | Two-letter country code |
| State or Province | Full name of the state/province |
| City | City Name |
| Organization | Name of organization |
| Organizational Unit | Division/Department Name |

<p style="text-align: center;">Table 1. CA parameters</p>

3. The user can configure the OpenVPN server once the certificates are created.

The first step is to fill in the Description (see Figure 3).

![OpenVPN server description and general info](/img/openvpn-server-st2.webp)
<p style="text-align: center;">Figure 3. OpenVPN Server Information</p>

The next step is to select the Protocol, Interface, and Local Port for the new server (see Figure 4). 

![OpenVPN protocol, interface, and port selection](/img/openvpn-server-st3.webp)
<p style="text-align: center;">Figure 4. Protocol, Interface, and Port Selection</p>

The Cryptographic Settings are set according to the specified requirements.

4. The user needs to configure the tunnel (see Figure 5).

![OpenVPN tunnel configuration settings](/img/openvpn-server-st4.webp)
<p style="text-align: center;">Figure 5. Tunnel Settings</p>

The following parameters need to be filled in:

- IPv4 Tunnel Network - the network allocated to clients. It must not overlap with the user's networks.
- IPv4 Local Network - The network or networks that will be accessed from the VPN network.

Other settings are set according to the user's needs. The user needs to click Next after filling in all the required parameters. 

5. The next step is for the user to check the Firewall Rule and the OpenVPN Rule (see Figure 6).

![Firewall and OpenVPN rule configuration](/img/openvpn-server-st5.webp)
<p style="text-align: center;">Figure 6. Firewall rule configuration</p>

After the user sets the required parameters, it is necessary to click “Next” and then “Finish”. After these actions, the new server should appear in the servers list (see Figure 7). 

![OpenVPN servers list in pfSense](/img/openvpn-servers.webp)
<p style="text-align: center;">Figure 7. Servers List</p>

6. The next step is to create a new user. Select "System -> User Manager -> Users" and click the “Add” button to do this. It is necessary to specify a username and a password for it (see Figure 8).
   
![Adding a new VPN user in pfSense](/img/vpnuser.webp)
<p style="text-align: center;">Figure 8. Adding a new user</p>

7. It is necessary to configure the certificate for the user. To do this, in the “Create Certificate for Users” window, fill in all fields and select the certificate that was created during the OpenVPN server configuration (see Figure 9).
   
![Creating a user certificate for OpenVPN](/img/certificate.webp)
<p style="text-align: center;">Figure 9. Certificate Setting</p>

After filling in all the fields the user is required to click the “Save” button.

For further configuration, the user needs to go to "VPN --> OpenVPN" and open the “Client Export” tab. In the “Client Connection Behavior” section select “Other” and specify the Public IP or domain name if it is available (see Figure 10). 

![OpenVPN client connection behavior settings](/img/hostname.webp)
<p style="text-align: center;">Figure 10. Configuring Client Connection Behavior </p>

The OpenVPN Clients window requires you to select the newly created user and then export the configuration (see Figure 11). 

![OpenVPN client configuration export window](/img/export.webp)
<p style="text-align: center;">Figure 11. OpenVPN Clients </p>

The client is configured according to the required  OS.

For this guide, the test will be performed on a virtual machine without a public IP address. Once configured, it should be accessible with a VPN connection.

```shell
 ssh ubuntu@10.128.0.26
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.0-79-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Wed Aug 30 08:59:32 AM UTC 2023

  System load:  0.0                Processes:             131
  Usage of /:   23.5% of 17.63GB   Users logged in:       0
  Memory usage: 16%                IPv4 address for eth0: 10.128.0.26
  Swap usage:   0%

 * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
   just raised the bar for easy, resilient and secure K8s cluster deployment.

   https://ubuntu.com/engage/secure-kubernetes-at-the-edge

Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status

*** System restart required ***
Last login: Wed Aug 30 08:59:33 2023 from 10.0.8.2
ubuntu@test-vm:~$ 

```
The user also needs to make sure that pfSense has started tracking packets. To do this, run the following commands:

Check External IP:

```shell
ubuntu@test-vm:~$ curl -4 icanhazip.com
51.250.89.142
ubuntu@test-vm:~$ 

```
Checking that pfSense has become the gateway for the virtual machine:

```shell
ubuntu@test-vm:~$ traceroute google.com
traceroute to google.com (64.233.165.102), 30 hops max, 60 byte packets
 1  _gateway (10.128.0.1)  0.821 ms  0.801 ms  0.792 ms
 2  * * *
 3  pfsense.ru-central1.internal (10.128.0.11)  1.161 ms  1.151 ms  1.142 ms
```

As we can see after gateway 10.128.0.1 there is a LAN interface of pfSense.

This completes the configuration.


