|
1 | | -# mullvad tailscale / zerotier |
2 | | -<p align="center"><b>Mullvad NF Tables Script</b></p> |
| 1 | +# Mullvad with Tailscale / Zerotier |
| 2 | +<p align="center"><b>Mullvad Nftables script</b></p> |
3 | 3 |
|
4 | 4 | > Note: The script was formerly called `mtc`. It is now `mnf` and has been improved. |
5 | 5 |
|
6 | | -This is a simple bash script that will allow you to run MullvadVPN along with Tailscale or Zerotier in a Linux system. |
| 6 | +This is a simple bash script that will allow you to run Mullvad VPN along with Tailscale or Zerotier on Linux. |
7 | 7 |
|
8 | | -The script is named `mnf` as per `Mullvad NF Tables`. The script was inspired by [this gist](https://gist.github.com/1player/e9cadfef833d5eb5a23c30223f560147), although it now has been completely rewritten and improved. |
| 8 | +`mnf` (for `Mullvad nftables`) was inspired by [this gist](https://gist.github.com/1player/e9cadfef833d5eb5a23c30223f560147), although it has been completely rewritten and improved. |
9 | 9 |
|
10 | | -The script can work with Zerotier and Tailscale. It would most probably also work with any other VPN like NetMaker or Wireguard, but I have not tested it. |
| 10 | +This script works with Zerotier and Tailscale. |
11 | 11 |
|
12 | 12 | ## Features |
13 | | - |
14 | | -- [x] Complete usage guide (and help) |
15 | | -- [x] Bring up Tailscale/Zerotier + Mullvad with a random server |
16 | | -- [x] Connect to a specific country via country code. |
17 | | -- [x] Select a specific rules file |
18 | | -- [x] Select a specific nf table |
| 13 | +- [x] Bring up Tailscale/Zerotier and Mullvad with a random server |
| 14 | +- [x] Connect to a specific country |
19 | 15 | - [x] Blacklist countries to avoid connecting to them |
20 | | -- [x] Use only [RAM-only (no disk) servers](https://mullvad.net/en/blog/2022/8/1/expanding-diskless-infrastructure-to-more-locations-system-transparency-stboot/) |
21 | | -- [x] Set custom DNS server for Mullvad |
22 | | -- [x] Bring down Mullvad VPN and remove nftables entries. |
23 | | -- [x] Bring down all (tailscale/zerotier+mullvad+nftables) |
24 | | -- [x] Automatically update the relay list at stratup |
25 | | -- [x] Only apply nftables configuration and do nothing more |
26 | | -- [x] Only remove nftables configuration and do nothing more |
| 16 | +- [x] Use only [RAM-only (diskless) servers](https://mullvad.net/en/blog/2022/8/1/expanding-diskless-infrastructure-to-more-locations-system-transparency-stboot/) |
| 17 | +- [x] Set custom DNS server(s) for Mullvad |
| 18 | +- [x] Bring down all (tailscale/zerotier+mullvad+nftables) or each one selectively |
| 19 | +- [x] Automatically update the Mullvad relay list at startup |
| 20 | +- [x] and more. |
27 | 21 |
|
28 | 22 | ## Requirements |
29 | 23 |
|
30 | | -- [Mullvad](https://mullvad.net/download/) must be installed in your system so you have the [mullvad cli](https://mullvad.net/en/help/how-use-mullvad-cli/) command available. |
31 | | - |
| 24 | +- [Mullvad](https://mullvad.net/download/) must be installed on your system, so that the [mullvad cli](https://mullvad.net/en/help/how-use-mullvad-cli/) command is available. |
32 | 25 | - Install the `nftables` package. |
33 | | - |
34 | | -- `tailscale` or `zerotier-one` must be installed and configured with its proper setup. |
| 26 | +- `tailscale` or `zerotier-one` must be installed and configured properly. |
35 | 27 |
|
36 | 28 | ## Setup |
37 | | - |
38 | 29 | 1. Clone this repo: |
39 | | - |
40 | 30 | ```bash |
41 | 31 | git clone https://github.com/r3nor/mullvad-tailscale |
42 | 32 | ``` |
43 | | - |
44 | 33 | > Or download and extract the latest release source from [releases page](https://github.com/r3nor/mullvad-tailscale/releases). |
45 | 34 |
|
46 | | -2. Go to cloned dir: `cd mullvad-tailscale` |
47 | | - |
48 | | -3. Set execution permissions on script: |
49 | | - |
| 35 | +2. Go to the cloned dir: `cd mullvad-tailscale` |
| 36 | +3. Make the script executable: |
50 | 37 | ```bash |
51 | | -chmod 700 mnf |
| 38 | +chmod +x mnf |
52 | 39 | ``` |
53 | | - |
54 | 40 | 4. Inspect and **edit** the script file (`mnf`): |
55 | | - |
56 | | -- Change the `RULES_DIR` variable to point to the folder where the `mullvad.rules` file from this repository is located. If you cloned the repo, it should be inside the `mullvad-tailscale` folder. Please, make sure you add the trailing slash (slash at the end). |
57 | | - |
58 | | -- Modify the `EXCLUDED_COUNTRY_CODES` if you want to exclude any countries from the VPN connection (don't connect to these countries). If you do not want to exclude any CC set this variable to `'(none)'`. If you want to add more, just follow the pattern. |
59 | | - |
| 41 | +- Change the `RULES_DIR` variable to point to the directory in which the `mullvad.rules` file from this repository is located. If you cloned the repo, it should be inside the `mullvad-tailscale` folder. |
| 42 | +- Modify the `EXCLUDE_COUNTRY_CODES` variable if you want to exclude any countries from the VPN connection (don't connect to these countries). If you do not want to exclude any country, set this variable to `''`. If you want to add more, just add most two-letter country codes, separated by spaces. |
| 43 | +- Uncomment the `INCLUDE_COUNTRY_CODES` variable if you want to force the connection to specific countries (only connect to these countries). This will override `EXCLUDE_COUNTRY_CODES`. If you want to add more, just add most two-letter country codes, separated by spaces. |
60 | 44 | 5. Edit the `mullvad.rules` file: |
61 | | - |
62 | 45 | - Set your Tailscale/Zerotier network IPs in the `EXCLUDED_IPS` variable (you can use CDIR notation). |
63 | | -- Set your Tailscale/Zerotier network IPv6 IPs in the `EXCLUDED_IPV6` variable (you can use CDIR notation), leave it blank (`= ""`) if there are no IPv6s. |
| 46 | +- Set your Tailscale/Zerotier network IPv6 IPs in the `EXCLUDED_IPV6` variable (you can use CDIR notation). If you do not want IPv6 support, comment this line as well as the one starting with `ip6 daddr $EXCLUDED_IPV6` . |
64 | 47 | - Set your Tailscale/Zerotier DNS resolver in `RESOLVER_ADDRS`. |
65 | | - - Should be `100.100.100.100` for Tailscale. |
66 | | - - If you are using Zerotier, the DNS resolver can be found in the `/etc/resolv.conf` file after running `zerotier-one` service. You will find it in a new line, it should look something like `10.X.X.X`. |
67 | | - |
68 | | -> You can find the Tailscale/Zerotier IPs in your dashboard. Just copy and paste for each of your devices. |
69 | | -
|
70 | | - |
| 48 | + - It should be `100.100.100.100` for Tailscale. |
| 49 | + - If you are using Zerotier, the DNS resolver IP can be found in the `/etc/resolv.conf` file after running `zerotier-one` service. You will find it in a new line. It should look like `10.X.X.X`. |
| 50 | +> You can find the Tailscale/Zerotier IPs in your dashboard. Just use copy and paste for each of your devices. |
71 | 51 | 6. Setup your Mullvad account if you haven't done it yet: |
72 | | - |
73 | 52 | ```bash |
74 | 53 | mullvad account login 1234123412341234 |
75 | 54 | ``` |
76 | 55 |
|
77 | 56 | ## Usage |
78 | | - |
79 | | -For Zerotier users, you should apply `-z` flag on all `up/down` actions. |
80 | | - |
81 | | -> You must be inside the directory where the script is located, or use it with the absolute path to it. If you want to run the command without specifying the folder where it is located, add the script directory to your PATH variable. |
82 | | -
|
| 57 | +> You might want to add `mnf` to your PATH. |
83 | 58 | [Jump to an example usage](#example) |
84 | 59 |
|
85 | 60 | ### up |
86 | 61 | Apply nftables configuration and connect to Mullvad and Tailscale/Zerotier. |
87 | | - |
88 | | -- mnf up [-OPTIONS]: |
89 | | - - -h, --help: Show this help message. |
90 | | - - -r, --ram: No-disk/RAM only Mullvad relays (default: all servers) |
91 | | - - -z, --zerotier: Use Zerotier instead of Tailscale |
92 | | - - -d, --dns: Set custom Mullvad DNS Server (i.e. -d 1.1.1.1) |
93 | | - - -c, --country: Specify a country code to connect to (i.e. -c gb) |
94 | | - - -f, --file: Specify a particular NFT rules file (default: mullvad.rules) |
| 62 | +``` bash |
| 63 | +mnf up [-OPTIONS]: |
| 64 | + -h | --help Show this help message |
| 65 | + -r | --ram No-disk/RAM only Mullvad relays (default: all servers) |
| 66 | + -z | --zerotier Use Zerotier instead of Tailscale |
| 67 | + -d | --dns Set custom Mullvad DNS server (i.e. -d 1.1.1.1 or -d 8.8.8.8,1.1.1.1) |
| 68 | + -c | --country Specify country code(s) to connect to (i.e. -c gb or -c fr,pt,es) |
| 69 | + -f | --file Specify a particular NFT rules file (default: mullvad.rules) |
| 70 | +``` |
95 | 71 |
|
96 | 72 | ### down |
97 | 73 | Bring down Mullvad and remove nftables configuration. |
98 | | - |
99 | | -- mnf down [-OPTIONS]: |
100 | | - - -h, --help: Show this help message. |
101 | | - - -a, --all: Stop Mullvad and Tailscale/Zerotier (default: only stop Mullvad) |
102 | | - - -z, --zerotier: Use Zerotier instead of Tailscale |
103 | | - - -t, --table: Indicate the nft tablename to bring down (default: mullvad-ts) |
| 74 | +``` bash |
| 75 | +mnf down [-OPTIONS]: |
| 76 | + -h | --help Show this help message |
| 77 | + -a | --all Stop Mullvad and Tailscale/Zerotier (default: only stop Mullvad) |
| 78 | + -z | --zerotier Use Zerotier instead of Tailscale |
| 79 | + -t | --table Indicate the nft tablename to bring down (default: mullvad-ts) |
| 80 | +``` |
104 | 81 |
|
105 | 82 | ### conf |
106 | 83 | Apply nftables configuration so Mullvad and Tailscale/Zerotier can work together and do nothing more. |
| 84 | +``` bash |
| 85 | +mnf conf [-OPTIONS]: |
| 86 | + -u Remove the nftables configuration |
| 87 | + -h Show this help message |
| 88 | +``` |
107 | 89 |
|
108 | | -- mnf conf [-OPTIONS]: |
109 | | - - -u: Remove the nftables configuration. |
110 | | - - -h: Show this help message. |
111 | | - |
112 | 90 | ### Example |
| 91 | +`mnf up -rz -d 1.1.1.1 -c ee` |
113 | 92 |
|
114 | | -`bash ~/LINUX/VPN/mnf.sh up -rz -d 1.1.1.1 -c ee` |
115 | | - |
116 | | -or, the same with long flag names: |
| 93 | +or the same command with long flag names: |
117 | 94 |
|
118 | | -`bash ~/LINUX/VPN/mnf.sh up --ram --zerotier --dns 1.1.1.1 --country ee` |
| 95 | +`mnf up --ram --zerotier --dns 1.1.1.1 --country ee` |
119 | 96 |
|
120 | | -The command above would set the connection to Mullvad's RAM-only servers (`-r`) and use Zerotier (`-z`). It would also configure the MullvadVPN DNS to `1.1.1.1` as indicated with the `-d` flag. Finally, the selected country would be Estonia as per the Country Code indicated after the `-c` flag. |
| 97 | +This connects to Mullvad's RAM-only servers (`-r`) in Estonia (`-c ee`) and uses Zerotier (`-z`). It also sets the MullvadVPN DNS to `1.1.1.1` . |
0 commit comments