0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Tailscale Subnet RouterとWireGuardメッシュ網で構築するセキュアな宅内インフラ遠隔管理基盤

0
Posted at

Chapter 004 Cover

概要

本稿では、Raspberry Pi 4BとIntel N100ミニPCを冗長化エッジルーターとし、 Tailscale(WireGuard)によるP2Pメッシュネットワークおよびサブネットルーティング基盤 を構築する実践的なエンジニアリングガイドを提示します。

従来のポート開放やOpenVPN中央集権型構成が抱える課題(SPOF、遅延増加、MTU不整合によるフリーズ)を解決し、外出先のモバイル回線から宅内LAN(192.168.3.0/24)の内部サービスへ安全かつ透過的にアクセス可能にします。

Mesh vs Traditional VPN Matrix


技術要件と物理トポロジー

  • Primary Gateway (pi4b) : Raspberry Pi 4B (4GB), IP: 192.168.3.2, Tailscale IP: 100.90.10.2
  • Secondary Gateway (n100) : Intel N100 (8GB), IP: 192.168.3.8, Tailscale IP: 100.90.10.8
  • Target Subnet : 192.168.3.0/24 (K3sクラスタ、PostgreSQL、管理ノード群)

Tailscale Mesh Topology


セットアップ手順

1. カーネル転送パラメータの永続化

sudo tee /etc/sysctl.d/99-tailscale.conf << 'EOF'
net.ipv4.ip_forward = 1
net.ipv6.conf.all.forwarding = 1
net.core.rmem_max = 2500000
net.core.wmem_max = 2500000
EOF

sudo sysctl -p /etc/sysctl.d/99-tailscale.conf

2. TCP MSSクランピングによるパケット破棄防止

WireGuard仮想IF(MTU 1280)と物理NIC(MTU 1500)の境界で発生するTCP通信の停止(PMTUブラックホール現象)を防ぐため、MSSクランピングを適用します。

sudo iptables -t mangle -A FORWARD -o tailscale0 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
sudo iptables -t mangle -A FORWARD -i tailscale0 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu

3. サブネットおよびExit Nodeの広報

sudo tailscale up \
  --advertise-routes=192.168.3.0/24 \
  --advertise-tags=tag:infra \
  --advertise-exit-node \
  --accept-dns=false \
  --reset

ステージング環境(検証環境)の分離原則
検証ノードが本番と同一のTailnetで 192.168.3.0/24 を広報すると、本番トラフィックの誤ルーティング(ハイジャック)が発生します。ステージング機(192.168.3.192/26 等)では単一ホスト経路(${PRIMARY_IP}/32)および専用タグ tag:staging を用いて広報し、ACLポリシー(autoApprovers.routes["192.168.3.192/26"] = ["tag:staging"])で厳格に分離します。

4. Exit Node用NATマスカレード

sudo iptables -t nat -A POSTROUTING -s 100.64.0.0/10 -o eth0 -j MASQUERADE
sudo iptables -I FORWARD 1 -i tailscale0 -o eth0 -j ACCEPT
sudo iptables -I FORWARD 2 -i eth0 -o tailscale0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

SRE検証:Pythonによる自動監査テスト

標準ライブラリのみで書かれた検証スクリプト ./code/tailscale-mesh-audit.py により、MTU耐性試験とP2P接続状態を自動監査します。

# Overlay網でのMTU耐性テスト
python3 code/tailscale-mesh-audit.py --benchmark-mtu --target-ip 100.73.8.122

判定基準

  • 直接P2P確立 : tailscale status で direct 接続確認 (UDP 41641番でのダイレクト疎通)
  • MTU耐性 : 1280バイトパケットの欠損なし、MSSクランプ正常動作

次回は、第005章「宅内名前解決の基盤:dnsmasqによるスプリットホライズンと漏洩防止」を解説します。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?