jpskill.com
🛠️ 開発・MCP コミュニティ

wireguard

WireGuard VPNを構築・管理し、サーバー設定、接続設定、ルーティング、DNS連携などを自動化することで、安全なネットワーク環境を構築・運用するSkill。

📜 元の英語説明(参考)

Deploy and manage WireGuard VPN tunnels. Use when a user asks to set up a WireGuard server, create peer configurations, build mesh networks, configure split tunneling, set up site-to-site links, automate peer provisioning, integrate with DNS (Pi-hole/AdGuard), manage keys, monitor connections, or build WireGuard-based overlay networks. Covers server setup, peer management, routing, DNS integration, and production deployment patterns.

🇯🇵 日本人クリエイター向け解説

一言でいうと

WireGuard VPNを構築・管理し、サーバー設定、接続設定、ルーティング、DNS連携などを自動化することで、安全なネットワーク環境を構築・運用するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o wireguard.zip https://jpskill.com/download/15568.zip && unzip -o wireguard.zip && rm wireguard.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15568.zip -OutFile "$d\wireguard.zip"; Expand-Archive "$d\wireguard.zip" -DestinationPath $d -Force; ri "$d\wireguard.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して wireguard.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → wireguard フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

WireGuard

概要

WireGuard をデプロイします。これは、Linux カーネルに組み込まれた、最新の高性能 VPN プロトコルです。OpenVPN よりもシンプルで、IPsec よりも高速であり、攻撃対象領域が最小限(約 4,000 行のコード)です。このスキルでは、サーバーのセットアップ、ピアの管理、スプリットトンネリング、サイト間リンク、メッシュトポロジー、DNS 統合(Pi-hole/AdGuard)、QR コードによる自動プロビジョニング、および監視について説明します。

手順

ステップ 1: インストールとキーの生成

# Ubuntu/Debian (kernel 5.6+ には WireGuard が組み込まれています)
apt update && apt install -y wireguard wireguard-tools qrencode

# サーバーキーの生成
umask 077
wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key

# ピアキーの生成 (+ オプションでポスト量子耐性用の事前共有キー)
wg genkey | tee client1_private.key | wg pubkey > client1_public.key
wg genpsk > client1_preshared.key

ステップ 2: サーバーの設定

/etc/wireguard/wg0.conf:

[Interface]
Address = 10.10.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
SaveConfig = false

PostUp = iptables -t nat -A POSTROUTING -s 10.10.0.0/24 -o eth0 -j MASQUERADE; iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -s 10.10.0.0/24 -o eth0 -j MASQUERADE; iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT

[Peer]
PublicKey = ALICE_PUBLIC_KEY
PresharedKey = ALICE_PRESHARED_KEY
AllowedIPs = 10.10.0.2/32

eth0 を実際のインターフェースに置き換えて起動します:

IFACE=$(ip route get 1.1.1.1 | awk '{print $5; exit}')
sed -i "s/eth0/$IFACE/g" /etc/wireguard/wg0.conf

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf && sysctl -p
systemctl enable --now wg-quick@wg0
ufw allow 51820/udp

ステップ 3: クライアント/ピアの設定

フルトンネル (すべてのトラフィックを VPN 経由):

[Interface]
PrivateKey = CLIENT_PRIVATE_KEY
Address = 10.10.0.2/32
DNS = 1.1.1.1, 1.0.0.1

[Peer]
PublicKey = SERVER_PUBLIC_KEY
PresharedKey = PRESHARED_KEY
Endpoint = server.example.com:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

スプリットトンネル (特定のネットワークのみ): AllowedIPs10.10.0.0/24, 10.0.0.0/8, 192.168.0.0/16 に変更します。

モバイル用の QR コード: qrencode -t ansiutf8 < client1.conf

ステップ 4: ピアの自動プロビジョニング

#!/bin/bash
# add-peer.sh — キーを生成し、サーバーに追加し、クライアント構成 + QR を作成します
set -e
PEER_NAME=$1; SERVER_IP="your.server.ip"; SERVER_PORT=51820
SERVER_PUBKEY=$(cat /etc/wireguard/server_public.key)
WG_SUBNET="10.10.0"

