|
| 1 | +--- |
| 2 | +title: Tailscale site-to-site pfSense - Linux |
| 3 | +date: 2024-04-06 10:00:00 +0200 |
| 4 | +categories: [Networking, VPN] |
| 5 | +tags: [vpn, security, tutorial, tailscale, pfsense] |
| 6 | +description: Setting up Tailscale site-to-site connection between pfSense and Linux |
| 7 | +image: |
| 8 | + path: /assets/img/posts/tailscale-pfsense-banner.webp |
| 9 | + alt: Tailscale Site-to-Site VPN Setup |
| 10 | +--- |
| 11 | + |
| 12 | +I've decided to implement monitoring for my homelab through a cloud virtual machine. As cloud provider I've opted for Hetzner, but more on that in a future post. |
| 13 | + |
| 14 | +To enhance the security of this setup, I've chosen to establish the cloud VM from Hetzner as the single entry point to my infrastructure. For this purpose, I've opted to use Tailscale for tunneling, not only for client-to-site but also for site-to-site connectivity. |
| 15 | + |
| 16 | +## Tailscale Site-to-Site Networking |
| 17 | + |
| 18 | +Information provided by Tailscale: |
| 19 | + |
| 20 | +> Use site-to-site layer 3 (L3) networking to connect two subnets on your Tailscale network with each other. The two subnets are each required to provide a subnet router but their devices do not need to install Tailscale. This scenario applies to Linux subnet routers only. |
| 21 | +{: .prompt-info } |
| 22 | + |
| 23 | +> This scenario will not work on subnets with overlapping CIDR ranges, nor with 4via6 subnet routing. |
| 24 | +{: .prompt-warning } |
| 25 | + |
| 26 | +## Network Architecture |
| 27 | + |
| 28 | +In my case, there are two private subnets without any connectivity between them: |
| 29 | + |
| 30 | +- **Subnet 1 - Homelab**: 10.57.57.0/24 |
| 31 | +- **Subnet 2 - Cloudlab**: 192.168.57.0/24 |
| 32 | + |
| 33 | +IP addresses of the routers for each subnet: |
| 34 | +- **Subnet 1**: 10.57.57.1 (pfSense) |
| 35 | +- **Subnet 2**: 192.168.57.254 (Linux VM) |
| 36 | + |
| 37 | +## Setting up Tailscale on pfSense (Subnet I) |
| 38 | + |
| 39 | +Let's dive into the configuration. Due to pfSense being based on FreeBSD and Tailscale not offering as much support for pfSense as for other platforms, this configuration is a bit trickier. |
| 40 | + |
| 41 | +### Install Tailscale on pfSense |
| 42 | + |
| 43 | +1. Navigate to **System > Package Manager** in the pfSense web interface |
| 44 | +2. Click on the **Available Packages** tab |
| 45 | +3. Search for `tailscale` and click **Install** |
| 46 | + |
| 47 | +### Configure Tailscale on pfSense |
| 48 | + |
| 49 | +Navigate to **VPN > Tailscale** |
| 50 | + |
| 51 | +#### Authentication |
| 52 | + |
| 53 | +1. Copy auth-key from [https://login.tailscale.com/admin/settings/keys](https://login.tailscale.com/admin/settings/keys) |
| 54 | +2. Generate Auth keys |
| 55 | + |
| 56 | +{: width="700" height="400" } |
| 57 | +_Tailscale authentication setup in pfSense_ |
| 58 | + |
| 59 | +#### Basic Configuration |
| 60 | + |
| 61 | +- ✅ **Enable tailscale** |
| 62 | +- **Listen port**: leave as default |
| 63 | +- ✅ **Accept Subnet Routes** |
| 64 | +- ✅ **Advertise Exit Node** (optional) |
| 65 | +- **Advertised Routes**: 10.57.57.0/24 |
| 66 | + |
| 67 | +### Tricky Part: Outbound NAT Rules |
| 68 | + |
| 69 | +Navigate to **Firewall > NAT > Outbound** |
| 70 | + |
| 71 | +#### Configure Outbound NAT Mode |
| 72 | + |
| 73 | +Set to: **Hybrid Outbound NAT** |
| 74 | + |
| 75 | +#### Create Manual Mapping |
| 76 | + |
| 77 | +- **Interface**: Tailscale |
| 78 | +- **Address Family**: IPv4+IPv6 |
| 79 | +- **Protocol**: Any |
| 80 | +- **Source Network or Alias**: 10.57.57.0/24 |
| 81 | +- **Destination**: Any |
| 82 | + |
| 83 | +> This part is broken from last update [23.09.1] so NAT Alias is missing. |
| 84 | +{: .prompt-warning } |
| 85 | + |
| 86 | +**Workaround**: |
| 87 | +- Translation section: |
| 88 | + - **Address**: Network or Alias |
| 89 | + - Put the tailscale IP address: `100.xx.xx.xx/32` |
| 90 | + |
| 91 | +This is how it should look: |
| 92 | + |
| 93 | +{: width="700" height="400" } |
| 94 | +_Outbound NAT configuration for Tailscale_ |
| 95 | + |
| 96 | +## Configure Tailscale on Linux VM (Subnet II) |
| 97 | + |
| 98 | +### Install Tailscale and Enable Routing |
| 99 | + |
| 100 | +```bash |
| 101 | +# Install tailscale |
| 102 | +curl -sSL https://tailscale.com/install.sh | sh |
| 103 | + |
| 104 | +# Activate routing for IPv4 |
| 105 | +echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf |
| 106 | + |
| 107 | +# Activate routing for IPv6 |
| 108 | +echo 'net.ipv6.conf.all.forwarding = 1' | sudo tee -a /etc/sysctl.conf |
| 109 | + |
| 110 | +# Apply routing configuration at kernel level |
| 111 | +sudo sysctl -p /etc/sysctl.conf |
| 112 | +``` |
| 113 | + |
| 114 | +### Advertise Routes on Linux |
| 115 | + |
| 116 | +On the 192.168.57.254 device, advertise routes for 192.168.57.0/24: |
| 117 | + |
| 118 | +```bash |
| 119 | +tailscale up --advertise-routes=192.168.57.0/24 --snat-subnet-routes=false --accept-routes |
| 120 | +``` |
| 121 | + |
| 122 | +**Command explained**: |
| 123 | +- `--advertise-routes`: Exposes the physical subnet routes to your entire Tailscale network |
| 124 | +- `--snat-subnet-routes=false`: Disables source NAT. In normal operations, a subnet device will see the traffic originating from the subnet router. This simplifies routing, but does not allow traversing multiple networks. By disabling source NAT, the end machine sees the LAN IP address of the originating machine as the source |
| 125 | +- `--accept-routes`: Accepts the advertised route of the other subnet router, as well as any other nodes that are subnet routers |
| 126 | + |
| 127 | +## Enable Subnet Routes from Admin Console |
| 128 | + |
| 129 | +> This step is not required if using autoApprovers. |
| 130 | +{: .prompt-info } |
| 131 | + |
| 132 | +1. Open the **Machines** page of the admin console |
| 133 | +2. Locate the devices configured as subnet routers (look for the **Subnets** badge or use the `property:subnet` filter) |
| 134 | +3. For each device, click the ellipsis icon menu and select **Edit route settings** |
| 135 | +4. In the Edit route settings panel, approve the device |
| 136 | + |
| 137 | +> The Tailscale side of the routing is complete! |
| 138 | +{: .prompt-tip } |
| 139 | + |
| 140 | +## Credits |
| 141 | + |
| 142 | +- [Tailscale Documentation](https://tailscale.com/kb/1214/site-to-site#step-2-enable-subnet-routes-from-the-admin-console) - Official site-to-site networking guide |
| 143 | +- [Christian McDonald](https://www.youtube.com/watch?v=Fg_jIPVcioY) - Helpful YouTube tutorial on pfSense Tailscale setup |
0 commit comments