> ## Documentation Index
> Fetch the complete documentation index at: https://www.latitude.sh/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Private networks

> Private networking allows you to group servers within the same location, enabling private communication between them

Latitude.sh servers are configured with a public and a private interface on a Layer 3 network topology by default. With private networking, you can switch to a Layer 2 topology, allowing for L2 traffic between two or more instances.

Layer 2 packets don't go through the network layer, and traffic is not filtered in any way. Latitude.sh does not charge for traffic from private networks, either inbound or outbound.

## Benefits & use cases

Private networking provides a myriad of benefits, with the most important ones being:

* Traffic doesn't go through the public internet, enhancing security.
* Private network traffic doesn't count against your bandwidth quota.

This feature is especially useful when you don't want or need traffic from specific servers going through the public internet. Common use cases include:

* Connecting a database server to a web application privately.
* Managing internal services like DHCP.
* Setting up Kubernetes clusters with direct node communication.

<img src="https://mintcdn.com/latitudesh/jTa6J8Hv5F4W4vnJ/images/product/28.Docs25Q4.CreateVLAN.png?fit=max&auto=format&n=jTa6J8Hv5F4W4vnJ&q=85&s=244ae8256772fff70363fff844c38487" alt="Create VLAN interface" width="1656" height="866" data-path="images/product/28.Docs25Q4.CreateVLAN.png" />

## Setup

### Step 1: Create a VLAN

The first step is to create a Virtual Network — commonly referred to as VLAN.