LAST_IP=$(grep -oP 'AllowedIPs = 10\.10\.0\.\K\d+' /etc/wireguard/wg0.conf | sort -n | tail -1)
NEXT_IP=$((${LAST_IP:-1} + 1))

PRIV=$(wg genkey); PUB=$(echo "$PRIV" | wg pubkey); PSK=$(wg genpsk)

# ピアをライブで追加 + 設定に追加
wg set wg0 peer "$PUB" preshared-key <(echo "$PSK") allowed-ips "${WG_SUBNET}.${NEXT_IP}/32"
cat >> /etc/wireguard/wg0.conf <<EOF

# ${PEER_NAME}
[Peer]
PublicKey = ${PUB}
PresharedKey = ${PSK}
AllowedIPs = ${WG_SUBNET}.${NEXT_IP}/32
EOF

# クライアント構成の生成
mkdir -p ~/wg-clients
cat > ~/wg-clients/${PEER_NAME}.conf <<EOF
[Interface]
PrivateKey = ${PRIV}
Address = ${WG_SUBNET}.${NEXT_IP}/32
DNS = 1.1.1.1, 1.0.0.1

[Peer]
PublicKey = ${SERVER_PUBKEY}
PresharedKey = ${PSK}
Endpoint = ${SERVER_IP}:${SERVER_PORT}
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
EOF

qrencode -t ansiutf8 < ~/wg-clients/${PEER_NAME}.conf
echo "Peer added: ${PEER_NAME} (${WG_SUBNET}.${NEXT_IP})"

ピアの削除: wg set wg0 peer "$PEER_PUB" remove を実行し、wg0.conf を編集してブロックを削除します。

ステップ 5: サイト間 VPN

オフィス A (LAN: 192.168.1.0/24):

[Interface]
Address = 10.10.0.1/24
ListenPort = 51820
PrivateKey = OFFICE_A_PRIVATE
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT

[Peer]
PublicKey = OFFICE_B_PUBLIC
Endpoint = office-b.example.com:51820
AllowedIPs = 10.10.0.2/32, 192.168.2.0/24
PersistentKeepalive = 25

オフィス B は、独自の秘密鍵、オフィス A の公開鍵、および AllowedIPs = 10.10.0.1/32, 192.168.1.0/24 でこれをミラーリングします。どちらも IP 転送を有効にする必要があります。

ステップ 6: DNS 統合と監視

WireGuard サーバー上の Pi-hole:

curl -sSL https://install.pi-hole.net | bash
pihole -a -i wg0
# クライアント DNS を 10.10.0.1 に設定します

監視:

wg show          # アクティブなピア、エンドポイント、転送統計、最後のハンドシェイク
wg show wg0 dump # スクリプト用の機械可読な出力

パフォーマンスチューニング:

sysctl -w net.core.rmem_max=2500000
sysctl -w net.core.wmem_max=2500000
# [Interface] 内: MTU = 1380 (追加のカプセル化を使用するネットワークの場合)

例 1: WireGuard サーバーをデプロイし、5 人のチームメンバーをプロビジョニングする

ユーザープロンプト: 「203.0.113.10 の Ubuntu 22.04 サーバーに WireGuard をセットアップします。alice、bob、carol、dave、eve のピアをフルトンネル構成で作成し、モバイルセットアップ用の QR コードを生成します。」

エージェントは、wireguard と qrencode をインストールし、サーバーキーを生成し、10.10.0.1/24 上のサーバーインターフェースと NAT マスカレードを使用して /etc/wireguard/wg0.conf を作成し、IP 転送を有効にし、add-peer.sh スクリプトを書き込み、5 人のチームメンバーそれぞれに対して実行してキーペアを生成し、ピアブロックをサーバー構成に追加し、フルトンネルルーティング(AllowedIPs 0.0.0.0/0)を使用して個別の .conf ファイルを作成し、それぞれに対して QR コードを表示し、wg-quick サービスを開始します。

例 2: サイト間 WireGuard トンネルを介して 2 つのオフィスネットワークを接続する

