【Proxmox VE】パブリックIP 1つで複数VM/CTを動かす 内部DHCP + WireGuard VPN構築ガイド

自動翻訳(Auto Translation)

はじめに

Hetzner等のVPSプロバイダーでProxmox VEを運用する際、パブリックIPが1つしかない環境で複数の仮想マシンやコンテナを動かすには、内部ネットワークの構築が必須です。

この記事では、以下を実現する環境を構築します

・内部ネットワーク(10.0.0.0/24)の構築

・DHCPサーバーによる自動IP割り当て

・WireGuard VPNでの安全なリモートアクセス

・NAT経由でのインターネット接続

環境情報

・サーバー: Hetzner Dedicated Server

OS: Debian 12 (Bookworm)

仮想化: Proxmox VE 8.4

ストレージ: NVMe SSD 512GB × 2(RAID 1)

パブリックIP: 157.180.63.183/26(例)

ネットワーク構成

インターネット

[Proxmox Host: 157.180.63.183]

├─ vmbr1: パブリックネットワーク (157.180.63.183/26)

├─ vmbr0: 内部ネットワーク (10.0.0.1/24)
│ ├─ DHCP: 10.0.0.100 〜 10.0.0.200
│ └─ VM/CT(Community Scripts互換)

└─ wg0: WireGuard VPN (10.0.1.0/24)
└─ リモートクライアント: 10.0.1.x

⚠️ 重要な注意事項

vmbr0を内部ネットワークにするのは、Proxmox Community Scriptsとの 互換性のためです。一般的な構成(vmbr0がパブリック)とは逆なので、 他の記事を参考にする際は注意してください。

ネットワークブリッジの設定

Proxmoxインストール後、ネットワーク設定を行います。

bash
# バックアップを作成
cp /etc/network/interfaces /etc/network/interfaces.backup
# 設定ファイルを編集
vi /etc/network/interfaces
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback
iface lo inet6 loopback
# 物理インターフェース(ブリッジに接続)
auto enp5s0
iface enp5s0 inet manual
# 内部ネットワーク用ブリッジ(vmbr0)
auto vmbr0
iface vmbr0 inet static address 10.0.0.1/24 bridge-ports none bridge-stp off bridge-fd 0 post-up echo 1 > /proc/sys/net/ipv4/ip_forward post-up iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -o vmbr1 -j MASQUERADE post-down iptables -t nat -D POSTROUTING -s 10.0.0.0/24 -o vmbr1 -j MASQUERADE
# パブリックネットワーク用ブリッジ(vmbr1)
auto vmbr1
iface vmbr1 inet static address 157.180.63.183/26 gateway 157.180.63.129 bridge-ports enp5s0 bridge-stp off bridge-fd 0 up route add -net 157.180.63.128 netmask 255.255.255.192 gw 157.180.63.129 dev vmbr1
iface vmbr1 inet6 static address 2a01:4f9:3100:4a46::2/64 gateway fe80::1
ポイント

vmbr0: 内部ネットワーク(物理接続なし)

vmbr1: パブリックネットワーク(enp5s0に接続)

post-up: NAT設定で内部ネットワークからインターネットへのアクセスを可能にする

設定の適用

bash
# ネットワーク設定を再起動
systemctl restart networking
# 確認
ip addr show
brctl show

DHCPサーバーのセットアップ

内部ネットワークのVM/CTに自動的にIPアドレスを割り当てるため、dnsmasqを使用します。

dnsmasqのインストール

bash
# dnsmasqをインストール
apt update
apt install -y dnsmasq

dnsmasqの設定

bash
# バックアップを作成
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
# 新しい設定ファイルを作成
vi /etc/dnsmasq.conf
# vmbr0(内部ネットワーク)でのみDHCPを提供
interface=vmbr0
# DHCPの範囲: 10.0.0.100 〜 10.0.0.200
dhcp-range=10.0.0.100,10.0.0.200,12h
# デフォルトゲートウェイ
dhcp-option=3,10.0.0.1
# DNSサーバー(Cloudflare DNS)
dhcp-option=6,1.1.1.1,1.0.0.1
# ドメイン名
domain=internal.local
# 他のDHCPサーバーからのリクエストを無視
dhcp-authoritative
# DNSキャッシュサイズ
cache-size=1000
# ログ設定
log-dhcp
log-queries

dnsmasqの起動

bash
# dnsmasqを有効化して起動
systemctl enable dnsmasq
systemctl restart dnsmasq
# 状態確認
systemctl status dnsmasq

WireGuard VPNのセットアップ

WireGuardのインストール

bash
# WireGuardをインストール
apt install -y wireguard
# 設定ディレクトリを作成
mkdir -p /etc/wireguard

鍵の生成

bash
# サーバー用の秘密鍵と公開鍵を生成
wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key
# クライアント用の秘密鍵と公開鍵を生成
wg genkey | tee /etc/wireguard/client_private.key | wg pubkey > /etc/wireguard/client_public.key
# 権限設定
chmod 600 /etc/wireguard/*.key
# 鍵を確認
echo "=== サーバー秘密鍵 ==="
cat /etc/wireguard/server_private.key
echo ""
echo "=== サーバー公開鍵 ==="
cat /etc/wireguard/server_public.key
echo ""
echo "=== クライアント秘密鍵 ==="
cat /etc/wireguard/client_private.key
echo ""
echo "=== クライアント公開鍵 ==="
cat /etc/wireguard/client_public.key

サーバー設定ファイルの作成

bash
vi /etc/wireguard/wg0.conf
[Interface]
Address = 10.0.1.1/24
ListenPort = 51820
PrivateKey = <サーバー秘密鍵をここに貼り付け>
# IP転送を有効化
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]
# クライアント1
PublicKey = <クライアント公開鍵をここに貼り付け>
AllowedIPs = 10.0.1.2/32
bash
# 権限設定
chmod 600 /etc/wireguard/wg0.conf

ファイアウォール設定

bash
# WireGuard用のポート51820を開放
iptables -A INPUT -p udp --dport 51820 -j ACCEPT
# 設定を永続化
apt install -y iptables-persistent
netfilter-persistent save

WireGuardの起動

bash
# WireGuardを有効化して起動
systemctl enable wg-quick@wg0
systemctl start wg-quick@wg0
# 状態確認
wg show

クライアント設定

bash
vi /etc/wireguard/client.conf
[Interface]
PrivateKey = <クライアント秘密鍵をここに貼り付け>
Address = 10.0.1.2/24
DNS = 10.0.0.1
[Peer]
PublicKey = <サーバー公開鍵をここに貼り付け>
Endpoint = 157.180.63.183:51820
AllowedIPs = 10.0.0.0/24, 10.0.1.0/24
PersistentKeepalive = 25

クライアント側のセットアップ

WireGuardクライアントをダウンロード:

設定をインポート:

・WireGuardアプリを開く

・「トンネルを追加」→「空のトンネルから作成」

・上記の client.conf の内容を貼り付け

・保存して「有効化」

接続テスト

bash
# VPN経由でProxmoxホストにping
ping 10.0.1.1
# 内部ネットワークのゲートウェイにping
ping 10.0.0.1
# Proxmox Web UIにアクセス(VPN経由)
# ブラウザで https://10.0.0.1:8006

これで、DHCPによって自動的に割り当てられたIPアドレスに接続することで、仮想マシンやコンテナを操作できるようになります。

    この記事は役に立ちましたか?



    広告ブロック機能を検知しました

    このウェブサイトは広告収益によって成り立っています。ご協力をお願いします。