<?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>ubiquiti on Daan Geijs</title>
    <link>https://www.daangeijs.nl/tags/ubiquiti/</link>
    <description>Recent content in ubiquiti on Daan Geijs</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en-us</language>
    <lastBuildDate>Wed, 14 Jun 2023 12:48:00 +0100</lastBuildDate><atom:link href="https://www.daangeijs.nl/tags/ubiquiti/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Setting Up an Isolated Virtual Server in a VLAN on Ubiquiti and Proxmox</title>
      <link>https://www.daangeijs.nl/posts/ubiquiti-vlan/</link>
      <pubDate>Wed, 14 Jun 2023 12:48:00 +0100</pubDate>
      
      <guid>https://www.daangeijs.nl/posts/ubiquiti-vlan/</guid>
      <description>Hosting your own services to be accessed by the public internet comes with its share of challenges, especially when exposing ports security concerns are involved. Cloud hosting providers are a good way to solve some of these problems, but can the costs can rise pretty quickly.</description>
      <content:encoded><![CDATA[<p>Hosting your own services to be accessed by the public internet comes with its share of challenges, especially when exposing ports security concerns are involved. Cloud hosting providers are a good way to solve some of these problems, but can the costs can rise pretty quickly.</p>
<p>In this article I wrote down a  step-by-step walkthrough on creating an isolated environment for hosting services, using a VLAN setup.  By using a VLAN and setting up a firewall we can isolate the virtual server from your primary private network, layering an additional shield of security to your setup. As an example we&rsquo;ll use a virtual machine (VM) hosting a database service as our primary example.</p>
<h3 id="ubiquiti-vlan-configuration">Ubiquiti VLAN Configuration</h3>
<h4 id="1-create-a-vlan">1. Create a VLAN</h4>
<ul>
<li>Log into your <strong>UniFi Controller</strong>.</li>
<li>Navigate to the &ldquo;Settings&rdquo; (gear icon) at the bottom left.</li>
<li>Under &ldquo;Networks&rdquo;, click on &ldquo;Create New Network&rdquo;.</li>
<li>Provide a name for the network, for instance, &ldquo;Public VLAN&rdquo;.</li>
<li>Set &ldquo;Purpose&rdquo; to &ldquo;Corporate&rdquo;.</li>
<li>Assign a VLAN ID of &ldquo;10&rdquo;.</li>
<li>Define the subnet as <code>10.0.0.1/24</code>.</li>
<li>Configure the DHCP range if required and save these settings.</li>
</ul>
<h4 id="2-firewall-rules-for-vlan-traffic">2. Firewall Rules for VLAN Traffic</h4>
<ul>
<li>
<p>Proceed to &ldquo;Routing &amp; Firewall&rdquo; within the settings.</p>
</li>
<li>
<p>Select &ldquo;Firewall&rdquo; and then &ldquo;LAN IN&rdquo;.</p>
</li>
<li>
<p>Set up a rule that permits only PostgreSQL traffic:</p>
<ul>
<li>Name: <strong>Allow PostgreSQL to WAN</strong></li>
<li>Action: <strong>Accept</strong></li>
<li>Source: <strong>Public VLAN</strong></li>
<li>Destination: <strong>Any</strong></li>
<li>Ports: <strong>5432</strong> (PostgreSQL&rsquo;s default port)</li>
</ul>
</li>
<li>
<p>Create rules that block all traffic from the VLAN to other local networks:</p>
<ul>
<li>Name: <strong>Block VLAN to all LANs</strong></li>
<li>Action: <strong>Drop</strong></li>
<li>Source: <strong>Public VLAN</strong></li>
<li>Destination: <strong>All other local networks/VLANs</strong></li>
</ul>
</li>
</ul>
<h4 id="3-port-forwarding">3. Port Forwarding</h4>
<ul>
<li>
<p>Navigate to &ldquo;Routing &amp; Firewall&rdquo; and select &ldquo;Port Forwarding&rdquo;.</p>
</li>
<li>
<p>Click on the &ldquo;+ Create New Rule&rdquo; or &ldquo;Add New Port Forward Rule&rdquo; button, which should open a new window or pane for rule creation.</p>
</li>
<li>
<p><strong>Name</strong>: Give the rule a descriptive name, e.g., &ldquo;PostgreSQL Remote Access&rdquo;.</p>
</li>
<li>
<p><strong>Enabled</strong>: Make sure this is toggled on.</p>
</li>
<li>
<p><strong>Rule Applied</strong>: Set to &ldquo;After Predefined Rules&rdquo;</p>
</li>
<li>
<p><strong>WAN Interface</strong>: Usually set to &ldquo;All&rdquo; unless you have multiple WANs and prefer a specific one.</p>
</li>
<li>
<p><strong>Original IP</strong>: Leave as &ldquo;Any&rdquo; to allow access from any external IP or specify a range/IP if you have a static IP where you&rsquo;ll be connecting from.</p>
</li>
<li>
<p><strong>Original Port</strong>: Set to the PostgreSQL default port, &ldquo;5432&rdquo;.</p>
</li>
<li>
<p><strong>Forward IP</strong>: Enter the IP address of the machine where PostgreSQL is running, in this case, the VM&rsquo;s IP, <code>10.0.0.2</code>.</p>
</li>
<li>
<p><strong>Forward Port</strong>: Again, set this to &ldquo;5432&rdquo;.</p>
</li>
<li>
<p><strong>Protocol</strong>: PostgreSQL typically uses TCP, so set this to &ldquo;TCP&rdquo;. If there are any reasons to believe you need both TCP and UDP, you can set it to &ldquo;Both&rdquo;, but this is usually not necessary for PostgreSQL.</p>
</li>
</ul>
<h3 id="proxmox-vm-configuration">Proxmox VM Configuration</h3>
<h4 id="1-vm-creation-or-modification">1. VM Creation or Modification</h4>
<p>Now lest assign our newly created VLAN to a VM. Either initiate a new VM or select an existing one.</p>
<ul>
<li>Access the Proxmox web interface.</li>
<li>During the setup or via the &ldquo;Network&rdquo; menu for an existing VM:
<ul>
<li>Set the <strong>Bridge</strong>, you can use your default, typically <code>vmbr0</code>.</li>
<li>Assign the <strong>VLAN Tag</strong> to &ldquo;10&rdquo;.</li>
<li>Ensure the firewall is activated.</li>
<li><strong>IPv4/CIDR</strong>: <code>10.0.0.2/32</code></li>
<li><strong>Gateway</strong>: <code>10.0.0.1</code></li>
</ul>
</li>
<li>Once the VM is started or rebooted, it should automatically acquire the assigned static IP.</li>
</ul>
<h3 id="testing-the-configuration">Testing the Configuration</h3>
<h4 id="1-verify-the-ip-address">1. Verify the IP Address</h4>
<ul>
<li>In Proxmox, access the VM&rsquo;s console.</li>
<li>Execute the <code>ifconfig</code> command to ensure that the IP address <code>10.0.0.2</code> has been correctly assigned.</li>
</ul>
<h4 id="2-test-connectivity">2. Test Connectivity</h4>
<ul>
<li>In the same console, check internet access by pinging an external website: <code>ping www.daangeijs.nl</code>.</li>
<li>Subsequently, attempt to ping a device from your private network. This ping should fail, verifying that the VM is isolated from the private network.</li>
</ul>
<p>There you go! You&rsquo;ve successfully set up a VLAN and isolated a VM within it. You can now host services on this VM and access them from the internet, while keeping your private network secure.</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
