{"id":9233,"date":"2024-02-29T13:09:38","date_gmt":"2024-02-29T13:09:38","guid":{"rendered":"https:\/\/cheapwindowsvps.com\/blog\/step-by-step-guide-to-installing-wireguard-vpn-on-opnsense-firewall\/"},"modified":"2025-01-20T11:34:16","modified_gmt":"2025-01-20T11:34:16","slug":"step-by-step-guide-to-installing-wireguard-vpn-on-opnsense-firewall","status":"publish","type":"post","link":"https:\/\/cheapwindowsvps.com\/blog\/step-by-step-guide-to-installing-wireguard-vpn-on-opnsense-firewall\/","title":{"rendered":"Step-by-Step Guide to Installing WireGuard VPN on OPNsense Firewall"},"content":{"rendered":"<div>If you are employing an OPNsense firewall, the option to configure WireGuard as a VPN server instead of OpenVPN is a viable option. WireGuard&#8217;s clients are available for all major operating systems, proving very fast and lightweight. This can easily be installed as an OPNsense extension and configured via the web console.<\/div>\n<p>For implementing a VPN Infrastructure with WireGuard on OPNSense, the following steps have to be executed:<\/p>\n<ol>\n<li>Install WireGuard<\/li>\n<li>Construct and configure a WireGuard instance<\/li>\n<li>Implement a network interface for the VPN server<\/li>\n<li>Develop a firewall rule for VPN<\/li>\n<li>Download and calibrate WireGuard client<\/li>\n<li>Classify clients on the VPN server<\/li>\n<li>Examine the connection to the WireGuard server<\/li>\n<\/ol>\n<h2>How to integrate WireGuard as an extension<\/h2>\n<p>WireGuard VPN needs to be installed initially via <em>System =&gt; Firmware =&gt; Extensions<\/em>. The label for this is <em>os-wireguard<\/em>. Post installation, you can find a new item titled <em>WireGuard<\/em> under the <em>VPN<\/em> menu. If this is not visible, you could try refreshing your browser.<\/p>\n<p><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/02\/WireGuard-is-installed-as-an-OPNsense-extension.png\" target=\"_blank\" rel=\"nofollow noopener\">WireGuard is installed as an OPNsense extension<\/a><\/p>\n<h2>Creating a new WireGuard instance<\/h2>\n<p>First off, you should create a new WireGuard server on the Instances tab, which is found under <em>VPN =&gt; WireGuard<\/em>. This can be done by clicking the &#8216;+&#8217; sign. It is possible to run multiple servers on an OPNsense firewall with WireGuard &#8211; give your new server a name that will appear on the interface.<\/p>\n<div><\/div>\n<p>Configuring a new WireGuard server<\/p>\n<p>For <em>Listen Port<\/em>, specify the TCP port on which the VPN server will listen for requests. This must also be unlocked in the firewall later. For <em>Tunnel address<\/em>, enter the subnet where the VPN interface and the clients will be located.<\/p>\n<p>In our example, we work with the subnet 172.16.2.1\/24, where the VPN interface receives the IP address 172.16.2.1.<\/p>\n<p>All other fields do not need to be filled. You can disable routes here if you want to create the routing rules yourself. After saving the server&#8217;s configuration in OPNsense, click <em>Apply<\/em>.<\/p>\n<div><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/02\/Overview-of-the-created-WireGuard-instances.png\" target=\"_blank\" rel=\"nofollow noopener\">Overview of the created WireGuard instances<\/a><\/div>\n<p>OPNsense automatically generates a public key for the VPN server. The key is later needed for the handshake with the clients.<\/p>\n<p>If you open the server&#8217;s configuration again, the public key and private key fields are automatically filled in. Copy the key to a text file because we will need it later.<\/p>\n<p>Then, you can activate WireGuard under <em>General<\/em>, which must be confirmed again by applying.<\/p>\n<p><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/02\/Activating-the-WireGuard-server-on-OPNsense.png\" target=\"_blank\" rel=\"nofollow noopener\">Activating the WireGuard server on OPNsense<\/a><\/p>\n<p>Activating the WireGuard server on OPNsense<\/p>\n<h2>Configuring network interfaces for WireGuard<\/h2>\n<p>To connect the VPN with OPNsense, the configuration of the VPN interface is required under <em>Interfaces<\/em>. Under <em>Assignments<\/em>, the existing interfaces are visible. Here, create the new interface and assign it to the WireGuard VPN.<\/p>\n<p><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/02\/Assigning-an-interface-to-the-VPN-server.png\" target=\"_blank\" rel=\"nofollow noopener\">Assigning an interface to the VPN server<\/a><\/p>\n<p>Assigning an interface to the VPN server<\/p>\n<p>By clicking on the new interface, the window with its configuration opens. Here, activate it via the respective checkbox. Moreover, I recommend setting <em>Prevent interface removal<\/em> to avoid accidental deletion.<\/p>\n<p><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/02\/Configuration-of-the-network-interface-for-the-VPN-server.png\" target=\"_blank\" rel=\"nofollow noopener\">Configuration of the network interface for the VPN server<\/a><\/p>\n<p>Unbound DNS can be set up on OPNsense for name resolution in the internal network.<\/p>\n<p><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/02\/OPNsense-also-offers-a-DNS-service.png\" target=\"_blank\" rel=\"nofollow noopener\">OPNsense also offers a DNS service<\/a><\/p>\n<h2>Creating firewall rules for WireGuard VPN<\/h2>\n<p>Next, create a rule under <em>Firewall =&gt; Rules =&gt; WAN<\/em> that allows access to the VPN server over the internet.<\/p>\n<p>Select the action <em>Allow<\/em> and the interface <em>WAN<\/em> when defining a new rule. For <em>Destination<\/em>, choose the option <em>in<\/em>; for <em>TCP\/IP Version<\/em>, select IPv4; for <em>Protocol<\/em>, select <em>UDP<\/em>; and for <em>Source<\/em>, select <em>Any<\/em>.<\/p>\n<p>It is crucial to select the <em>Destination port range<\/em> under <em>from<\/em> and for <em>to<\/em> to set the port number given during the server&#8217;s creation. The setting can be found under <em>VPN =&gt; WireGuard<\/em>. At this point, you can also activate the option <em> Log packets that are handled by this rule<\/em>.<\/p>\n<div><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/02\/Defining-firewall-rules-for-the-VPN-network.png\" target=\"_blank\" rel=\"nofollow noopener\">Defining firewall rules for the VPN network<\/a><\/div>\n<p>With another rule, you specify how the traffic of the VPN clients is forwarded to the internal network. When clients connect via VPN, they initially find themselves in the VPN network, whose IP range was specified during the creation of the server.<\/p>\n<p>From this point, they need to access the respective applications in the local network. The configuration of these rules can be done through <em>Firewall =&gt; Rules =&gt; &lt;WireGuard Interface&gt;<\/em>. It&#8217;s recommended to design these rules in such a way that VPN clients can only access the necessary devices.<\/p>\n<p>For doing so, when creating a new rule, select the action <em>Allow<\/em> and the interface of WireGuard. For the <em>Direction<\/em> option, choose <em>in<\/em>, and for the <em>Protocol<\/em> option, choose <em>any<\/em>. Concerning <em>Source and Destination<\/em>, you can select <em>any<\/em> if you wish to allow access to all resources in the network.<\/p>\n<div><\/div>\n<p>Firewall rule controlling access to internal resources<\/p>\n<h2>Installing and adjusting WireGuard clients<\/h2>\n<p>Afterward, install the WireGuard client, for example, <a href=\"https:\/\/www.wireguard.com\/install\/\" target=\"_blank\" rel=\"nofollow noopener\">on Windows<\/a>. Then, you can configure a new connection by adding a tunnel.<\/p>\n<p>In the first step, assign a name for the VPN connection. Save the value for <em>Public Key<\/em> again in a text file, as it needs to be entered on the server later.<\/p>\n<p>Under <em>Interface<\/em>, provide the IP address of the client in the VPN subnet. This was pre-determined during the set up of the VPN server. For illustration, we allot the IP address 172.16.2.11 to the Windows PC. For DNS, input either an internal DNS server or the IP address of the VPN server.<\/p>\n<p>Under <em>PEER<\/em>, provide the name or the IP address of the VPN server, along with the port under <em>Endpoint<\/em>. Under <em>AllowedIPs<\/em>, identify which IP addresses should route the traffic via the VPN tunnel. Here, the subnet 10.0.0.0\/16 corresponds to the OPNsense firewall&#8217;s LAN.<\/p>\n<p>If you decide that all traffic should direct through the VPN post connection, including the internet, you should provide 0.0.0.0\/0 here.<\/p>\n<p>For the <em>PublicKey<\/em>, input the public key of the WireGuard VPN server, which you had stored earlier in a text file. The public key of the client goes into the WireGuard server&#8217;s configuration.<\/p>\n<h2>Configuring VPN clients in WireGuard<\/h2>\n<p>Configure the VPN clients on the OPNsense web interface on the <em>Peers<\/em> tab under <em>VPN =&gt; WireGuard =&gt; Settings<\/em>. Create a new client by clicking the plus sign and setting its name.<\/p>\n<p>Copy the client&#8217;s public key into the <em>Public Key<\/em> field. For <em>Allowed IPs<\/em>, enter the IP address assigned to the client in its configuration.<\/p>\n<p><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/02\/Creating-and-configuring-a-VPN-client.png\" target=\"_blank\" rel=\"nofollow noopener\">Creating and configuring a VPN client<\/a><\/p>\n<p>A pre-shared key can be helpful in a production environment, but we omit it in the test environment. Save to create the client.<\/p>\n<p>Then, switch to <em>Instances<\/em> and open the settings of the WireGuard server. Under <em>Peers<\/em>, check the new client so the server accepts it upon connection.<\/p>\n<p><a href=\"https:\/\/4sysops.com\/wp-content\/uploads\/2024\/02\/Allowing-a-new-client-through-the-OPNsense-console.png\" target=\"_blank\" rel=\"nofollow noopener\">Here is a visual guide<\/a> of allowing a new client through the OPNsense console.<\/p>\n<p>Afterward, I recommend restarting the WireGuard service via <em>Lobby =&gt; Dashboard<\/em>.<\/p>\n<h2>Establishing a connection with the VPN client<\/h2>\n<p>You can now test a connection on the client. The value for received and sent data should increase. If it remains at 0, the handshake did not work.<\/p>\n<p>In this case, check if the server and client&#8217;s public key have been configured correctly. Also, the client must be entered in the server&#8217;s settings under Peers.<\/p>\n<p>The protocol shows information about the connection, and the OPNsense firewall displays the connections under <em>VPN =&gt; WireGuard =&gt; Diagnostics<\/em>. Here, all active clients are visible.<\/p>\n<div><\/div>\n<p>Overview of connected VPN clients<\/p>\n<h2>Summary<\/h2>\n<p>To install WireGuard on OPNsense, you need to add an extension. After configuring its interface, the name resolution is handled with <em>Unbound DNS<\/em>, another OPNsense service.<\/p>\n<div>\n<h2>Subscribe to 4sysops newsletter!<\/h2>\n<\/div>\n<p>Firewall rules determine which resources the clients can access. Finally, the VPN clients are set up, for which the server&#8217;s public keys and clients must be entered into each other&#8217;s configuration.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are employing an OPNsense firewall, the option to configure WireGuard as a VPN server instead of OpenVPN is a viable option. WireGuard&#8217;s clients are available for all major operating systems, proving very fast and lightweight. This can easily be installed as an OPNsense extension and configured via the web console. For implementing a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9234,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92,167,133,114],"tags":[],"class_list":["post-9233","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles","category-firewall","category-networking","category-security"],"_links":{"self":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/9233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/comments?post=9233"}],"version-history":[{"count":1,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/9233\/revisions"}],"predecessor-version":[{"id":10452,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/9233\/revisions\/10452"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media\/9234"}],"wp:attachment":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media?parent=9233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/categories?post=9233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/tags?post=9233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}