Wireguard - トラフィックの一部だけをトンネルする方法

Wireguard - トラフィックの一部だけをトンネルする方法

IP アドレスのリスト [A、B、C、...] のみが Wireguard 経由でトンネリングされ、残りのトラフィックは無視されて非 Wireguard インターフェイスを通過するように Wireguard サーバーを設定することは可能ですか?

言い換えると、私は外部の人々に Wireguard VPN へのアクセスを許可しようとしていますが、彼らが VPN を使用して私が指定したもの以外の IP/サイトを閲覧できないようにしたいのです (一方で、彼ら自身の非 VPN インターフェイス/接続では何でもできるようにしたいのです)。

ありがとう

答え1

iptables を使用できます。インターネットに接続するネットワーク インターフェイスとクライアント サブネットに
置き換えます。eth010.6.0.1/24

これをWireguard設定のどこかに挿入します[INTERFACE]

# Drop all outgoing packets from the client subnet
PreUp = iptables -I FORWARD -s 10.6.0.1/24 -o eth0 -j DROP
## Add your exceptions here

例えば:

[Interface]
PrivateKey = ...
Address = 10.6.0.1/24
MTU = 1420
ListenPort = 51820

## Before interface wg0 is up
# Drop all outgoing packets from the client subnet
PreUp = iptables -I FORWARD -s 10.6.0.1/24 -o eth0 -j DROP
# Allow clients to connect to the local network 192.168.0.1/24
PreUp = iptables -I FORWARD -s 10.6.0.1/24 -d 192.168.0.1/24 -j ACCEPT
# Allow clients to connect to tcp port 80 (usually http) on 10.10.0.5
PreUp = iptables -I FORWARD -s 10.6.0.1/24 -d 10.10.0.5 -p tcp --dport 80 -j ACCEPT

## After interface wg0 is down
PostDown = iptables -D FORWARD -s 10.6.0.1/24 -o eth0 -j DROP
PostDown = iptables -D FORWARD -s 10.6.0.1/24 -d 192.168.0.1/24 -j ACCEPT
PostDown = iptables -D FORWARD -s 10.6.0.1/24 -d 10.10.0.5 -p tcp --dport 80 -j ACCEPT

[Peer]
...

クライアント側でシームレスなエクスペリエンスを実現するには、AllowedIPsクライアントの構成でも を構成する必要があります。そうしないと、クライアントは VPN を使用してインターネットにアクセスしようとし、その要求はタイムアウトしてしまいます。

上記の例に従うと、クライアントの設定は次のようになります。

[Interface]
PrivateKey = ...
Address = 10.6.0.2/24
DNS = 10.6.0.1

[Peer]
PublicKey = ...
AllowedIPs = 192.168.0.1/24, 10.10.0.5
Endpoint = ...
PresharedKey = ...

ドキュメンテーション:

関連情報