
この設定を考慮すると:
2.2.2.2: name: client
WireGuard address: 10.0.0.2
^
|
<internet>
|
v
1.1.1.1: name: gw (ISP router)
LAN address: 192.168.1.1
^
|
v
192.168.3.1: name: wg (br-lan)
WireGuard server
WireGuard address: 10.0.0.3 (wg0)
WAN address: 192.168.1.3 (wan)
クライアント(2.2.2.2)はすべてのwgのアドレス(10.0.0.3、192.168.3.1、192.168.1.3)をpingできますが、gwのlanアドレス(192.168.1.1)をpingすることはできません。
ip route
示す:
default via 192.168.1.1 dev wan src 192.168.1.3 metric 1024
10.0.0.0/24 dev wg0 scope link src 10.0.0.3
10.0.0.2 dev wg0 scope link
192.168.1.0/24 dev wan scope link metric 1024
192.168.3.0/24 dev br-lan scope link src 192.168.3.1
他の答えに基づいてwg(192.168.3.1)で試しました。
ip route add 192.168.1.0/24 via 10.0.0.3 dev wg0
これがうまくいかない場合は、パスを削除してネットワークを再起動してから試しました。
ip route add 192.168.1.0/24 via 192.168.1.3 dev wan
これがうまくいかない場合は、パスを削除してネットワークを再起動してから試しました。
ip route add 192.168.1.0/24 via 192.168.1.1 dev wan
しかし幸運はありません。何が間違っているのか、どんなアイデアがありますか?
PS cat /proc/sys/net/ipv4/ip_forwardは「1」を表示します。
答え1
あなたはどのように見えましたAllowedIPs
かwg.conf
?
両方のネットワークにアクセスするには、次のように表示する必要があります。
AllowedIPs = 10.0.0.2/32, 192.168.1.0/24
その後、WireGuardサーバーでip_forward
Masqueradeを設定し、次の間に渡す必要があります。wan
wg
iptables -t nat -A POSTROUTING -o wan -j MASQUERADE
これにより、ファイアウォールはこれらのパケットをどこに転送するかを知ることができます。
例:
10.10.4.10 - Wireguard Client -> <Internet> -> 10.10.4.1 - Wireguard Server ->
10.10.4.3 - RPI2 at Home acting as a Gateway for VPN -> Hosts in Local Network
WireGuardで自分(ホームルーター)をpingできるようにしたいので、次の192.168.1.1
手順に従う必要があります。
WireGuardサーバーから:
10.10.4.3
変更(RPI)許可IPは次のとおりです。AllowedIPs = 10.10.4.3/32, 192.168.1.0/24
192.168.1.0/24
RPIを介したアクセス用のルーティングルールを追加します。ip route add 192.168.1.0/24 via 10.10.4.3 dev wg0
- WireGuardを再起動します。
wg setconf wg0 /etc/wireguard/wg0.conf
- ネットワーク間転送を許可する
iptables -A FORWARD -s 10.10.4.0/24 -d 192.168.1.0/24 -i wg0 -o wg0 -j ACCEPT iptables -A FORWARD -s 192.168.1.0/24 -d 10.10.4.0/24 -i wg0 -o wg0 -j ACCEPT
- 有効になっていることを確認してください
ip_forward
。# cat /proc/sys/net/ipv4/ip_forward 1
- マスカレーディングの有効化
iptables -t nat -A POSTROUTING -s 10.10.4.0/24 -o eth0 -j MASQUERADE
Raspberry PI (VPN ゲートウェイ)
- 〜できるようにする
ip_forward
echo 1 > /proc/sys/net/ipv4/ip_forward
- マスカレーディングの有効化
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
- ネットワーク間のIP転送を有効にする
iptables -A FORWARD -s 10.10.4.0/24 -d 192.168.1.0/24 -i wg1 -o eth0 -j ACCEPT iptables -A FORWARD -s 192.168.1.0/24 -d 10.10.4.0/24 -i eth0 -o wg1 -j ACCEPT
結果(マイコンピュータ):
$ ping -I wg1 -c 4 192.168.1.1
PING 192.168.1.1 (192.168.1.1) from 10.10.4.10 wg1: 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=62 time=75.5 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=62 time=76.1 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=62 time=74.8 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=62 time=75.5 ms
--- 192.168.1.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 74.802/75.475/76.082/0.454 ms
$ ping -c 4 192.168.1.1
PING 192.168.1.1 (192.168.1.1) 56(84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq=1 ttl=64 time=0.251 ms
64 bytes from 192.168.1.1: icmp_seq=2 ttl=64 time=0.204 ms
64 bytes from 192.168.1.1: icmp_seq=3 ttl=64 time=0.211 ms
64 bytes from 192.168.1.1: icmp_seq=4 ttl=64 time=0.210 ms
--- 192.168.1.1 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3074ms
rtt min/avg/max/mdev = 0.204/0.219/0.251/0.018 ms
私の設定は少し複雑なので、あなたの場合、WireGuardサーバーにルーティングルールを追加する必要はありませんが、次のことを確認する必要があります。
- ファイアウォールルールは配信を許可します。
- MASQUERADEはファイアウォールルールによって有効になります。
- クライアント構成で許可されたIPは、ローカルネットワークへのアクセスを許可します。
- ルータが wg クライアントの ping をブロックする可能性を排除するには、WireGuard クライアントからネットワーク上の他のホストに ping を試みます。