iptables -t nat -L -n

iptables -t nat -L -n

OpenVPNクライアントを実行している192.168.1.1のルーターに192.168.1.5のDebian Jessieボックスが接続されています(実際にはこの設定。唯一の違いは、Piのeth0 IPがルータによって固定されていることです。つまり、PiはルータのDHCPを使用します。

LANクライアントが192.168.1.5をゲートウェイとして有効にすると、期待どおりにVPNになります。

私にとって必要なのは、192.168.1.128/25内のLANクライアントがすべてのトラフィックを192.168.1.5にリダイレクトすることです。ルータのDHCPによってIPが設定されている場合そのゲートウェイは192.168.1.1になります。つまり、192.168.1.128/25 内のクライアントは、ゲートウェイが 192.168.1.5 のように動作する必要があります。

これを行うには、ルーターは何を実行またはiptables設定する必要がありますか?route add(トマト3.4-138を実行しているルータ)?ルータの設定は次のとおりです。

iptables -t nat -L -n

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
WANPREROUTING  all  --  0.0.0.0/0            wan_ip
upnp       all  --  0.0.0.0/0            wan_ip

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
MASQUERADE  all  --  0.0.0.0/0            0.0.0.0/0
SNAT       all  --  192.168.1.0/24       192.168.1.0/24       to:192.168.1.1
SNAT       all  --  172.16.1.0/24        172.16.1.0/24        to:172.16.1.1

Chain WANPREROUTING (1 references)
target     prot opt source               destination
DNAT       icmp --  0.0.0.0/0            0.0.0.0/0            to:192.168.1.1
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:443 to:192.168.1.1:443
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:2222 to:192.168.1.5:22
DNAT       all  --  0.0.0.0/0            0.0.0.0/0            to:192.168.1.4

Chain pupnp (0 references)
target     prot opt source               destination

Chain upnp (1 references)
target     prot opt source               destination
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:55355 to:192.168.1.130:55355
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:55355 to:192.168.1.130:55355
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:5353 to:192.168.1.48:5353
DNAT       udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:4500 to:192.168.1.48:4500

iptables-L

Chain INPUT (policy DROP)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere             state INVALID
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
shlimit    tcp  --  anywhere             anywhere             tcp dpt:ssh state NEW
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https

Chain FORWARD (policy DROP)
target     prot opt source               destination
           all  --  anywhere             anywhere            account: network/netmask: 192.168.1.0/255.255.255.0 name: lan
           all  --  anywhere             anywhere            account: network/netmask: 172.16.1.0/255.255.255.0 name: lan1
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere             state INVALID
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
DROP       all  --  anywhere             anywhere
DROP       all  --  anywhere             anywhere
wanin      all  --  anywhere             anywhere
wanout     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere
upnp       all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             SIP-Device

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain shlimit (1 references)
target     prot opt source               destination
           all  --  anywhere             anywhere             recent: SET name: shlimit side: source
DROP       all  --  anywhere             anywhere             recent: UPDATE seconds: 60 hit_count: 4 name: shlimit side: source

Chain upnp (1 references)
target     prot opt source               destination
ACCEPT     udp  --  anywhere             client-1                udp dpt:55355
ACCEPT     tcp  --  anywhere             client-1                tcp dpt:55355
ACCEPT     udp  --  anywhere             client-2          udp dpt:mdns
ACCEPT     udp  --  anywhere             client-2          udp dpt:4500

Chain wanin (1 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             *Pi*               tcp dpt:ssh

Chain wanout (1 references)
target     prot opt source               destination

路線

(ルーターはWANモデムの後ろにあります)

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
modem.ip.0.1    *               255.255.255.255 UH    0      0        0 vlan2
192.168.1.0     *               255.255.255.0   U     0      0        0 br0
172.16.1.0      *               255.255.255.0   U     0      0        0 br1
modem.ip.0.0    *               255.255.224.0   U     0      0        0 vlan2
127.0.0.0       *               255.0.0.0       U     0      0        0 lo
default         modem.ip.0.1    0.0.0.0         UG    0      0        0 vlan2

ベストアンサー1

ルータと RaspPi を同じ LAN セグメントに接続できず、RaspPi が他のクライアントが LAN に送信したパケットを書き換えることを期待することはできません。これは、ARPスプーフィングなどの方法を使用したい人によく見られる問題のようです。しかし、Webはそのように動作しません。

きれいな解決策はすべてを置くことです後ろにラズベリーパイ:

Router --- [eth0] RaspPi [eth1] --- Switch +--- Client1
                                           +--- Client2
                                           +--- Client3

デフォルトでは、RaspPiを2番目のルーターとして使用したいと思います。つまり、2 番目の LAN インターフェイスが必要です。ルータに DHCP サーバをインストールし、VPN の RaspPi で NAT をイネーブルにしてサブネットを処理すると、すべての準備が完了します。

別の方法は、VPNを有効にすることです。存在するルータ自体(ルートアクセス権を取得したり、OpenWRTなどをフラッシュできる場合)

別のオプションは、ルーターで DHCP サーバーを無効にすることです。これにより、RaspPiとルーターを同じLANセグメントに接続でき、RaspPiには1つのLANインターフェースのみが必要です。

おすすめ記事