# How to set up a VPN router using Meshnet

## Introduction <a href="#introduction" id="introduction"></a>

[VPN routers](https://nordvpn.com/flashrouters/) are quite common items in many households. This popularity stems from the ease of use and management — they offer full network protection without installing VPN apps on individual devices. Additionally, you can protect devices that don’t natively support VPN apps, such as SmartTVs running TizenOS or WebOS.

In a standard situation, to [set up a VPN on a router](https://nordvpn.com/blog/setup-vpn-router/), you have to upload a VPN server’s configuration file to the router. This keeps the connection restricted to a single server and changing it can be tedious. If you already have a Linux device like a [Raspberry Pi](https://www.raspberrypi.com/), you can configure your own VPN router instead. This keeps you in full control of the configuration, allows swift management of the connection, and provides insight into the world of networking.

By using [Meshnet](https://nordvpn.com/meshnet/) and its [traffic routing](https://meshnet.nordvpn.com/features/routing-traffic-in-meshnet) capabilities, you can create your [own VPN server](https://meshnet.nordvpn.com/how-to/traffic-routing) and connect the router to it at no additional cost. Such a setup allows you to reap the benefits of traffic routing on devices that cannot run Meshnet directly.

This guide showcases how you can use a Linux device as a VPN router with the help of Meshnet.

## Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

Make sure that you have:

* A Linux device with an ethernet connection and a Wi-Fi adapter.
* Access to the Linux device’s command line (can be an [SSH connection](https://meshnet.nordvpn.com/how-to/remote-access/access-remote-systems-over-ssh)).
* A traffic routing [host device](https://meshnet.nordvpn.com/features/routing-traffic-in-meshnet#feature-availability) that will act as [your VPN server](https://meshnet.nordvpn.com/traffic-routing/set-up-your-own-vpn-server#using-your-own-device-as-a-vpn-server).

{% hint style="info" %}
**Note**

In this article, a Raspberry Pi 4 running Raspberry Pi OS Lite 64-bit will be used as the router device.
{% endhint %}

### Update the system and set your WLAN country <a href="#update-the-system-and-set-your-wlan-country" id="update-the-system-and-set-your-wlan-country"></a>

Ensure that your system is up to date and that the correct [wireless local area network](https://nordvpn.com/cybersecurity/glossary/wireless-local-area-network/) (WLAN) country is selected. From the router device’s terminal:

1. Fetch and install all available updates for your system by running the following command:

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo apt update &#x26;&#x26; sudo apt full-upgrade -y
   </code></pre>

   &#x20;
2. Once the process is finished, reboot your device. You can use the `sudo reboot now` command for this.
3. Upon reboot, open the Raspberry Pi configuration tool with this command:

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo raspi-config
   </code></pre>

   &#x20;
4. Navigate to **Localisation options** > **WLAN country**.
5. Choose the country you are currently in and press **Enter**.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FTHHajiw0BGZvnQle7DDA%2Frouter_wlan_country.png?alt=media&#x26;token=d85506c5-e504-45c0-aa04-d9dfb9b327dd" alt="United States selected in the WLAN country selection dialog." width="375"><figcaption></figcaption></figure></div>

   &#x20;&#x20;
6. Select **Finish** to exit the configuration tool.

Your device is now ready to create a new Wi-Fi network.

{% hint style="info" %}
**Note**

The steps for setting the WLAN country may differ depending on the device and Linux distribution you are using. Consult your system’s documentation for detailed instructions.
{% endhint %}

## Create a hotspot connection <a href="#create-a-hotspot-connection" id="create-a-hotspot-connection"></a>

To share a VPN connection, you need to create a new Wi-Fi network that your client devices could connect to. Below you can find two distinct methods for doing so — one using an all-in-one utility called [RaspAP](https://raspap.com/), and the other using [NetworkManager](https://en.wikipedia.org/wiki/NetworkManager). Choose whichever one fits your setup better.

### Method 1: Using RaspAP <a href="#method-1-using-raspap" id="method-1-using-raspap"></a>

RaspAP is a simple tool that turns your Linux device into a wireless access point. It is compatible with most [Debian-based systems](https://docs.raspap.com/#compatible-operating-systems) and can be installed on bare metal or run as a [Docker container](https://docs.raspap.com/docker/). This section will focus on installing RaspAP directly onto the system.

#### Install RaspAP <a href="#install-raspap" id="install-raspap"></a>

You can install RaspAP by using the quick installation script via this command:&#x20;

```bash
curl -sL https://install.raspap.com | bash
```

You will be asked if you want to install certain add-ons during the installation. Provide your answer by using the **Y** and **N** keys and pressing **Enter**.

Once the installation is complete, you will be prompted to reboot your device.

{% hint style="info" %}
**Note**

If you prefer to do the installation by yourself rather than using the installation script, you can follow the manual installation steps from the [RaspAP documentation](https://docs.raspap.com/manual/).
{% endhint %}

#### Access the RaspAP web interface <a href="#access-the-raspap-web-interface" id="access-the-raspap-web-interface"></a>

After rebooting, your device will create a new wireless network called `raspi-webgui`.

<div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Fdg8HgxPyPG4VJRSqjuPj%2Frouter_raspap_web_wifi_dark.png?alt=media&#x26;token=d0f8f16c-9ebe-484d-9b53-9ea093504faf" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FtB9UkKEprs8t5DfviGXk%2Frouter_raspap_web_wifi.png?alt=media&#x26;token=27feea40-4a83-4930-ba16-a8391d463b61" alt="Available Wi-Fi network titled &#x22;raspi-webgui&#x22;."></picture><figcaption></figcaption></figure></div>

To access the RaspAP web interface from another device, connect to the created network using the password `ChangeMe`. Once connected, take these steps:

1. Open your internet browser.
2. In the URL bar, enter `10.3.141.1` and press **Enter**.
3. In the login prompt, enter the default RaspAP web interface credentials.
   * Username: `admin`
   * Password: `secret`

Now you can control your new router right from the web browser.

<figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FSPb1osfRkGpaZzQQxOjA%2Frouter_raspap_webgui_dark.png?alt=media&#x26;token=882df23a-ee58-47cf-ad08-2cd16fa07d0a" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F5SCMvK4W4I7ShV1g6594%2Frouter_raspap_webgui.png?alt=media&#x26;token=b2299618-fd00-4fb6-958c-c330d9a230c5" alt="RaspAP dashboard visible in a browser window."></picture><figcaption></figcaption></figure>

{% hint style="success" %}
**Tip**

Remember to change the default web login password to a different, secure one. To do so, from the menu on the left, select **Authentication**, enter your old and new passwords, and click **Save settings**.
{% endhint %}

#### Secure the Wi-Fi connection <a href="#secure-the-wi-fi-connection" id="secure-the-wi-fi-connection"></a>

To secure your new Wi-Fi network, change the default SSID and password.

1. On your RaspAP web interface, from the menu on the left, select **Hotspot**.
2. In the **SSID** field, enter a custom name for your Wi-Fi network.

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FHJ2mCyrI59PtkGQZvFj6%2Fraspap_ssid_dark.png?alt=media&#x26;token=cec57cfb-0082-45de-a523-46603c8c914f" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2Fvi6zRqHfmZe1RRlrmhH4%2Fraspap_ssid.png?alt=media&#x26;token=8ce1ebc5-da4f-4899-9c81-12300b92ff64" alt="SSID field with a custom name highlighted." width="375"></picture><figcaption></figcaption></figure></div>

   &#x20;&#x20;
3. Switch to the **Security** tab.
4. In the **PSK** field, replace the pre-filled password with your preferred password for the Wi-Fi network.

   <div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FiHRwm9vwpHtjbwpZypQe%2Fraspap_pwd_dark.png?alt=media&#x26;token=f6793c33-ac4f-4c36-afd8-339dd5d6480e" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F1iDWtGRFRNahSmMMsu5h%2Fraspap_pwd.png?alt=media&#x26;token=bec111d2-9806-4039-bd35-eff832171243" alt="PSK field with a new password highlighted." width="375"></picture><figcaption></figcaption></figure></div>

   &#x20;&#x20;
5. Click **Save settings** and **Restart hotspot**.

You should now see a new Wi-Fi network with the custom SSID instead of the previous `raspi-webgui` network.

<div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FvxgZvpnCe6vUSPEB255k%2Frouter_raspap_wifi_dark.png?alt=media&#x26;token=daeabe73-f352-4993-a1c4-27e7db1955b3" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FaEY7zSiwOU0CjfU0q7LD%2Frouter_raspap_wifi.png?alt=media&#x26;token=0e2003d3-ce5c-48de-9b09-a82c442e6a70" alt="Available Wi-Fi network titled &#x22;meshnet-router&#x22;."></picture><figcaption></figcaption></figure></div>

Connect the devices that will use the VPN connection to your newly created Wi-Fi network and proceed to the [Set up Meshnet](#set-up-meshnet) section below.

{% hint style="success" %}
**Tip**

If your device is compatible, consider using the 5 GHz wireless band for improved connection speeds. Select it from the **Wireless mode** dropdown list on the **Hotspot** settings menu.
{% endhint %}

### Method 2: Using NetworkManager <a href="#method-2-using-networkmanager" id="method-2-using-networkmanager"></a>

NetworkManager offers a quick and easy method to create a Wi-Fi network. It can be controlled through [nmcli](https://networkmanager.dev/docs/api/latest/nmcli.html), a command line tool for managing all aspects of the networking service.

Follow the steps below to create a new wireless network using `nmcli`:

1. Open **Terminal**.
2. Check whether NetworkManager recognizes your Wi-Fi adapter by running the following command:

   ```bash
   nmcli device
   ```

   &#x20;

   Under the **Devices** column, you should see `wlan0`.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FChvbCaIuwjwZUqIhI2l3%2Frouter_nmcli_device.png?alt=media&#x26;token=64efbd6b-ad30-4519-aa74-c4db07c6710f" alt="Terminal output of the &#x27;nmcli device&#x27; command and the &#x27;wlan0&#x27; entry underlined."><figcaption></figcaption></figure></div>

   &#x20;&#x20;
3. Create a new hotspot network with the command provided below. Replace `<NAME>` with a custom SSID, and `<PASSWORD>` with a secure password to access the Wi-Fi network.

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo nmcli device wifi hotspot ssid &#x3C;NAME> password &#x3C;PASSWORD> ifname wlan0
   </code></pre>

   &#x20; \
   **Example**

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo nmcli device wifi hotspot ssid meshnet-wifi password s3cur3-w1f1-p4ssw0rd ifname wlan0
   </code></pre>

   &#x20;&#x20;
4. Verify that the new network has been created with the `nmcli connection` command.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FkTznjtPVuO1DkL4934Sg%2Frouter_nmcli_connection.png?alt=media&#x26;token=a1dccba1-8e24-4cf7-a621-b46680b202bc" alt="Terminal output of the &#x27;nmcli connection&#x27; command and the &#x22;Hotspot&#x22; entry underlined."><figcaption></figcaption></figure></div>

Your nearby devices should now see the newly created Wi-Fi network with the custom name.

<div align="left"><figure><picture><source srcset="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FfwzGpGS3wM3AafRF4CSK%2Frouter_nmcli_wifi_dark.png?alt=media&#x26;token=c57b108c-e237-4056-8617-cae56ee602c8" media="(prefers-color-scheme: dark)"><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FVjZ9jmcJ5jDy3w1jccJg%2Frouter_nmcli_wifi.png?alt=media&#x26;token=f6a586d0-5ee8-4934-baec-b34f82ac14b5" alt="Available Wi-Fi network titled &#x22;meshnet-wifi&#x22;."></picture><figcaption></figcaption></figure></div>

This network will share your router device’s internet connection. All you need to do is start routing traffic, and NetworkManager will take care of all the network forwarding to begin transmitting the VPN connection. Continue to the [Set up Meshnet](#set-up-meshnet) section below for further guidance.

## Set up Meshnet

With the networking configurations taken care of, you can install NordVPN and enable Meshnet to finalize the setup.

### Install NordVPN <a href="#install-nordvpn-on-the-virtual-machine" id="install-nordvpn-on-the-virtual-machine"></a>

Follow these steps to install NordVPN on your Linux router device:

1. Download and install the NordVPN Linux client by running the command below.

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sh &#x3C;(wget -qO - https://downloads.nordcdn.com/apps/linux/install.sh)
   </code></pre>

   &#x20;
2. Log in to your NordVPN account.

### Log in to NordVPN <a href="#log-in-to-nordvpn" id="log-in-to-nordvpn"></a>

You can log in to your NordVPN account without the use of a graphical user interface (GUI) in two ways:

* By running the `nordvpn login` command with the `--token` flag
* By running the `nordvpn login` command with the `--callback` flag

Instructions for both methods are outlined below.

<details>

<summary>Log in using a token</summary>

1. On any device, log in to your [Nord Account](https://my.ndaccount.com/) dashboard and select the **Meshnet (by NordVPN)** card.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FxpqHfJyxPLb25uHSZ74I%2Fucp_meshnet_card.png?alt=media&#x26;token=c9bc9798-bc96-4dfc-8ac7-8a3cf1b4538a" alt="&#x22;Meshnet (by NordVPN)&#x22; card highlighted."><figcaption></figcaption></figure></div>

   &#x20;
2. Under **Advanced settings**, select **Get access token**.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FJn3YfCSN2rokFjnMJAzS%2Fucp_get_token.png?alt=media&#x26;token=9f657403-0eff-47af-8da3-4a4837db5d4b" alt="Clicking the &#x27;Set up NordVPN manually&#x27; button."><figcaption></figcaption></figure></div>

   &#x20;
3. Enter the verification code sent to your email address.
4. Under **Access token**, click **Generate new token**.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2F2rdjIz6B8KD69EpvERV2%2Fucp_generate_token.png?alt=media&#x26;token=ca21fa64-1669-4786-945f-d2af2fec5cdb" alt="Clicking &#x27;Generate new token&#x27;."><figcaption></figcaption></figure></div>

   &#x20;
5. In the dialog that appears, choose either a token that expires in 30 days or one that never expires, and then select **Generate token**.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FM44Zi3LCVbbovfM5sCra%2Fucp_generate_new.png?alt=media&#x26;token=c06d9740-1a21-4acd-8246-fc81208576bb" alt="Selecting the token expiry option." width="563"><figcaption></figcaption></figure></div>

   &#x20;
6. Select **Copy and close**.
7. On your router device, run the `nordvpn login --token <your_token>` command, replacing `<your_token>` with the copied token.\
   &#x20;\
   **Example**

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nordvpn login --token 3fe460cefb8dcf1478c92e45908cec9f9bdbadf7a456a6dfb35dc2c58ee39d5b
   </code></pre>

You should now see a welcome message.

</details>

<details>

<summary>Log in using a URL</summary>

1. Run the following command:

   ```
   nordvpn login
   ```

   &#x20;
2. Open the provided link on any device in your browser.
3. Complete the login procedure.
4. Right-click the **Continue** button and select **Copy link address**.
5. Run the `nordvpn login --callback "<URL>"` command, replacing `<URL>` with the previously copied link address.\
   &#x20;\
   **Example**

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nordvpn login --callback "nordvpn://login?action=login&#x26;exchange_token=MGFlY2E1NmE4YjM2NDM4NjUzN2VjOWIzYWM3ZTU3ZDliNDdiNzRjZTMwMjE5YjkzZTNhNTI3ZWZlOTIwMGJlOQ%3D%3D&#x26;status=done"
   </code></pre>

You should now see a welcome message.

</details>

{% hint style="info" %}
**Note**

If you encounter the error message `Whoops! Permission denied accessing /run/nordvpn/nordvpnd.sock`, enter `sudo usermod -aG nordvpn $USER`. Then, reboot your device and log back in.
{% endhint %}

{% hint style="success" %}
**Tip**

To preserve your token when logging out of the NordVPN app, use the `nordvpn logout --persist-token` command. Otherwise, your token will be revoked.&#x20;
{% endhint %}

### Enable Meshnet <a href="#enable-meshnet" id="enable-meshnet"></a>

Upon logging in, you can [enable Meshnet on Linux](https://meshnet.nordvpn.com/getting-started/how-to-start-using-meshnet/using-meshnet-on-linux#enable-meshnet-on-linux) by typing this command:

{% code overflow="wrap" %}

```bash
nordvpn set meshnet on
```

{% endcode %}

To check your server’s Nord name and the Meshnet IP address, enter the following command:

{% code overflow="wrap" %}

```bash
nordvpn meshnet peer list
```

{% endcode %}

**Example**

<div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FdmSe6SVDT1t3NgIQBt4b%2Frouter_peer_list.png?alt=media&#x26;token=e3f0ee9b-a095-4ddb-95c3-27538eb30865" alt=""><figcaption></figcaption></figure></div>

You will also see your Meshnet peer devices with their [corresponding permissions](https://meshnet.nordvpn.com/features/explaining-permissions).

## Share the VPN connection

{% hint style="info" %}
**Note**

Ensure that the device you want to route traffic through has granted your device the [traffic routing permission](https://meshnet.nordvpn.com/features/explaining-permissions/traffic-routing-permissions).
{% endhint %}

Lastly, you should modify the app’s settings to allow connections from local devices and establish a traffic routing connection to share it with nearby devices.

1. On the router device, add the IP range of your new wireless network to the NordVPN firewall’s allowlist.
   * If you set up the Wi-Fi network using RaspAP, use this command:

     <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nordvpn allowlist add subnet 10.4.0.0/16 #For RaspAP
     </code></pre>

     &#x20;&#x20;
   * If you configured the hotspot using NetworkManager, run the command below:

     <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nordvpn allowlist add subnet 10.42.0.0/16 #For NetworkManager
     </code></pre>

     &#x20;&#x20;
2. To retain local access to the router device, add your local network’s IP range to the allowlist with the following command, where `<network>` is your [local area network](https://nordvpn.com/blog/what-is-lan/) (LAN) subnet:

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nordpvn allowlist add subnet &#x3C;network>
   </code></pre>

   &#x20;\
   **Example**

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nordvpn allowlist add subnet 192.168.0.0/16
   </code></pre>

   &#x20;
3. Locate your VPN server device's Nord name using the `nordvpn meshnet peer list` command.

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FGU6DKxKuengWDyLMqoZe%2Frouter_host_name.png?alt=media&#x26;token=eec9ca8b-2639-4380-a4a9-d2711859b7c5" alt="" width="375"><figcaption></figcaption></figure></div>

   &#x20;
4. Initiate a traffic routing connection by running the following command, replacing `<server>` with your VPN server’s Nord name.

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nordvpn meshnet peer connect &#x3C;server>
   </code></pre>

   &#x20;\
   **Example**

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FdHifuxsfdDz66AjVRGmr%2Frouter_mesh_connected.png?alt=media&#x26;token=f8c10eb4-b6b4-4b6d-a68c-1d909a267289" alt=""><figcaption></figcaption></figure></div>

The configuration is now fully complete. All devices connected to your Linux router’s Wi-Fi network will gain the public IP address of the traffic routing VPN connection.