<Tabs>
  <Tab title="From the dashboard">
    <Steps>
      <Step title="Create a VLAN">
        [Log in to the dashboard](https://www.latitude.sh/dashboard), select a
        project, navigate to **Networking → Private networks** in the sidebar menu,
        and click **Create VLAN**. Select the location and add a description to help
        you identify what the VLAN is used for.
      </Step>
    </Steps>
  </Tab>

  <Tab title="Using the API">
    <Steps>
      <Step title="Use the API">
        Use the [/virtual\_networks](https://www.latitude.sh/docs/api-reference/create-virtual-network) endpoint to create a VLAN.
      </Step>
    </Steps>
  </Tab>
</Tabs>

### Step 2: Assign servers

After creating the VLAN, assign at least two servers to allow the server's private IPs to communicate.

<img src="https://mintcdn.com/latitudesh/jTa6J8Hv5F4W4vnJ/images/product/29.Docs25Q4.VLANassign.png?fit=max&auto=format&n=jTa6J8Hv5F4W4vnJ&q=85&s=a16417aa52e598d649b95e39015f46a0" alt="Assign servers to VLAN" width="2940" height="1450" data-path="images/product/29.Docs25Q4.VLANassign.png" />

<Steps>
  <Step title="Assign servers to the VLAN">
    Go to the Virtual Network you created and click **Assign**. Select the
    server you'd like to assign - only servers from the facility the virtual
    network was created in will be listed. Save and wait a few seconds while the
    network is provisioned.
  </Step>
</Steps>

### Step 3: Configure the OS

The network provisioning on Latitude.sh switches is handled automatically after you assign your first server to a VLAN. Latitude.sh has no access to your servers, an additional step is required, and you need to configure the VLAN on your Operating System.

<Tabs>
  <Tab title="Ubuntu">
    <Steps>
      <Step title="Load the 8021q module into the kernel and install the VLAN package">
        ```bash theme={null}
        sudo modprobe 8021q
        sudo apt install vlan
        ```
      </Step>

      <Step title="Change netplan">
        Change the Netplan configuration file in `/etc/netplan/50-cloud-init.yaml` and add the configuration below to the end of the file.

        * Replace `{{VID}}` with the **VID** value from the VLAN you created.
        * Replace `10.8.0.1` with a private address of your choice. This address becomes the private IP of the server within the VLAN. It can be anything you want, but each server in the same VLAN needs a different IP.
        * Replace `eno2` with the correct interface name. For servers with bonded interfaces, use bond0.

        ```yaml theme={null}
          vlans:
            vlan.{{VID}}:
              id: {{ VID }}
              link: eno2
              addresses: [10.8.0.1/24]
        ```

        <Warning>
          The `vlans` section should be at the same indentation level as the `ethernets` key.
        </Warning>
      </Step>

      <Step title="Adding a default route">
        Due to eventual changes in Netplan versions, to use [Cloud Gateway](/networking/cloud-gateway), you need to define a default route to ensure proper network routing.
        You can do that by adding the following routes section under the vlans key:

        ```yaml theme={null}
        routes:
          - to: 10.8.0.0/16
            via: 192.168.0.1
        ```

        * Replace `10.8.0.0/16` with the network prefix you want to reach through eno2.

        * Replace `192.168.0.1` with the gateway IP address for your network (typically the first IP of your subnet).
      </Step>

      <Step title="Save the file and apply the configuration">
        ```shell theme={null}
        sudo netplan apply
        ```

        This configuration is persistent, you don't need to do anything else.
      </Step>
    </Steps>
  </Tab>

  <Tab title="Windows">
    This will show you how to set up multiple VLANs on a single network interface when using Windows Server 2012 or later.

    <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/product/1265233-ws-required-setup.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=5d1c16b8bf543f37a9d23a4ac2ea1a88" alt="Windows Server Private VLAN required setup." width="1200" height="297" data-path="images/product/1265233-ws-required-setup.png" />

    1. If you want to configure a single VLAN in the interface, go to **Network Connections > Properties > Advanced tab > Select the VLAN ID** field and add the desired value.

    If you want multiple VLANs in the same interface, make sure that the property **VLAN ID is set to 0** - otherwise, it will not work.

    <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/product/724f944-VLANs-config-1.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=b96ed9e1ec0d5b3dff9ff1a6dc3144c6" alt="Setting the VLAN ID property to 0 when setting up multiple VLANs in the same interface." width="407" height="493" data-path="images/product/724f944-VLANs-config-1.png" />

    2. Access your server's IPMI via the [Remote access](/servers/remote-access) feature.

    3. On your IPMI interface go to **Server Manager > Local server** and click on **NIC Teaming**.

           <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/product/4a3f0e9-VLANs-config-02.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=67020da5f756f2431dfd287efb30b883" alt="NIC Teaming on your server's IPMI interface." width="1198" height="622" data-path="images/product/4a3f0e9-VLANs-config-02.png" />

    4. Create a new Team with a single interface by going to **Teams > Tasks > New Team**. Select the desired interface (e.g. 40GbE) and give it a name. Once you create the Team, your IP configuration will be cleaned and your server's internet connection will be lost until the end of the process. **Select your secondary interface for the private VLAN**.

           <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/product/92fbe55-VLANs-config-03.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=3d5471a84aafa5a66bf8f5c89a283391" alt="Creating a new team with a single interface for VLAN configuration" width="533" height="506" data-path="images/product/92fbe55-VLANs-config-03.png" />

    5. Go to **Adapter and Interfaces** and click on **TASKS > Add Interface**. The first interface needs to have the **VLAN ID 0 (zero)** or **Default**.

           <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/product/7b92799-VLANs-config-04.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=7d8dbe1da6a453b18b182393e55cc6ca" alt="Adding a new interface with VLAN ID 0 for default configuration" width="1200" height="624" data-path="images/product/7b92799-VLANs-config-04.png" />

    6. Configure the specific VLAN and click OK. The VLAN ID that you need to configure is the same displayed on your dashboard.

           <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/product/bb15aad-VLANs-config-05.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=107faa8fd6f69605183cdc5e4c112789" alt="Configuring the specific VLAN ID that matches the dashboard settings" width="536" height="414" data-path="images/product/bb15aad-VLANs-config-05.png" />

    7. To add another VLAN interface on the same port, repeat step #4.

           <img src="https://mintcdn.com/latitudesh/ELzsuRnxGwFWx5KO/images/product/f86d34b-VLANs-config-06.png?fit=max&auto=format&n=ELzsuRnxGwFWx5KO&q=85&s=fa17f192b186511aeac446ace69a650a" alt="Adding another VLAN interface on the same port for multiple VLAN setup" width="1194" height="621" data-path="images/product/f86d34b-VLANs-config-06.png" />

    8. To assign an IP address to the new interface, click on **Network Connections**, and find the VLAN interface you have just added. Then, configure the IP similarly to any other interface. You need to configure the VLAN 0 with your public IP.

    You can configure any IP address in your private VLAN (e.g.: 10.10.10.1/24) and you don't need to configure a Gateway in the private interfaces. Gateway information is only mandatory for ' Public' Interfaces.

    <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/product/2e93020-VLANs-config-07.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=846c5d0f6fab466959a18c7ca098d724" alt="Configuring IP address for the new VLAN interface in Network Connections" width="995" height="596" data-path="images/product/2e93020-VLANs-config-07.png" />

    Let's say you created three VLAN interfaces (VLANs 1,2,3) on the teaming interface and add three IP addresses, here is what you should see on the Server Manager window:

    <img src="https://mintcdn.com/latitudesh/_9x7641lGNJX3WXB/images/product/660e44f-VLANs-config-08.png?fit=max&auto=format&n=_9x7641lGNJX3WXB&q=85&s=74ff64f694451004b7b5afac7a6e3d8f" alt="Server Manager window showing three configured VLAN interfaces with assigned IP addresses" width="782" height="479" data-path="images/product/660e44f-VLANs-config-08.png" />

    **Troubleshooting**

    * If you try to configure multiple VLANs, make sure that the value of the VLAN ID field in the properties Advanced tab is equal to 0.
    * Do not configure the primary virtual interface with the VLAN ID, as it needs to be on its default configuration (VLAN ID 0). When the port configuration is set up to native VLAN, do not change this VLAN configuration.
  </Tab>

  <Tab title="CentOS and RedHat Enterprise Linux">
    <Steps>
      <Step title="Load the 8021q module">
        In Red Hat Enterprise Linux and Centos 7, the 8021q module is loaded by default. If necessary, you can make sure that the module is loaded by issuing the following command as root:

        ```shell theme={null}
        modprobe --first-time 8021q
        modprobe: ERROR: could not insert '8021q': Module already in kernel
        ```
      </Step>

      <Step title="Display module information">
        To display information about the module, issue the following command:

        ```shell theme={null}
        modinfo 8021q
        ```
      </Step>

      <Step title="Additional options">
        See the `modprobe(8)` man page for more command options.
      </Step>
    </Steps>
  </Tab>
</Tabs>

## Additional Resources

<AccordionGroup>
  <Accordion title="Setting up 802.1Q VLAN tagging using IFCFG files">
    <Steps>
      <Step title="Configure the parent interface">
        Configure the parent interface in `/etc/sysconfig/network-scripts/ifcfg-eno2`.

        ```bash theme={null}
        DEVICE=eno2
        TYPE=Ethernet
        BOOTPROTO=none
        ONBOOT=yes
        ```
      </Step>

      <Step title="Set the VLAN interface configuration">
        Set the VLAN interface configuration in the `/etc/sysconfig/network-scripts/ directory`. The configuration file name should be the parent interface plus a `.` character followed by the VLAN ID number. For example, if the VLAN ID is 192, and the parent interface is eth0, then the configuration file name should be `ifcfg-eno2.192`:

        ```bash theme={null}
        DEVICE=eno2.192
        BOOTPROTO=none
        ONBOOT=yes
        IPADDR=192.168.1.1
        PREFIX=24
        NETWORK=192.168.1.0
        VLAN=yes
        ```
      </Step>

      <Step title="Set up the second VLAN">
        If there is a need to configure a second VLAN, with, for example, VLAN ID 193, on the same interface, eno2, add a new file with the name `eno2.193` with the VLAN configuration details. Restart the networking service in order for the changes to take effect. As `root` issue the following command:

        ```shell theme={null}
        systemctl restart network
        ```
      </Step>
    </Steps>
  </Accordion>
</AccordionGroup>
