<?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>lxc on Luis Logs</title>
    <link>https://luislogs.com/tags/lxc/</link>
    <description>Recent content in lxc on Luis Logs</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Sun, 02 Jul 2023 18:40:30 +0900</lastBuildDate><atom:link href="https://luislogs.com/tags/lxc/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Keepalived with Pihole for DNS HA</title>
      <link>https://luislogs.com/posts/keepalived-with-pihole-for-dns-ha/</link>
      <pubDate>Sun, 02 Jul 2023 18:40:30 +0900</pubDate>
      
      <guid>https://luislogs.com/posts/keepalived-with-pihole-for-dns-ha/</guid>
      <description>In my previous post about my DNS, I mentioned there that I migrated Pihole from Unraid to my Proxmox hosting my router. But in fact, on top of that, I left an instance of Pihole on Unraid running inside a LXC container. Together with that I also configured keepalived for high availability. Hosting the DNS on the same hypervisor as my router should already be sufficient (I&amp;rsquo;d say my OPNsense VM is more likely to face issues than a LXC container) but I still wanted to try out an use case for keepalived.</description>
      <content:encoded><![CDATA[<p>In my previous post about my DNS, I mentioned there that I migrated Pihole from Unraid to my Proxmox hosting my router. But in fact, on top of that, I left an instance of Pihole on Unraid running inside a LXC container. Together with that I also configured keepalived for high availability. Hosting the DNS on the same hypervisor as my router should already be sufficient (I&rsquo;d say my OPNsense VM is more likely to face issues than a LXC container) but I still wanted to try out an use case for keepalived.</p>
<h3 id="install-gravity-sync">Install Gravity Sync</h3>
<p>Keep in mind that the following IP addresses were used for the setup:</p>
<table>
<thead>
<tr>
<th>IP address</th>
<th>Hostname</th>
<th>Host</th>
</tr>
</thead>
<tbody>
<tr>
<td>10.0.0.80</td>
<td>pihole-ha-ip</td>
<td>-</td>
</tr>
<tr>
<td>10.0.0.81</td>
<td>pihole1b</td>
<td>Proxmox LXC</td>
</tr>
<tr>
<td>10.0.0.81</td>
<td>pihole2b</td>
<td>Unraid LXC</td>
</tr>
</tbody>
</table>
<p>
    <img src="/posts/keepalived-with-pihole-for-dns-ha/pihole-proxmox.png" alt="Proxmox Pihole">
  </p>
<p>
    <img src="/posts/keepalived-with-pihole-for-dns-ha/pihole-unraid.png" alt="Unraid Pihole">
  </p>
<p>I already had one pihole instance running on 10.0.0.80. I just had to shut this down to test my new HA-configured pihole.</p>
<p>To keep the configuration of both piholes in sync, we can install <a href="https://github.com/vmstan/gravity-sync/wiki/Installing">gravity-sync</a>. I faced permission issues when I ran this as root. Make sure you have <code>PermitRootLogin yes</code> set in the <code>/etc/ssh/sshd_config</code> file. Then only execute below installation script.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -sSL https://raw.githubusercontent.com/vmstan/gs-install/main/gs-install.sh <span class="p">|</span> bash
</span></span></code></pre></div><p>The installation procedure is straightforward. Just input the required information and wait for it to complete. You can then conduct a quick test of pulling or pushing configuration.</p>
<p>Create a new domain in pihole1 and ensure it&rsquo;s not reflected on pihole2.</p>
<p>
    <img src="/posts/keepalived-with-pihole-for-dns-ha/keepalived_test.png" alt="Test configuration">
  </p>
<p>You can then execute <code>gravity-sync compare</code> to see if there is any configuration mismatch.</p>
<p>
    <img src="/posts/keepalived-with-pihole-for-dns-ha/gravity_compare.png" alt="Gravity Sync Compare">
  </p>
<p>Then you can execute <code>gravity-sync pull</code> from the pihole2 and check if the delta configuration is reflected.</p>
<p>
    <img src="/posts/keepalived-with-pihole-for-dns-ha/gravity_pull.png" alt="Gravity Sync Pull">
  </p>
<h3 id="automate">Automate</h3>
<p>Execute <code>gravity-sync auto</code> on both pihole instances.</p>
<p>By default pihole should sync after 5 mins. For my setup I will set it hourly.</p>
<p><code>gravity-sync auto hour</code></p>
<h3 id="install-keepalived">Install keepalived</h3>
<p>I found this tutorial on reddit <a href="https://www.reddit.com/r/pihole/comments/d5056q/tutorial_v2_how_to_run_2_pihole_servers_in_ha/">link here</a> shared by <a href="https://www.reddit.com/user/Panja0/">Panja0</a> on how to make use of keepalived by monitoring the pihole-FTL service with a simple bash script. I wanted to try and do it from scratch to add to my knowledge but I have decided to park this for now and test out this tutorial. For those interested, the keepalived documentation can be found <a href="https://keepalived.readthedocs.io/en/latest/installing_keepalived.html">here</a>.</p>
<p>Install libipset13 and keepalived.</p>
<p><code>yum install -y libipset13 keepalived</code></p>
<p>Create a new scripts directory in /etc.</p>
<p><code>mkdir /etc/scripts</code></p>
<p>Create a new file and copy-paste the content from <a href="https://pastebin.com/npw6tcuk">https://pastebin.com/npw6tcuk</a>.</p>
<p>Add permision to execute the file:</p>
<p><code>chmod u+x /etc/scripts/chk_ftl</code></p>
<p>You need to edit keepalived.conf on both pihole instances. This file is located in <code>/etc/keepalived/</code>. The config files can be downloaded in the following links:
<a href="https://pastebin.com/nsBnkShi">keealived.conf for master</a>
<a href="https://pastebin.com/HbdsUc07">keealived.conf for master</a></p>
<p>Modify the following fields according to your IP configuration. The auth_pass field is a password that should be match between both configuration files.
unicast_src_ip
unicast_peer
auth_pass
virtual_ipaddress</p>
<p>Restart the keepalived service and now the IP should be assigned to your primary pihole!</p>
<p><code>sudo systemctl restart keepalived</code></p>
<p>You should now be able to see DNS queries coming in.</p>
<p>
    <img src="/posts/keepalived-with-pihole-for-dns-ha/pihole2a-running.png" alt="">
  </p>
<h3 id="testing-for-auto-fail-over">Testing for auto fail-over</h3>
<p>Shutdown the other pihole. Now pihole2b started accepting traffic</p>
<p>
    <img src="/posts/keepalived-with-pihole-for-dns-ha/pihole-failover.png" alt="">
  </p>
<p>Let’s see if it will preempt. Poweron other pihole and check the keepalived. You can also check 10.0.0.80/admin (virtual ip) and see if it’s routed to the primary .</p>
<p>
    <img src="/posts/keepalived-with-pihole-for-dns-ha/pihole-preempt.png" alt="">
  </p>
]]></content:encoded>
    </item>
    
    <item>
      <title>Run Pihole in an LXC container in Proxmox</title>
      <link>https://luislogs.com/posts/run-pihole-in-an-lxc-container-in-proxmox/</link>
      <pubDate>Mon, 08 May 2023 18:40:30 +0900</pubDate>
      
      <guid>https://luislogs.com/posts/run-pihole-in-an-lxc-container-in-proxmox/</guid>
      <description>Pihole as our local DNS at home has been working perfectly fine. It blocks almost every ad there is whenever I am browsing. I was initially running it as a docker container within my Unraid server. The problem is every time I would restart Unraid for some experimental work, the internet of the entire house also goes down momentarily. I already tried defining a secondary DNS on my DHCP server but noticed some of my devices would randomly pick a DNS if there are multiple defined.</description>
      <content:encoded><![CDATA[<p>Pihole as our local DNS at home has been working perfectly fine. It blocks almost every ad there is whenever I am browsing. I was initially running it as a docker container within my Unraid server. The problem is every time I would restart Unraid for some experimental work, the internet of the entire house also goes down momentarily. I already tried defining a secondary DNS on my DHCP server but noticed some of my devices would randomly pick a DNS if there are multiple defined. Now that I have a Proxmox running OPNsense, I just thought of running Pihole there instead, since anyway I rarely restart that box.</p>
<p>Proxmox already supports LXC containers by default and in this case, running Pihole on LXC provides some advantage in terms of flexibility and ease of configuration. This is especially for those who have less experience working with docker but only with Linux in general. I will share one good use case for this later on but for now let’s start setting up Pihole on Proxmox.</p>
<p>The hardware requirements according to the pihole documentation:
Minimum of 2GB disk (4GB recommended)
512MB RAM</p>
<p>First you need to download an LXC template. I like using debian as the base image since it’s very lightweight and it’s where Ubuntu is based from. If you don’t have it yet, you can download it by going to Datacenter &gt; pve &gt; storage &gt; CT templates &gt; Templates and search for Debian 11 Bullseye.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_2.png" alt="alt text">
  </p>
<p>Click on Create CT and input a container ID, hostname, and the root password. Check Unprivileged container and nesting (optional). Note that nesting is not really required but in my case the proxmox terminal will keep on printing permission errors if I leave this unchecked.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_3.png" alt="alt text">
  </p>
<p>Select debian as the template.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_4.png" alt="alt text">
  </p>
<p>For disk, I assigned 6GB. For RAM, double the recommended, since I have enough.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_5.png" alt="alt text">
  </p>
<p>Assign a static IP to the container. Gateway should also be defined.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_6.png" alt="alt text">
  </p>
<p>For DNS I will assign my unbound IP which is the same as my OPNsense gateway IP. (Unbound is a DNS caching tool built-into OPNsense). This will basically be my upstream DNS for my Pihole. If you don’t have Unbound running then you can input any public DNS like Google (8.8.8.8, 8.8.4.4) or Cloudflare (1.1.1.1).</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_7.png" alt="alt text">
  </p>
<p>Confirm</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_8.png" alt="alt text">
  </p>
<p>Enable start on boot flag.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_9.png" alt="alt text">
  </p>
<p>Login as root</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_10.png" alt="alt text">
  </p>
<p>Update and upgrade</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get update -y <span class="o">&amp;&amp;</span> apt-get upgrade -y
</span></span></code></pre></div><p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_11.png" alt="alt text">
  </p>
<p>Install curl:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">apt-get install curl -y
</span></span></code></pre></div><p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_12.png" alt="alt text">
  </p>
<p>Install Pihole:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -sSL https://install.pi-hole.net <span class="p">|</span> bash
</span></span></code></pre></div><p>Install custom upstream and point to unbound IP</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_13.png" alt="alt text">
  </p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_14.png" alt="alt text">
  </p>
<p>Install the default blacklist.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_15.png" alt="alt text">
  </p>
<p>Install admin interface and lighthttpd.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_16.png" alt="alt text">
  </p>
<p>Query logging or any other option is fine.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_17.png" alt="alt text">
  </p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_18.png" alt="alt text">
  </p>
<p>Reset the pihole password.</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">sudo pihole -a -p
</span></span></code></pre></div><p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_19.png" alt="alt text">
  </p>
<p>Now go to your container IP and append /admin (e.g. http://10.0.0.88/admin)</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_20.png" alt="alt text">
  </p>
<p>If you are running it on proxmox like me you’d probably get the same error as in the snap below. You can ignore this especially if you have multi-core host. If you want to be sure you can check your CPU utilization with the top command.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_21.png" alt="alt text">
  </p>
<p>After changing your DNS to pihole, check with nslookup if your device is able to send and receive to and from the Pihole IP.</p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_22.png" alt="alt text">
  </p>
<p>
    <img src="/posts/run-pihole-in-an-lxc-container-in-proxmox/20230508_23.png" alt="alt text">
  </p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
