<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Opnsense on 0x2142 | Networking Nonsense</title>
    <link>https://0x2142.com/tags/opnsense/</link>
    <description>Recent content in Opnsense on 0x2142 | Networking Nonsense</description>
    <image>
      <title>0x2142 | Networking Nonsense</title>
      <url>https://0x2142.com/logo.jpg</url>
      <link>https://0x2142.com/logo.jpg</link>
    </image>
    <generator>Hugo -- 0.143.1</generator>
    <language>en-us</language>
    <lastBuildDate>Tue, 29 Aug 2023 15:01:15 +0000</lastBuildDate>
    <atom:link href="https://0x2142.com/tags/opnsense/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>[How To] Protect Your Home Network with Mullvad VPN &amp; OPNsense</title>
      <link>https://0x2142.com/how-to-protect-your-home-network-with-mullvad-vpn-opnsense/</link>
      <pubDate>Tue, 29 Aug 2023 15:01:15 +0000</pubDate>
      <guid>https://0x2142.com/how-to-protect-your-home-network-with-mullvad-vpn-opnsense/</guid>
      <description>In this post, we&amp;rsquo;ll walk through how to connect an OPNsense firewall to Mullvad&amp;rsquo;s VPN service. This covers both a full tunnel &amp;amp; partial tunnel configuration.</description>
      <content:encoded><![CDATA[<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
      <iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen="allowfullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/9B4FW5pf2wA?autoplay=0&amp;controls=1&amp;end=0&amp;loop=0&amp;mute=0&amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"></iframe>
    </div>

<p>In this post, we&rsquo;ll walk through how to connect an OPNsense firewall to Mullvad&rsquo;s wireguard VPN. This can be used in various deployments to help protect your home network traffic.</p>
<p>As a quick note, this post is not sponsored by <a href="https://mullvad.net/">Mullvad</a> - I just happen to really like their service &amp; appreciate their approach to privacy and security. In fact, they currently don&rsquo;t offer any incentives or paid promotions of their product. More info on their current policy can be found <a href="https://mullvad.net/en/help/policy-reviews-advertising-and-affiliates/">here</a>.</p>
<h1 id="creating-an-account">Creating an Account</h1>
<p>Mullvad is unique in that they don&rsquo;t really require any sign up to get started with their service. Instead, when you sign up for new service, they randomly generate an account number. That&rsquo;s it. They don&rsquo;t require any additional information from you.</p>
<p>So first we can hit their new account page <a href="https://mullvad.net/en/account/create">here</a> - then click to generate a new account number.</p>
<p><img alt="create-account" loading="lazy" src="/content/images/2023/07/create-account.png#center"></p>
<blockquote>
<p>Keep this account number somewhere safe. Mullvad has <a href="https://mullvad.net/en/account/recover/">very limited</a> ability to help you recover the account number.</p></blockquote>
<p>Once we have that, we can click the button to <strong>Add time</strong> to our account.</p>
<p>Mullvad doesn&rsquo;t support any recurring subscriptions, so that they are able to keep less data about their customers. Instead, we just add time increments in months for how long we would like to use the service. This can be anywhere from a single month up to a year.</p>
<p>In terms of payments, they do offer a number of options, including the usual PayPal/credit cards - or if you&rsquo;re truly concerned about privacy, they accept a few cryptocurrencies or you can actually mail them a cash payment as well.</p>
<p>After a payment has been made &amp; time added to the account, we can quickly jump into the configuration side of things.</p>
<h1 id="config-mullvad-side">Config: Mullvad Side</h1>
<p>First we&rsquo;ll take a quick look at the configuration required on the Mullvad VPN side of things.</p>
<p>On the left side of the account page, we&rsquo;ll click on <strong>WireGuard Configuration</strong>.</p>
<p>First we&rsquo;ll select <strong>Linux</strong> as our platform (In this context, what is selected here isn&rsquo;t really important) - and then click the button to generate WireGuard keys:</p>
<p><img alt="generate-keys" loading="lazy" src="/content/images/2023/07/generate-keys.png#center"></p>
<blockquote>
<p>Note: Alternatively, we could have generated our WireGuard keys on our OPNsense firewall - then applied them here. It&rsquo;s up to you on which method you prefer!</p></blockquote>
<p>Next, we&rsquo;ll take a look at which server(s) we would like to connect to.</p>
<p><img alt="select-server" loading="lazy" src="/content/images/2023/07/select-server.png#center"></p>
<p>When selecting a server, we have the option to pick our desired country &amp; location - as well as picking a specific server to connect to if we choose. There is also an option to select all servers - in which case the config generator will create a WireGuard configuration file for each server.</p>
<p>For the purpose of this walk through, we&rsquo;ll keep things simple &amp; only select a single server. So in the screenshot above, I&rsquo;ve selected <code>us-qas-wg-004</code>.</p>
<p>We&rsquo;ll also take a quick look at the advanced options, which give us a little flexibility if we need it. For most people, these additional options will not be necessary to change or modify.</p>
<p>We can enable <strong>Multihop</strong> functionality, so long as we only selected a single server to connect to. So if you selected the <strong>All Servers</strong> option, this won&rsquo;t be available. This allows us to specify an entry &amp; exit server for our VPN. In other words, our device would directly connect to the entry server we select - then Mullvad would tunnel our traffic across their network to the exit server, where our traffic would be decrypted &amp; forwarded out to the internet. Depending on your privacy &amp; security desires, this is a really nice option to have the ability to enable.</p>
<p>Next, we have options on what type of connection we would like &amp; which traffic to forward.</p>
<p><strong>Server connection protocol</strong> will specify whether we are using IPv4 or IPv6 between our device &amp; our VPN server. Most likely you&rsquo;ll want to leave this at IPv4, unless you have an IPv6-only internet connection (or if you just would prefer to use IPv6 anyways!).</p>
<p><strong>Tunnel traffic</strong> is how we can specify whether we would like IPv4 or IPv6 <em>client-side</em> traffic to be forwarded over the VPN. So this would depend on whether the clients on our network have IPv4 vs IPv6 connectivity, or both - and whether we prefer to only forward certain types of traffic over the VPN. I&rsquo;ll be leaving this setting as the default: <strong>Both.</strong></p>
<p>Next we can specify a custom port if we would like. By default, wireguard will use UDP port 51820 - and we probably won&rsquo;t need to change this unless the port is being blocked upstream.</p>
<p>Lastly, we also have the option to enable content blocking across the VPN. Mullvad accomplishes content filtering through DNS-level blocking - and when we finish generating a configuration file, the file will include DNS servers to use. This is okay to use if you were connecting a single client to their VPN service. However, if you&rsquo;re using a router or device like OPNsense, you would need to update the DNS on all clients on your network to make this work. This is possible by updating DHCP on our router with the new DNS server address - or configuring a DNS rewrite. We won&rsquo;t get into either of those in this post - so for now I will leave the content blocking options unchecked.</p>
<p>Once we&rsquo;re good with our configuration - we can click the <strong>Download File</strong> button. We&rsquo;ll get a standard WireGuard config file, that looks like this:</p>
<p><img alt="wireguard-config" loading="lazy" src="/content/images/2023/07/wireguard-config.png#center"></p>
<p>At this point, we&rsquo;re good to move onto the next part!</p>
<h1 id="config-opnsense-side">Config: OPNsense Side</h1>
<p>Okay, so now that we have everything ready to go on the Mullvad side - we can configure our OPNsense device.</p>
<p>Make sure you already have WireGuard installed on OPNsense. This can be done by navigating to <strong>System &gt; Firmware &gt; Plugins</strong> then searching for <strong>wireguard</strong> &amp; clicking the install button.</p>
<p>Next, we&rsquo;ll enable Wireguard by navigating to <strong>VPN &gt; Wireguard</strong> and checking the box to <strong>Enable WireGuard</strong>, then <strong>Apply</strong>.</p>
<p><img alt="enable-wireguard" loading="lazy" src="/content/images/2023/07/enable-wireguard.png#center"></p>
<p>Then we&rsquo;ll hop over to the <strong>Endpoints</strong> tab &amp; configure our Mullvad VPN peer.</p>
<p>For this part of the configuration, we&rsquo;ll just copy our public key, allowed IPs, endpoint address, and endpoint port from our Mullvad config file. In the screenshot below, I also named my endpoint with the specific Mullvad server I&rsquo;ll be connecting to:</p>
<p><img alt="mullvad-peer-config-1" loading="lazy" src="/content/images/2023/07/mullvad-peer-config-1.png#center"></p>
<p>Then we can click <strong>Save</strong> and <strong>Apply.</strong></p>
<blockquote>
<p>If you wanted multiple Mullvad servers configured, just create a new endpoint for each one. Then, make sure that you select all of the Mullvad peers on the next step below.</p></blockquote>
<p>After that, we can move over to the <strong>Local</strong> tab to define our OPNsense tunnel configuration.</p>
<p>Click the button to add a new peer, then we&rsquo;ll fill in our private key and tunnel address(es) from the Mullvad config file. Under <strong>Peers</strong>, we&rsquo;ll also select our Mullvad VPN peer that we configured just a moment ago:</p>
<p><img alt="opnsense-local-1" loading="lazy" src="/content/images/2023/07/opnsense-local-1.png#center"></p>
<blockquote>
<p>UPDATE: Looks like with a recent OPNsense update, they now require you to enter both the WireGuard private &amp; public key into the local config (shown above). In the the screenshot, I only show entering the private key - since this was all that was required at the time.
Two ways to get your public key:</p>
<ol>
<li>Log into Mullvad &amp; check the &ldquo;Devices&rdquo; tab under &ldquo;Account Management&rdquo;. This will show your device public key (They don&rsquo;t keep your private key after generating it for you, only the public).</li>
<li>If you have wireguard installed somewhere else, you can use the &ldquo;wg pubkey&rdquo; command to derive a public key from your private key. Command: <code>echo &lt;private_key&gt; | wg pubkey</code></li>
</ol></blockquote>
<blockquote>
<p>Note: By default with the configuration we&rsquo;ve applied so far, this VPN will forward ALL traffic on our network to Mullvad. If we would prefer to selectively choose which traffic to send over the VPN, we can check the box for <strong>Disable Routes</strong> - then use policy routing to forward specific things to Mullvad.
We&rsquo;ll take a look at how to do this later in the post - but for now just be aware that our current configuration will forward ALL traffic.</p></blockquote>
<p>Okay, with that all done we can click <strong>Apply</strong> and <strong>Save</strong> here as well.</p>
<p>With any luck, we can check the <strong>Status</strong> tab &amp; see that there is data being transmitted &amp; successful WireGuard handshakes:</p>
<p><img alt="wg-status" loading="lazy" src="/content/images/2023/07/wg-status.png#center"></p>
<p>However, before our clients traffic can be forwarded over the VPN, we&rsquo;ll need to create a firewall rule to permit traffic &amp; a NAT rule to translate our client addresses to our Mullvad IP.</p>
<p>We&rsquo;ll navigate to <strong>Firewall &gt; Rules &gt; WireGuard (Group)</strong>. Then we&rsquo;ll click to create a new rule.</p>
<p>Within this new rule, I&rsquo;ll update <strong>Direction</strong> to <strong>Out</strong> and change <strong>TCP/IP Version</strong> to <strong>IPv4+IPv6</strong>. I&rsquo;ll leave the source as <strong>Any:</strong></p>
<p><img alt="wgrule1" loading="lazy" src="/content/images/2023/07/wgrule1.png#center"></p>
<p>We can also leave the <strong>Destination</strong> as <strong>Any</strong>, but I&rsquo;ll update the rule to enable logging:</p>
<p><img alt="wgrule2" loading="lazy" src="/content/images/2023/07/wgrule2.png#center"></p>
<p>This rule will allow any clients behind our OPNsense firewall to reach anything on the internet.</p>
<p>Next, we&rsquo;ll have to create a NAT rule. This ensures that our client addresses on our network get appropriately translated to the tunnel IP address that Mullvad has assigned us.</p>
<p>We&rsquo;ll navigate to <strong>Firewall &gt; NAT &gt; Outbound</strong>. By default, OPNsense will be set to <strong>Automatic outbound NAT rule generation</strong>. We&rsquo;ll need to update this to <strong>Hybrid outbound NAT rule generation</strong> to allow custom NAT rules. Then we can click <strong>Save</strong> and <strong>Apply</strong>.</p>
<p><img alt="nat-before" loading="lazy" src="/content/images/2023/07/nat-before.png#center"></p>
<p>Next, we&rsquo;ll create a new <strong>Manual NAT</strong> rule, where we&rsquo;ll update our <strong>Interface</strong> to <strong>WireGuard (Group):</strong></p>
<p><img alt="nat-rule1" loading="lazy" src="/content/images/2023/07/nat-rule1.png#center"></p>
<p>Then we&rsquo;ll make sure our <strong>Translation / target</strong> is set to <strong>Interface Address</strong> - and again, I&rsquo;ll enable logging:</p>
<p><img alt="nat-rule2" loading="lazy" src="/content/images/2023/07/nat-rule2.png#center"></p>
<p>After we click save, we should have a NAT rule that looks like this:</p>
<p><img alt="nat-after" loading="lazy" src="/content/images/2023/07/nat-after.png#center"></p>
<p>At this point, we should be good to test our clients!</p>
<h1 id="testing">Testing</h1>
<p>Of course, it&rsquo;s easy enough to use one of our clients to check that we still have internet access - but how can we be sure that they&rsquo;re using the VPN?</p>
<p>The easiest way might be to check the <a href="https://mullvad.net">mullvad.net</a>, where they do have a quick validation at the top of the page:</p>
<p><img alt="mullvad-test" loading="lazy" src="/content/images/2023/07/mullvad-test.png#center"></p>
<p>So according to Mullvad, it looks like we&rsquo;re connected &amp; they even show which server we&rsquo;re connecting from.</p>
<p>We can also double check using a traceroute or tracepath command:</p>
<p><img alt="tracepath" loading="lazy" src="/content/images/2023/07/tracepath.png#center"></p>
<p>In this case, we can see that our traffic to Google hits our OPNsense gateway, then the Mullvad VPN gateway followed by another external address owned by Mullvad.</p>
<p>So based on some quick testing, it looks like we&rsquo;re all good!</p>
<h1 id="policy-routing">Policy Routing</h1>
<p>So in the above walkthrough, we configured a Mullvad VPN from our OPNsense firewall - but it is forwarding ALL of our network clients over the VPN. What about if we only wanted certain clients to use the VPN? Or all clients to use it, but only for certain destinations?</p>
<p>We can accomplish this through policy routing.</p>
<p>So the first thing we&rsquo;ll do is go back to our WireGuard config, then under the <strong>Local</strong> tab. We&rsquo;ll edit our configuration here, and check the box for <strong>Disable Routes</strong>.</p>
<p><img alt="disable-routes" loading="lazy" src="/content/images/2023/07/disable-routes.png#center"></p>
<p>By default, OPNsense / WireGuard will install routes for any IPs listed in the <strong>AllowedIPs</strong> field for each peer. In our set up, we configured <strong>0.0.0.0/0</strong> - which matches all traffic. By checking the box for <strong>Disable Routes</strong>, we prevent OPNsense from installing that default route - and instead we can manually specify our own.</p>
<blockquote>
<p>If you&rsquo;re curious to double check this, you can try hitting Mullvad&rsquo;s website after changing this setting - and it should show that you&rsquo;re no longer connected.</p></blockquote>
<p>Then, we&rsquo;ll need to set up our WireGuard configuration to use a dedicated, named interface so that we can create a static gateway.</p>
<p>We&rsquo;ll head to <strong>Interfaces &gt; Assignments</strong> - and create a new interface. From the drop-down, we&rsquo;ll select our WireGuard interface - in my case this was <code>wg1</code>. Then we can assign it a name:</p>
<p><img alt="create-interface" loading="lazy" src="/content/images/2023/07/create-interface.png#center"></p>
<p>Then click the <strong>+</strong> icon to add, and <strong>Save.</strong></p>
<p>Then we can navigate to the interface name under the <strong>Interfaces</strong> menu - and enable the new interface:</p>
<p><img alt="enable-interface" loading="lazy" src="/content/images/2023/07/enable-interface.png#center"></p>
<p>Next we can create a gateway to route traffic through. Navigate to <strong>System &gt; Gateways &gt; Single</strong>.</p>
<p>Create a new gateway &amp; give it a name. Then we&rsquo;ll enter our Mullvad VPN gateway IP address, which in my case was <code>10.64.0.1</code>. How did we find this? Well earlier when we tested our VPN connectivity - we performed a tracepath. In the output of this tracepath, our second hop (the one right after our OPNsense firewall) would be the Mullvad VPN gateway. So this is the address we&rsquo;ll use for our gateway here:</p>
<p><img alt="mullvad-gateway" loading="lazy" src="/content/images/2023/07/mullvad-gateway.png#center"></p>
<p>Then clic <strong>Save</strong> and <strong>Apply</strong>.</p>
<blockquote>
<p>Note: You may get an error here, like &ldquo;The gateway address &ldquo;10.64.0.1&rdquo; does not lie within one of the chosen interface&rsquo;s IPv4 subnets.&rdquo;
To resolve this, we&rsquo;ll temporarily change our interface address. Navigate to the WireGuard local config, and re-enter your tunnel address excluding the &ldquo;/32&rdquo;. For example, if your tunnel IP was <code>10.10.10.10/32</code>, change this to just <code>10.10.10.10</code>
You should be able to set the gateway address now. Be sure to change your tunnel IP back afterwards!</p></blockquote>
<p>Next, we&rsquo;ll create a firewall rule for each set of sources or destinations we would like to manipulate.</p>
<p>So we can navigate to <strong>Firewall &gt; Rules &gt; Floating</strong> (or select a specific interface for clients, like LAN).</p>
<p>In here, we&rsquo;ll set whichever parameters we would like to match. So for this example, let&rsquo;s say I have a client PC at <code>10.100.100.10</code> and I only want traffic to <code>8.8.8.8</code> to use Mullvad. All other traffic can use the normal internet connection &amp; not use the VPN.</p>
<p>In that case, I&rsquo;ll set my source address to <code>10.100.100.10/32</code> and my destination to <code>8.8.8.8/32</code>:</p>
<p><img alt="policy-route1" loading="lazy" src="/content/images/2023/07/policy-route1.png#center"></p>
<p>Then all we need to do is update our <strong>Gateway</strong> to use the Mullvad gateway we just created:</p>
<p><img alt="policy-route2" loading="lazy" src="/content/images/2023/07/policy-route2.png#center"></p>
<p>Now, if we hop over to our client PC - Mullvad&rsquo;s website will say that we&rsquo;re not connected to the VPN. However, we can check that traffic to 8.8.8.8 is actually being sent through Mullvad using tracepath again:</p>
<p><img alt="split-routing" loading="lazy" src="/content/images/2023/07/split-routing.png#center"></p>
<p>In the screenshot above, I also included a tracepath to 8.8.4.4, just to show that it is going through my normal internet connection &amp; not Mullvad.</p>
<p>This was just one example, but you could easily create multiple firewall rules for different sources and/or destinations to control where traffic is sent. Aliases can also be used to group sources or destinations, so that multiple can be added to a single firewall rule.</p>
<hr>
<p>Okay - I think that&rsquo;s about all I wanted to cover in this post.</p>
<p>Hope it is helpful! Feel free to leave a comment below - or follow me on <a href="https://youtube.com/@0x2142">YouTube</a> 😊</p>
]]></content:encoded>
    </item>
    <item>
      <title>[How To] Set up AdGuard Home on OPNsense</title>
      <link>https://0x2142.com/how-to-set-up-adguard-on-opnsense/</link>
      <pubDate>Fri, 09 Dec 2022 16:40:49 +0000</pubDate>
      <guid>https://0x2142.com/how-to-set-up-adguard-on-opnsense/</guid>
      <description>In this post, we&amp;rsquo;ll walk through how to install, setup, and configure AdGuard Home on OPNsense for DNS-level ad blocking.</description>
      <content:encoded><![CDATA[<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;">
      <iframe allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen="allowfullscreen" loading="eager" referrerpolicy="strict-origin-when-cross-origin" src="https://www.youtube.com/embed/7RC7q5WOYC0?autoplay=0&amp;controls=1&amp;end=0&amp;loop=0&amp;mute=0&amp;start=0" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;" title="YouTube video"></iframe>
    </div>

<p>In this post - we&rsquo;ll take a look at how to set up &amp; configure AdGuard Home on OPNsense.</p>
<p>Please note that the AdGuard Home plugin for OPNsense is a <a href="https://github.com/mimugmail/opn-repo">community built plugin</a>, and not officially supported by OPNsense.</p>
<hr>
<h2 id="whats-adguard-home-why-use-it">What&rsquo;s AdGuard Home? Why use it?</h2>
<p>Almost every website we visit these days is loaded with additional components for  advertisements, analytics, and engagement tracking. One one side, these tools can be very helpful for the company or website owner to monetize their platform and/or track &amp; understand their audience&rsquo;s interests.</p>
<p>However, it&rsquo;s also becoming more popular to want to <em>avoid</em> being tracked on every website, or reduce the amount of advertisements you see. Unfortunately, a lot of these scripts &amp; code snippets are automatically embedded in websites and most don&rsquo;t allow you to opt-out.</p>
<p>A while back, there were a few browser extensions that became popular by automatically blocking the advertisement &amp; tracking elements from loading. These were great (and still are!), but a lot of website owners have been fighting it &amp; making it harder to block their content. In addition, these types of extensions operate at your web browser level - meaning that your computer has already made a few calls out to the internet before the extension even has a chance to block something.</p>
<p>Here&rsquo;s where we&rsquo;ve started to see more ad blockers come out that operate at the network level. AdGuard Home is one of them, but you also may have seen similar packages like Pi-hole or NextDNS. These are typically packages that you install on your home network &amp; run as a local Domain Name System (DNS) server.</p>
<p>Each time your browser needs to load something from the web, the first step is figuring out what IP address to connect to. For this, the computer reaches out to it&rsquo;s configured DNS server and provides the website name (like 0x2142.com). The DNS server looks up where that lives &amp; provides the computer with the IP address (like 203.0.113.52). Then your computer can load the website by connecting to that address.</p>
<p>With a DNS-level blocker, like AdGuard Home, we can block your computer from ever trying to establish that connection. If you tried to go to a website (like 0x2142.com), and there was an embedded advertisement or tracking, AdGuard would tell your computer that the domain hosting the advertisement doesn&rsquo;t exist (usually via returning a 0.0.0.0 or NXDOMAIN response). So your browser would still be able to load the main site (0x2142.com), but it would never even try to establish a connection to the advertisement or tracking components.</p>
<p>So we gain a few benefits here - the big ones being some level of privacy &amp; reduced advertisement noise when browsing the web. But also since we block so much of that noise early in the process, your computer never has the opportunity to load that content - meaning that we also save on bandwidth usage &amp; data costs. There may also be small performance improvements since each site has less content that needs to be loaded.</p>
<p>The other bonus worth considering is security. There are quite a handful of DNS blocklists that are constantly updated with the latest malicious or suspicious domains. The quicker we can block  &amp; stop clients from potentially connecting to those domains, the better off we are!</p>
<p>Is there a down side? Yeah, of course there is! A lot of these DNS-level blockers pull from varying website blocklists - which are not always 100% accurate. So sometimes you may still see advertisements or get tracked. It&rsquo;s not a perfect system. In addition, you may also (and sometimes often) see the reverse - parts of websites being blocked that are legitimate. And there are quite a handful of websites these days that won&rsquo;t work correctly unless they can load 3rd party components. Most of the time everything will be fine, but just be aware that there may be some time spent troubleshooting &amp; manually unblocking website components.</p>
<h3 id="do-i-have-to-install-this-on-opnsense">Do I have to install this on OPNsense?</h3>
<p>Nope. AdGuard Home has a number of packages &amp; ways to get running. Check out their <a href="https://github.com/AdguardTeam/AdguardHome">GitHub</a> repo.</p>
<p>If you&rsquo;re already running OPNsense, it&rsquo;s easy to install this as an add-on package &amp; not have another system to manage. However, if you prefer to set up AdGuard (or Pi-hole, or others) elsewhere, that&rsquo;s fine too. You&rsquo;ll just need to update your client network&rsquo;s DHCP options to use the new DNS servers. See the last section below on how to do that.</p>
<p>Okay - Let&rsquo;s get started with setting this up!</p>
<h2 id="topology">Topology</h2>
<p>For the purposes of this walkthrough, we&rsquo;ll be using a fairly simple &amp; straightforward topology. A single OPNsense appliance connected to the internet via it&rsquo;s WAN port, as well as a single client PC connected via the LAN port.</p>
<p>In this setup, the OPNsense appliance is configured to provide IP address &amp; DNS information to our client PCs via DHCP.</p>
<p><img alt="topology" loading="lazy" src="/content/images/2022/12/topology.png#center"></p>
<h2 id="adding-the-community-repository-to-opnsense">Adding the Community Repository to OPNsense</h2>
<p>So by default, AdGuard Home is not included in the available plugins to download/install in OPNsense. However, someone built a community plugin repository that includes a small handful of additional packages.</p>
<p>Before we can install the AdGuard Home plugin, we will need to setup &amp; install that <a href="https://github.com/mimugmail/opn-repo">community repository</a>.</p>
<p>To do this, we&rsquo;ll need direct SSH or console access to our OPNsense appliance.</p>
<p>SSH is disabled by default, but we can enable it quickly by navigating to <strong>System &gt; Settings &gt; Administration</strong> and then scrolling down to the <strong>Secure Shell</strong> section.</p>
<p><img alt="enable-ssh-1" loading="lazy" src="/content/images/2022/12/enable-ssh-1.png#center"></p>
<p>We&rsquo;ll need to check the box for <strong>Enable Secure Shell</strong> and <strong>Permit Password Login</strong>. If you&rsquo;re logging into OPNsense with the <strong>root</strong> account, you&rsquo;ll also need to select <strong>Permit root user login</strong>.</p>
<p>Then scroll down to the bottom of the page &amp; click <strong>Save</strong>.</p>
<blockquote>
<p>Note: By default OPNsense will also have the SSH <strong>Listen Interface</strong> set to <strong>All</strong>. I would highly recommend setting this to only enable on your <strong>LAN</strong> interface
Also: If you don&rsquo;t need SSH access all the time, please remember to disable this service once you&rsquo;re finished setting this up!</p></blockquote>
<p>Okay, now that&rsquo;s enabled - we can connect to our OPNsense appliance using your preferred SSH client (like <a href="https://www.putty.org/">PuTTY</a>).</p>
<p>If you&rsquo;re using the <strong>root</strong> account, you&rsquo;ll likely be dropped into the OPNsense shell - but you can select option 8 here to access the underlying FreeBSD shell.</p>
<p>In order to install the community repository, we&rsquo;ll pull down the repository config file using the following command:</p>
<pre tabindex="0"><code>fetch -o /usr/local/etc/pkg/repos/mimugmail.conf https://www.routerperformance.net/mimugmail.conf
</code></pre><p>Then, we&rsquo;ll need to ask OPNsense to update it&rsquo;s local cache with the new repo - so it knows what packages are hosted there:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">pkg update
</span></span></code></pre></div><p>If everything is successful, you&rsquo;ll see output similar to below - which lists the <code>mimugmail</code> repository now:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">root@0xOPNsense:/home/matt <span class="c1"># pkg update</span>
</span></span><span class="line"><span class="cl">Updating OPNsense repository catalogue...
</span></span><span class="line"><span class="cl">Fetching meta.conf: 100%    <span class="m">163</span> B   0.2kB/s    00:01
</span></span><span class="line"><span class="cl">Fetching packagesite.pkg: 100%  <span class="m">229</span> KiB 234.3kB/s    00:01
</span></span><span class="line"><span class="cl">Processing entries: 100%
</span></span><span class="line"><span class="cl">OPNsense repository update completed. <span class="m">822</span> packages processed.
</span></span><span class="line"><span class="cl">Updating mimugmail repository catalogue...
</span></span><span class="line"><span class="cl">Fetching meta.conf: 100%    <span class="m">163</span> B   0.2kB/s    00:01
</span></span><span class="line"><span class="cl">Fetching packagesite.pkg: 100%   <span class="m">54</span> KiB  54.8kB/s    00:01
</span></span><span class="line"><span class="cl">Processing entries: 100%
</span></span><span class="line"><span class="cl">mimugmail repository update completed. <span class="m">177</span> packages processed.
</span></span><span class="line"><span class="cl">All repositories are up to date.
</span></span></code></pre></div><h2 id="installing-the-adguard-home-package">Installing the AdGuard Home Package</h2>
<p>Now that the additional package repository is set up, we can download &amp; install the AdGuard Home plugin via the OPNsense web interface.</p>
<p>So back in our browser, we can nagivate to: <strong>System &gt; Firmware &gt; Plugins</strong>. On this page we can search for <strong>adguard</strong> or scroll through the list to find it.</p>
<p><img alt="plugin-install" loading="lazy" src="/content/images/2022/12/plugin-install.png#center"></p>
<p>Then we just click the plus icon on the right side to install (not shown in the screenshot above).</p>
<p>This should install pretty quickly:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">***GOT REQUEST TO INSTALL***
</span></span><span class="line"><span class="cl">Currently running OPNsense 22.7.9 <span class="o">(</span>amd64/OpenSSL<span class="o">)</span> at Sun Dec  <span class="m">4</span> 12:48:38 EST <span class="m">2022</span>
</span></span><span class="line"><span class="cl">Updating OPNsense repository catalogue...
</span></span><span class="line"><span class="cl">OPNsense repository is up to date.
</span></span><span class="line"><span class="cl">Updating mimugmail repository catalogue...
</span></span><span class="line"><span class="cl">mimugmail repository is up to date.
</span></span><span class="line"><span class="cl">All repositories are up to date.
</span></span><span class="line"><span class="cl">The following <span class="m">1</span> package<span class="o">(</span>s<span class="o">)</span> will be affected <span class="o">(</span>of <span class="m">0</span> checked<span class="o">)</span>:
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">New packages to be INSTALLED:
</span></span><span class="line"><span class="cl"> os-adguardhome-maxit: 1.8 <span class="o">[</span>mimugmail<span class="o">]</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">Number of packages to be installed: <span class="m">1</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl">The process will require <span class="m">35</span> MiB more space.
</span></span><span class="line"><span class="cl"><span class="m">7</span> MiB to be downloaded.
</span></span><span class="line"><span class="cl"><span class="o">[</span>1/1<span class="o">]</span> Fetching os-adguardhome-maxit-1.8.pkg: .......... <span class="k">done</span>
</span></span><span class="line"><span class="cl">Checking integrity... <span class="k">done</span> <span class="o">(</span><span class="m">0</span> conflicting<span class="o">)</span>
</span></span><span class="line"><span class="cl"><span class="o">[</span>1/1<span class="o">]</span> Installing os-adguardhome-maxit-1.8...
</span></span><span class="line"><span class="cl"><span class="o">[</span>1/1<span class="o">]</span> Extracting os-adguardhome-maxit-1.8: .......... <span class="k">done</span>
</span></span><span class="line"><span class="cl">Stopping configd...done
</span></span><span class="line"><span class="cl">Starting configd.
</span></span><span class="line"><span class="cl">Migrated OPNsense<span class="se">\A</span>dguardhome<span class="se">\G</span>eneral from 0.0.0 to 0.0.1
</span></span><span class="line"><span class="cl">Reloading plugin configuration
</span></span><span class="line"><span class="cl">Configuring system logging...done.
</span></span><span class="line"><span class="cl">Reloading template OPNsense/Adguardhome: OK
</span></span><span class="line"><span class="cl">Checking integrity... <span class="k">done</span> <span class="o">(</span><span class="m">0</span> conflicting<span class="o">)</span>
</span></span><span class="line"><span class="cl">Nothing to <span class="k">do</span>.
</span></span><span class="line"><span class="cl">***DONE***
</span></span></code></pre></div><p>Now all we have to do is enable the plugin.</p>
<p>So we&rsquo;ll navigate down to <strong>Services &gt; Adguardhome &gt; General</strong>. Our only option here will be an <strong>Enable</strong> checkbox, so we&rsquo;ll select that &amp; <strong>Save</strong>.</p>
<p><img alt="enable-adguard" loading="lazy" src="/content/images/2022/12/enable-adguard.png#center"></p>
<p>The rest of the setup &amp; initial configuration will be done directly from the AdGuard-specific web interface.</p>
<h2 id="initial-setup">Initial Setup</h2>
<p>By default, the AdGuard Home web interface will run on port 3000 &amp; is not HTTPS-enabled. So if your OPNsense firewall is at <code>https://192.168.1.1</code>, you&rsquo;ll need to connect to <code>http://192.168.1.1:3000</code>.</p>
<p>As long as that works - we&rsquo;ll see the initial setup prompt below:</p>
<p><img alt="adguard-setup-01" loading="lazy" src="/content/images/2022/12/adguard-setup-01.png#center"></p>
<p>We&rsquo;ll click on <strong>Get Started</strong>.</p>
<p>Now we&rsquo;ll be asked to configure the Admin Web interface (the interface we&rsquo;re connected to now) and the DNS server interface (which clients will use to resolve domain names).</p>
<p>By default, AdGuard home will try to set both of these to listen on <strong>All interfaces</strong> - and set the web on port 80 &amp; DNS on port 53.</p>
<p>I would recommend setting the <strong>Listen Interface</strong> on both of these to only your LAN-side networks. There is no reason to enable them on your WAN, and it can be a security risk to do so.</p>
<p>You may also get warnings that port 80 &amp; 53 may already be in use. For the web interface, we could change 80 to 3000 &amp; just keep what we&rsquo;re using now.</p>
<p>However, if we change the default DNS port, that will cause some additional problems since client machines will query port 53. Likely if port 53 is already in use, it&rsquo;s because another service on OPNsense (like Unbound DNS) is already enabled. In my case, I disabled this in favor of using AdGuard. However, if you want to use both - you can change the default DNS port in AdGuard to something like 65353, then have Unbound forward requests to AdGuard (More on this down below).</p>
<p>So here&rsquo;s what my set up looks like so far, with <code>192.168.1.1</code> being my LAN side interface:</p>
<p><img alt="adguard-setup-02" loading="lazy" src="/content/images/2022/12/adguard-setup-02.png#center"></p>
<p>On the next page, we&rsquo;ll be prompted to set up an administrative user &amp; password for logging into AdGuard.</p>
<p><img alt="adguard-setup-03" loading="lazy" src="/content/images/2022/12/adguard-setup-03.png#center"></p>
<p>Next we&rsquo;ll be given instructions on how to set up client devices. In my lab network, the OPNsense firewall is providing DNS server configuration via DHCP - so we&rsquo;ll get to that configuration shortly.</p>
<p>For now, we&rsquo;ll just click <strong>Next</strong>.</p>
<p><img alt="adguard-setup-04" loading="lazy" src="/content/images/2022/12/adguard-setup-04.png#center"></p>
<p>On the last screen, we&rsquo;ll just get a message saying that setup is complete &amp; a link to open the dashboard:</p>
<p><img alt="adguard-setup-05" loading="lazy" src="/content/images/2022/12/adguard-setup-05.png#center"></p>
<p>And now we can log in:</p>
<p><img alt="adguard-setup-06" loading="lazy" src="/content/images/2022/12/adguard-setup-06.png#center"></p>
<h2 id="adguard-home-configuration">AdGuard Home Configuration</h2>
<p>After logging in, the first thing we&rsquo;ll see is a pretty empty dashboard. We don&rsquo;t have any clients configured to use this yet, so there isn&rsquo;t anything to report on.</p>
<p><img alt="adguard-dashboard-initial" loading="lazy" src="/content/images/2022/12/adguard-dashboard-initial.png#center"></p>
<h3 id="blocking-domains">Blocking Domains</h3>
<p>First thing we&rsquo;ll look at is our DNS blocklists. We&rsquo;ll navigate to <strong>Filters &gt; DNS blocklists</strong>.</p>
<p>Here is where we can ask AdGuard to query lists of what domains to block. By default, AdGuard does include two - but we can add more if we want:</p>
<p><img alt="adguard-dns-blocklists" loading="lazy" src="/content/images/2022/12/adguard-dns-blocklists.png#center"></p>
<p>If we want to add to the configured blocklists, we can do so by clicking the <strong>Add Blocklist</strong> button. This will prompt us whether we want to choose from a pre-populated list, or supply our own custom list:</p>
<p><img alt="add-blocklist" loading="lazy" src="/content/images/2022/12/add-blocklist.png#center"></p>
<p>The easy option will be selecting from the provided lists:</p>
<p><img alt="choose-blocklist" loading="lazy" src="/content/images/2022/12/choose-blocklist.png#center"></p>
<p>There are a ton of different curated block lists available depending on what you&rsquo;re trying to block. If we wanted to use a custom list, a lot can be found on GitHub just by searching for <a href="https://github.com/topics/pihole-blocklists">PiHole</a> or <a href="https://github.com/topics/adguard-blocklist">Adguard</a> blocklists.</p>
<p>How to pick a blocklist will be up to you. There are blocklists that focus on advertisements, tracking &amp; analytics, parental controls, etc. So it just depends on what areas you want to focus on.</p>
<h3 id="allowing-domains--custom-filtering">Allowing Domains &amp; Custom Filtering</h3>
<p>If we have a list of known services that we want to ensure are never blocked, we can pull those lists via <strong>Filters &gt; DNS allowlists</strong>. However, it&rsquo;s more likely you&rsquo;ll find a handful of domains you want to unblock, rather than a whole list.</p>
<p>For that - we can go to <strong>Filters &gt; Custom filtering rules</strong>. At the bottom of this page there is a tool to check filtering, where we can enter a domain name &amp; instantly see what the result is.</p>
<p>For example, with the default ruleset I&rsquo;ll check to see if 0x2142.com is filtered:</p>
<p><img alt="filter-test-default" loading="lazy" src="/content/images/2022/12/filter-test-default.png#center"></p>
<p>So by default that domain isn&rsquo;t found anywhere, so it will be permitted. The tool also gives us a convenient button to quickly block a domain.</p>
<p>We can click that button, or add the syntax <code>||0x2142.com^</code> to the custom filtering rules at the top of the page (and saving via the <strong>Apply</strong> button). Now if we check the results again - the filter check will show the domain is blocked:</p>
<p><img alt="filter-test-block" loading="lazy" src="/content/images/2022/12/filter-test-block.png#center"></p>
<p>And of course, we don&rsquo;t want to block 0x2142.com!! So let&rsquo;s add this to our allowlist instead, so that it can never be blocked 🙃. We can do that by adding <code>@@||0x2142.com^</code> to the custom filtering.</p>
<p>And now we&rsquo;ll see a green box that shows that the domain is permitted via an allowlist:</p>
<p><img alt="filter-test-allow" loading="lazy" src="/content/images/2022/12/filter-test-allow.png#center"></p>
<h3 id="blocking-known-services">Blocking Known Services</h3>
<p>The other option worth mentioning is the ability to block certain known services, like WhatsApp, Twitter, Reddit, etc. This can be great if there are certain services you want to block, or for use as parental controls.</p>
<p>This can be found on the <strong>Filters &gt; Blocked Services</strong> page.</p>
<p><img alt="blocked-services" loading="lazy" src="/content/images/2022/12/blocked-services.png#center"></p>
<p>This way we can select a service to block, rather than having to know all of the individual domains that service uses. For example, I&rsquo;ll go ahead and select <strong>YouTube</strong> to block - and we&rsquo;ll check that later on after we configure our clients.</p>
<h2 id="configure-opnsense-dhcp-to-use-adguard">Configure OPNsense DHCP to use AdGuard</h2>
<p>Now that we&rsquo;ve taken a quick look at the AdGuard Home settings &amp; have a few things configured - let&rsquo;s look at setting up our clients to use our new DNS server.</p>
<p>In the lab environment I&rsquo;m using, the OPNsense appliance is providing client IP address configuration via Dynamic Host Configuration Protocol (DHCP).</p>
<p>By default, if a specific DNS server is not configured for your client DHCP settings, then OPNsense will provide the clients with the same DNS server it uses. This could have been a DNS server that was configured when you set up OPNsense, or it also can use DNS servers that are provided by your internet service provider.</p>
<p>So to update our LAN DHCP configuration, we&rsquo;ll head back to our OPNsense web interface. From there, we&rsquo;ll navigate to <strong>Services &gt; DHCPv4 &gt; [LAN]</strong>.</p>
<p>In the configuration, there is an open option for <strong>DNS Servers</strong>. We&rsquo;ll set this to our OPNsense LAN IP address. In my case, that is <code>192.168.1.1</code>. Then scroll to the bottom of the page &amp; click <strong>Save</strong>.</p>
<p><img alt="opn-dhcp" loading="lazy" src="/content/images/2022/12/opn-dhcp.png#center"></p>
<h2 id="client-testing">Client Testing</h2>
<p>Now we should be all set up! However, it&rsquo;s important to note that because of the way DHCP works, clients may not pick up the new configuration immediately. When DHCP assigns an IP address, it also tells the client how long it can use that address for. So if a client stays powered-on &amp; connected, it won&rsquo;t ask for new configuration until that timer expires.</p>
<p>We can speed that up by resetting the network interface on our clients. This can be done in a number of ways including rebooting the client or simply disconnecting from wifi/ethernet &amp; reconnecting.</p>
<p>I&rsquo;m using a Linux computer as my test system, so first I&rsquo;ll check via the <code>nslookup</code> command - which will query our configured DNS server &amp; return the resolved IP addresses.</p>
<p>If you remember, I blocked all of YouTube&rsquo;s services earlier:</p>
<p><img alt="client-test-before" loading="lazy" src="/content/images/2022/12/client-test-before.png#center"></p>
<p>As we can see, we did get the correct IP addresses - which means our filtering isn&rsquo;t working yet.</p>
<p>I&rsquo;ll reset the network adapter on the test PC, which will refresh the DHCP configuration - then try again:</p>
<p><img alt="client-test-after" loading="lazy" src="/content/images/2022/12/client-test-after.png#center"></p>
<p>Now that&rsquo;s the result we want! By returning the <code>0.0.0.0</code> result, our client can no longer resolve that domain. So if this was an advertisement or tracking domain, it&rsquo;s now blocked from loading.</p>
<p>And sure enough, if we now try to browse to that site via a web browser - we don&rsquo;t be able to access it:</p>
<p><img alt="client-test-browser" loading="lazy" src="/content/images/2022/12/client-test-browser.png#center"></p>
<h2 id="troubleshooting-blocked-domains">Troubleshooting Blocked Domains</h2>
<p>Okay, so now we know our blocking works&hellip;. But now someone in our home is trying to access YouTube &amp; it&rsquo;s not working. How can we tell if that&rsquo;s our AdGuard service?</p>
<p>Our first stop might be the AdGuard query log. Opening this log, we can filter by domain name or client - or show only blocked queries if we like.</p>
<p>Pretty quickly we can see the issue - we blocked YouTube&rsquo;s services:</p>
<p><img alt="adguard-query-log" loading="lazy" src="/content/images/2022/12/adguard-query-log.png#center"></p>
<p>Now we know how to fix the issue, which would be to unblock that service. However, if it was just a specific domain that was blocked, we would likely want to add it to our custom filtering as we showed earlier.</p>
<h2 id="reporting">Reporting</h2>
<p>Last but not least, we can also check our AdGuard Home dashboard again, which should be much more interesting than before:</p>
<p><img alt="adguard-dashboard-after" loading="lazy" src="/content/images/2022/12/adguard-dashboard-after.png#center"></p>
<p>Here we can quickly see how many queries have been made &amp; how many were blocked for various reasons. We&rsquo;ll also see what clients are using our DNS server, and which are making the most queries.</p>
<p>Most interesting (at least to me), is being able to see the top domains that were queried or blocked. Here&rsquo;s where you might find some interesting information. For example, on my test machine - it&rsquo;s a fresh installation of Ubuntu &amp; we used FireFox to test. But we can see that even during the brief time it&rsquo;s been set up, almost all of the highest queried domains belong to Mozilla&rsquo;s analytics services. So it may be tempting to add those to our custom blocklists.</p>
<h2 id="additional-info">Additional Info</h2>
<h3 id="what-if-i-have-adguard-running-on-a-different-server-or-want-to-keep-using-unbound-dns">What if I have AdGuard running on a different server? Or want to keep using Unbound DNS?</h3>
<p>Sure - we can make both of those work.</p>
<p>For the first scenario, maybe we have AdGuard Home installed &amp; set up on a Raspberry Pi on our network. For that, all we need to do is set that Raspberry Pi as the DNS server in our DHCP configuration on OPNsense. See above where we did that for our on-box AdGuard setup.</p>
<p>For the other situation, perhaps you want to use Unbound on OPNsense, but also AdGuard. There might be reasons for this - like even though Unbound does support DNS blocklists, AdGuard has better reporting tools. But on the other hand, Unbound has more features &amp; configuration options for DNS than Unbound.</p>
<p>In this case, we would want to run AdGuard on a different DNS port (like 65353), then have Unbound forward those to AdGuard. See below if you need to change the port AdGuard uses for DNS.</p>
<p>Within OPNsense, we could go to <strong>Services &gt; Unbound DNS &gt; Query Forwarding</strong>. Then add a new custom forwarding entry. Here we can forward requests for specific domains if we want - or if we want to forward <strong>all</strong> DNS requests, we can leave the domain field empty. Then fill in the AdGuard information - so in my example this would be 192.168.1.1 and port 65353.</p>
<p><img alt="unbound-custom-1" loading="lazy" src="/content/images/2022/12/unbound-custom-1.png#center"></p>
<p>Then click <strong>Save</strong> and <strong>Apply!</strong></p>
<h3 id="how-do-i-change-the-interface--port-for-the-web-ui-or-dns">How do I change the interface / port for the Web UI or DNS?</h3>
<p>So perhaps we mis-typed something when configuring AdGuard. Or just wanted to change the interface IP address AdGuard listens on. No problem!</p>
<p>Unfortunately, since this is a community plugin - there is no configuration for the plugin within the OPNsense interface.</p>
<p>We&rsquo;ll need to reconnect to the OPNsense command line to make some additional configuration changes. This can be done via SSH or the device console.</p>
<p>Once there, we can use the command <code>edit /usr/local/AdGuardHome/AdGuardHome.yaml</code>.</p>
<p>That config file looks like this:</p>
<p><img alt="adguard-config-file" loading="lazy" src="/content/images/2022/12/adguard-config-file.png#center"></p>
<p>At the top, <code>bind_host</code> &amp; <code>bind_port</code> pertains to the admin web interface. A little below there, under the <code>dns</code> section - you&rsquo;ll see another <code>bind_hosts</code> and <code>port</code> config. Those ones are specific to the DNS server side of things.</p>
<p>Once done, save the config file by pressing <code>Esc</code> then selecting to quit the editor &amp; save the file.</p>
<p>Lastly - Go back into the OPNsense web UI &amp; restart the AdGuard Home service for the changes to take effect.</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
