Setting Up an Ad Blocker + VPN with Tailscale + NextDNS + AWS
Tags: beginners, tutorial, aws
Published: 2023-11-25 06:06:17

## Introduction

In today's digital world, privacy and security are paramount. Tailscale and NextDNS are two powerful tools that can help you protect your online data and improve your browsing experience.

This guide will walk you through setting up Tailscale and NextDNS on AWS, and show you how to use Tailscale as an adblocker and VPN.

## Prerequisites

- Brain and Common Sense
- AWS account
- Amazon EC2 instance
- Tailscale account
- NextDNS account

##Benefits

- Enhanced privacy and security
- Ad-free browsing
- Malware protection
- Secure remote access to your home network

##Target Audience

This guide is for anyone seeking to set up Tailscale and NextDNS on AWS or utilize Tailscale as an adblocker or VPN.


##**A - Create a NextDNS Account**

1. Head to [NextDNS Website](https://nextdns.io/)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w7ra0wegxzstjzmulels.png)

2. Open an account (Do I need to say this? :p)

3. Head to [my.nextdns.io](https://my.nextdns.io/). This is how the main page is supposed to look.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/213kfp9k988ytq0v7vju.png)

##**B - Create a TailScale Account**

1. Head over to [Tailscale Website](https://tailscale.com/)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zsd4dflisev1zirtjkjm.png)

2. Login with Google (best :0)! This is how the Admin Console looks here (while writing the guide)!
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5oek8z1x6rf0lw1xlr2h.png)

3. This is the welcome page. It is waiting for your first device!

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ncc00vxtmiwffght0d80.png)
Click on [Skip this introduction ->](https://login.tailscale.com/admin/machines). This will open the **Machines** section. All your connected devices will appear here!


##**C - Connecting NextDNS to Tailscale**
1. Remember the NextDNS Profile created in Step A? Well, head over to [my.nextdns.io](https://my.nextdns.io/) and note the **ID** under **Endpoints** section. It is **<u>d3f9dd</u>** in my case.
(It is showing 'using another profile' because I am already conected while writing the guide. It will show you 'Not Connected' alongwith a Red Dot)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c3mduo37y1o26u11sjix.png)

2. Get back to Tailscale tab! Head over to **DNS** section
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aijgguzop46m8ou4ag2w.png)

3. Right there in **DNS** section, scroll down and see **Nameservers** subsection. Now look for **Add Nameservers** dropdown menu (locatable under **Global Nameservers**). Click on it, from the dropdown select **NextDNS**.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rwtvxfzzqljkmlwbtj41.png)

4. It will ask for **NextDNS Endpoint**, which is the **NextDNS ID** you just copied in Step 1! Click on **Save**!
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oqvqls2bqm7hs144clpx.png)

5. Turn on **Override Local DNS** (sitting right to **Global Nameservers**)
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x8yuyqh5q4wbluvd1lew.png)
VOILA!! You have successfully connected NextDNS to Tailscale!
What does it means? You can just download Tailscale on your devices and sign-in with the Tailscale account. 

##**D - Connecting your device(s) to Tailscale**
Tailscale has a very intuitive [guide](https://tailscale.com/download/) on setting up your device. Follow that guide to set-up Tailscale on your device.

Once you have done setting up your device, verify the connection.
### 1. Verify NextDNS working or not
On the same device where you have set up Tailscale, login to your [NextDNS account ](https://my.nextdns.io/). A succesful deployment will look like this.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k2a3nwaawdfm0c4qc6si.png)
### 2. Verify using NextDNS Test Page
Head over to [NextDNS Test](https://test.nextdns.io/). You will see a response page which gives the status of your connection alongwith other important information.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23tn82veegfah90c6k1a.png)



##E - Setting up NextDNS as an Adblocker 
THE REAL FUN BEGINS!!
Our first target and priority is to setup an Adblocker. The VPN accomplishes our priority in an easier way by setting up a local home server where we have all our devices interconnected (peer) and we can easily hide our identity and protect ourselves in public networks with some more steps (will be covered in following steps) 

I am providing a Github Repo which details on setting up NextDNS for an ad-free and hassle-free experience.
Link to the repo - https://github.com/yokoffing/NextDNS-Config/blob/main/README.md
(small suggestion - Turn on **AI-Driven Threat Detection**)

### - Verify whether AdBlocker is working or not.
Head over to https://d3ward.github.io/toolz/adblock.html and check the score.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0wcqcwi9t98rds6btjr5.png)
I have a score around 93% which is really impressive!

### - Free? Or Paid??
> No Good things are free in this world!

Whoever said this (or I made this up :p) is true. NextDNS is free only for 300K requests per month! Sounds like a big number? Well it took me only 2 and a half days to reach this limit. :(

You have two options - 
1. Buy the NextDNS Premium Plan  

2. [Contact me](https://tree.panchajanya.dev) to get NextDNS Premium access at a very reasonable price (like you buying me a roadside coffee)! 

##F - Setting up tailscale on Cloud Computer
`You are free to choose the Cloud Provider`
We will be using AWS for setting up a Cloud Computer. Setup EC2 instance (Free Tier is enough). Select Ubuntu LTS 22.04 as OS since it is easier for newbies. 
Once you have successfully created an instance, run these commands.

- Install Tailscale by running the folowing script

 ```shell
  curl -fsSL https://tailscale.com/install.sh | sh
 ```

- Turn on IPv4 forwarding

```shell
echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
```
- Turn on IPv6 forwarding

```shell
echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.conf
```
- Re-execute the sysctl conf file

```shell
sudo sysctl -p /etc/sysctl.conf
```
- Login to Tailscale account

```shell
sudo tailscale up --advertise-exit-node
```
- This will print an URL which you can copy and paste it on browser window which will login your cloud instance with your tailscale account.

- Edit Route Settings for your Cloud Instance on Tailscale. Head over to [Tailscale Dashboard](https://login.tailscale.com/admin/machines) and adjust the route by clicking on **Edit Route Settings** for your recently created Cloud Machine. ( My Cloud Instance is renamed to 'aws'. For you it will be different, something like 'ubuntu-s-<ip><specs>')
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wjxsya1z54ilj4g37lxr.png)
Turn on **Exit Node** as per the screenshot.
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8sx9hdjdf0vzobmhk1aq.png)

- On your different device(s), use this Cloud as **Exit Node** and route all your traffic through this cloud machine. Your location will be decided as per the location of your Cloud Instance.
This is how it looks here - 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ufk0h9mca6jyy6gmusrl.png)

##G - Verify whether the VPN with Exit Node is working or not

I have my Exit Node set to **AWS** which has the following IP **100[dot]106[dot]64[dot]134** 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lo7obhjmkhh8pmgogsur.png)


and my current device is **archlinux** which has the following IP 100[dot]123[dot]75[dot]2 
![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/km4t6pweqixcsxzqzn5y.png)
Now if I check the response page at [NextDNS Test](https://test.nextdns.io/), I can see the `devicename` is set to `aws` and the `deviceIP` is set to `100.106.64.134` regardless of my device's IP is `100.123.75.2`. This signifies that the Internet actually thinks my device is `aws` and not `archlinux`. 
Thus we have set our VPN successfully.

##H - Privacy --- Do You Speak It???
Do follow these steps to align with more privacy when online.
- Switch the log **Storage location** to Switzerland in NextDNS
- Set Quad9 as the default DNS on your Cloud Computer

##Recap
I wrote this guide, making it easier to write and understand. If you feel any problem or if you are here to suggest an improvement, feel free to [contact me](https://tree.panchajanya.dev/).