pfsense + WireGuard VPNルータ構築まとめ
投稿日: 2024/05/8
自宅ラボに pfSense + WireGuard VPN を構築し、ルータとして中継できる構成を整える。
pfSense + WireGuard VPNルータ構築まとめ
✅ 目的
外出先のPCやスマホから自宅ネットワークへ安全かつ柔軟にアクセスするため、pfSenseにWireGuard VPNを構築し、ルータとして中継できる構成を整える。
🧱 ネットワーク構成概要
- 自宅ルーター: グローバルIPを持つ
- pfSense:
- WAN: 192.168.0.3(ルーターからDHCP)
- LAN: 192.168.1.1
- WireGuardトンネル: 10.100.0.1/24
- Proxmox等: 192.168.0.x に存在
- クライアント(VPN端末): 10.100.0.2/24 などを割り当て
🛠 手順まとめ
① pfSense に WireGuard パッケージをインストール
- System > Package Manager > Available Packages →
wireguard
をインストール
② トンネル(tun_wg0)作成
- VPN > WireGuard > Tunnels
- Enable Tunnel ✅
- Listen Port: 51820
- Interface Keys: 自動生成
- Interface Addresses:
10.100.0.1/24
を Add Address - Save & Apply Changes
③ Peer(クライアント)追加
- PublicKey: クライアントで生成した公開鍵
- Allowed IPs:
10.100.0.2/32
- Keepalive: 25秒程度推奨
- Save
④ Interface Assignment
- Interfaces > Assignments → tun_wg0 を OPT1 として追加
- Enable にチェック → Save
⑤ Firewallルール追加
-
Firewall > Rules > OPT1 (WireGuard)
- Protocol: any / Source: any / Destination: any → Pass
-
Firewall > Rules > WAN
- UDP 51820 ポートを Pass(VPN受け口)
⑥ Outbound NAT の設定
- Firewall > NAT > Outbound
- 「Manual Outbound NAT」に切り替え → Save
10.100.0.0/24
→192.168.0.0/24
へのルールを追加- Interface: WAN
- Address Family: IPv4
- Source:
10.100.0.0/24
- Destination:
192.168.0.0/24
- Translation Address: Interface address
⑦ クライアント設定(例)
[Interface]
PrivateKey = (クライアント秘密鍵)
Address = 10.100.0.2/24
DNS = 1.1.1.1
[Peer]
PublicKey = (pfSense公開鍵)
Endpoint = (グローバルIP):51820
AllowedIPs = 10.100.0.0/24, 192.168.1.0/24, 192.168.0.0/24
PersistentKeepalive = 25
✅ 動作確認
ping 10.100.0.1
→ OKping 192.168.1.1
(pfSense)→ OKping 192.168.0.150
(Proxmoxなど)→ OKhttps://192.168.0.150:8006
(WebGUI)→ アクセス成功
✅ まとめ
- pfSense を VPNルータとして動かし、複数ネットワークを中継可能にした構成
- セキュアかつルール制御がしやすい
- スマホ・PCなど複数端末にも展開可能
🔐 注意
- pfSenseのFirewallやNATのルールが正しく設定されていないと通信できない
- Interface Address は Tunnel に設定する。OPT1側には設定不要