ユーザープロンプト: 「オフィス A は 198.51.100.5 にあり、LAN は 192.168.1.0/24 で、オフィス B は 203.0.113.20 にあり、LAN は 192.168.2.0/24 です。両方の LAN が相互に到達できるように、WireGuard サイト間トンネルをセットアップします。」

エージェントは、両方のサーバーでキーペアを生成し、AllowedIPs = 10.10.0.2/32, 192.168.2.0/24 をリストするオフィス B のピアブロックを使用して、オフィス A に wg0.conf を作成し、`AllowedIPs = 10.10. を使用してオフィス B にミラー構成を作成します。

(原文がここで切り詰められています)

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

WireGuard

Overview

Deploy WireGuard — the modern, high-performance VPN protocol built into the Linux kernel. Simpler than OpenVPN, faster than IPsec, with a minimal attack surface (~4,000 lines of code). This skill covers server setup, peer management, split tunneling, site-to-site links, mesh topologies, DNS integration (Pi-hole/AdGuard), automated provisioning with QR codes, and monitoring.

Instructions

Step 1: Installation & Key Generation

# Ubuntu/Debian (kernel 5.6+ has WireGuard built-in)
apt update && apt install -y wireguard wireguard-tools qrencode

# Generate server keys
umask 077
wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key

# Generate peer keys (+ optional preshared key for post-quantum resistance)
wg genkey | tee client1_private.key | wg pubkey > client1_public.key
wg genpsk > client1_preshared.key

Step 2: Server Configuration

/etc/wireguard/wg0.conf:

[Interface]
Address = 10.10.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY
SaveConfig = false

PostUp = iptables -t nat -A POSTROUTING -s 10.10.0.0/24 -o eth0 -j MASQUERADE; iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -s 10.10.0.0/24 -o eth0 -j MASQUERADE; iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT

[Peer]
PublicKey = ALICE_PUBLIC_KEY
PresharedKey = ALICE_PRESHARED_KEY
AllowedIPs = 10.10.0.2/32

Replace eth0 with your actual interface and start:

IFACE=$(ip route get 1.1.1.1 | awk '{print $5; exit}')
sed -i "s/eth0/$IFACE/g" /etc/wireguard/wg0.conf

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf && sysctl -p
systemctl enable --now wg-quick@wg0
ufw allow 51820/udp

Step 3: Client/Peer Configuration

Full tunnel (all traffic through VPN):

[Interface]
PrivateKey = CLIENT_PRIVATE_KEY
Address = 10.10.0.2/32
DNS = 1.1.1.1, 1.0.0.1

[Peer]
PublicKey = SERVER_PUBLIC_KEY
PresharedKey = PRESHARED_KEY
Endpoint = server.example.com:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

Split tunnel (only specific networks): change AllowedIPs to 10.10.0.0/24, 10.0.0.0/8, 192.168.0.0/16

QR code for mobile: qrencode -t ansiutf8 < client1.conf

Step 4: Automated Peer Provisioning

#!/bin/bash
# add-peer.sh — generate keys, add to server, create client config + QR
set -e
PEER_NAME=$1; SERVER_IP="your.server.ip"; SERVER_PORT=51820
SERVER_PUBKEY=$(cat /etc/wireguard/server_public.key)
WG_SUBNET="10.10.0"

LAST_IP=$(grep -oP 'AllowedIPs = 10\.10\.0\.\K\d+' /etc/wireguard/wg0.conf | sort -n | tail -1)
NEXT_IP=$((${LAST_IP:-1} + 1))

PRIV=$(wg genkey); PUB=$(echo "$PRIV" | wg pubkey); PSK=$(wg genpsk)

# Add peer live + to config
wg set wg0 peer "$PUB" preshared-key <(echo "$PSK") allowed-ips "${WG_SUBNET}.${NEXT_IP}/32"
cat >> /etc/wireguard/wg0.conf <<EOF

# ${PEER_NAME}
[Peer]
PublicKey = ${PUB}
PresharedKey = ${PSK}
AllowedIPs = ${WG_SUBNET}.${NEXT_IP}/32
EOF

# Generate client config
mkdir -p ~/wg-clients
cat > ~/wg-clients/${PEER_NAME}.conf <<EOF
[Interface]
PrivateKey = ${PRIV}
Address = ${WG_SUBNET}.${NEXT_IP}/32
DNS = 1.1.1.1, 1.0.0.1

[Peer]
PublicKey = ${SERVER_PUBKEY}
PresharedKey = ${PSK}
Endpoint = ${SERVER_IP}:${SERVER_PORT}
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
EOF

qrencode -t ansiutf8 < ~/wg-clients/${PEER_NAME}.conf
echo "Peer added: ${PEER_NAME} (${WG_SUBNET}.${NEXT_IP})"

Remove a peer: wg set wg0 peer "$PEER_PUB" remove and edit wg0.conf to remove the block.

Step 5: Site-to-Site VPN

Office A (LAN: 192.168.1.0/24):

[Interface]
Address = 10.10.0.1/24
ListenPort = 51820
PrivateKey = OFFICE_A_PRIVATE
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT

[Peer]
PublicKey = OFFICE_B_PUBLIC
Endpoint = office-b.example.com:51820
AllowedIPs = 10.10.0.2/32, 192.168.2.0/24
PersistentKeepalive = 25

Office B mirrors this with its own private key, Office A's public key, and AllowedIPs = 10.10.0.1/32, 192.168.1.0/24. Both need IP forwarding enabled.

Step 6: DNS Integration & Monitoring

Pi-hole on WireGuard server:

curl -sSL https://install.pi-hole.net | bash
pihole -a -i wg0
# Set client DNS to 10.10.0.1

Monitoring:

wg show          # Active peers, endpoints, transfer stats, last handshake
wg show wg0 dump # Machine-readable output for scripting

Performance tuning:

sysctl -w net.core.rmem_max=2500000
sysctl -w net.core.wmem_max=2500000
# In [Interface]: MTU = 1380 (for networks with extra encapsulation)

Examples

Example 1: Deploy a WireGuard server and provision 5 team members

User prompt: "Set up WireGuard on our Ubuntu 22.04 server at 203.0.113.10. Create peers for alice, bob, carol, dave, and eve with full tunnel configs and generate QR codes for mobile setup."

The agent will install wireguard and qrencode, generate server keys, create /etc/wireguard/wg0.conf with the server interface on 10.10.0.1/24 and NAT masquerading, enable IP forwarding, write an add-peer.sh script, run it for each of the five team members to generate key pairs, append peer blocks to the server config, create individual .conf files with full tunnel routing (AllowedIPs 0.0.0.0/0), display QR codes for each, and start the wg-quick service.

Example 2: Connect two office networks over a site-to-site WireGuard tunnel

User prompt: "Office A is at 198.51.100.5 with LAN 192.168.1.0/24 and Office B is at 203.0.113.20 with LAN 192.168.2.0/24. Set up a WireGuard site-to-site tunnel so both LANs can reach each other."

The agent will generate key pairs on both servers, create wg0.conf on Office A with a peer block for Office B listing AllowedIPs = 10.10.0.2/32, 192.168.2.0/24, create the mirror config on Office B with AllowedIPs = 10.10.0.1/32, 192.168.1.0/24, enable IP forwarding and iptables FORWARD rules on both machines, open UDP port 51820 in the firewall, and start wg-quick@wg0 on each side.

Guidelines

  • Always use umask 077 before generating keys so private keys are readable only by root
  • Enable preshared keys (wg genpsk) on all peers for defense-in-depth against future quantum computing attacks
  • WireGuard has no built-in user authentication; access is controlled entirely by key pairs, so treat private keys like passwords and revoke peers by removing their public key from the server
  • Set PersistentKeepalive = 25 for peers behind NAT to keep the UDP session alive; omit it for server-to-server links where both sides have public IPs
  • The AllowedIPs field serves as both a routing table and an ACL; it controls which IPs a peer can send traffic from and which destination IPs get routed to that peer
  • Back up /etc/wireguard/wg0.conf before adding peers since wg-quick will refuse to start if the config has syntax errors