Part 3 - Setting up Wireguard on OPNsense

Rebuilding my network - Part 3: Settings up Wiregoard on OPNsense

Parts:

The pieces are starting to fall in place, but there are still some things that are missing to even get back to where i started to break my network..

Next piece is Wireguard, the new and hip VPN protocol.

Lets install that one too as with most other things.

https://docs.opnsense.org/manual/how-tos/wireguard-client.html

System -> Firmware -> Plugins

![Alt text](/img/user/projects/rebuilding my home network/assets/pkg_search_wireguard.png)

And poof, new menu under VPN just showed up!

![Alt text](/img/user/projects/rebuilding my home network/assets/ui_vpn_wireguard.png)

Alrighty, to set up Wireguard there is a couple of steps we need to do!

First thing first is under the Local Tab:

![Alt text](/img/user/projects/rebuilding my home network/assets/wireguard_local_settings.png)

Fill out Name, Listen Port and Tunnel address. The keys populates itsself on save.

Ignore Peers, we will create a peer for that dropdown next!

![Alt text](/img/user/projects/rebuilding my home network/assets/wireguard_endpoint_settings.png)

Fill out whatever you want for a name, and which IP's the client should be allowed to talk to. I prefer a setup where i only route 10.0.0.0/8 over the VPN.

I also duplicate a separate profile with 0.0.0.0/0, which is the same as a full tunnel.

There is one field here which needs some love, and that is the Public Key field. This is separate from the Private/Public keypair set in "Local".

We could generate both via that dialog, but we can use this as an oppertunity to get aquainted with the wireguard tooling for Linux

![Alt text](/img/user/projects/rebuilding my home network/assets/apt_search_wireguard.png)

sudo apt install wireguard wireguard-tools

When that is done we can create the keys we need!
https://www.wireguard.com/quickstart/#key-generation

wg genkey | tee privatekey | wg pubkey > publickey

This will give us the two files privatekey and publickey

Take the public key and supply it to the Endpoint configuration in OPNsense!

After you saved, go back into the Endpoint config and add your new peer to the dropdown list.

Alrighty, you are now ready to press Enable in the General tab :)

Still some more things to fix tough, lets to the Firewall++ first, then create a client cert.

When you check out this menu you will not see the Wireguard interface. Next up is adding it by going into the Assignments menu. In the dropdown select the wg* interface and give it a good name.

![Alt text](/img/user/projects/rebuilding my home network/assets/ui_if_assignments.png)

![Alt text](/img/user/projects/rebuilding my home network/assets/if_assignment.png)

This is so that we can refer to the Wireguard interace in out Firewall config, and get it managed in the outbound NAT automatically.

On that note, lets fix the outbound NAT

![Alt text](/img/user/projects/rebuilding my home network/assets/ui_firewall_nat.png)

Set the outbound nat mode to Hybrid.

We also want to create a new nat rule

This is just a super basic setup, NAT is confusing, and this works for me..

![Alt text](/img/user/projects/rebuilding my home network/assets/fw_nat_outbound_rule_blank.png)

![Alt text](/img/user/projects/rebuilding my home network/assets/firewall_nat_outbound.png)

Firewall rules next:

First one on the WAN, so that we can access Wireguard
![Alt text](/img/user/projects/rebuilding my home network/assets/wireguard_nat_rule.png)

And one in Wireguard interface, which can be used to restrict the access in your network beyond the VPN setup

![Alt text](/img/user/projects/rebuilding my home network/assets/firewall_wireguard_rule.png)

Alrighty! Now its just one thing left!

Create a client configuration.

On linux you should add this to /etc/wireguard/<name>.conf

Interface.PrivateKey -> This is the private key you created on your machine

Peer.PublicKey -> This the public key from the server

[Interface]
PrivateKey = 8GboYh0YF3q/hJhoPFoL3HM/ObgOuC8YI6UXWsgWL2M=
Address = 10.200.1.2/32
DNS = 10.100.1.1

[Peer]
PublicKey = OwdegSTyhlpw7Dbpg8VSUBKXF9CxoQp2gAOdwgqtPVI=
AllowedIPs = 10.0.0.0/8
Endpoint = wireguard.hacky.software:51820

When this file is added to for example /etc/wireguard/wg.conf.

The reason why you add it here is so that you can use wg-quick
Like so: wg-quick up wg.

This will fix all the configuration you need to get the VPN up and running

Parts: