Umleiten des Subnetzverkehrs auf ein anderes Gateway

482
Gaia

Ich habe eine Debian-Jessie-Box bei 192.168.1.5, die an den Router (an 192.168.1.1) angeschlossen ist, auf dem ein OpenVPN-Client ausgeführt wird (es ist tatsächlich ein Pi, der dieses Setup verwendet . Der einzige Unterschied besteht darin, dass die eth0-IP von Pi statisch ist, weil der Router dh das Pi verwendet das DHCP des Routers).

Wenn LAN-Clients 192.168.1.5 als Gateway verwenden, befinden sie sich wie vorgesehen im VPN.

Ich brauche LAN-Clients innerhalb von 192.168.1.128/25, deren gesamten Datenverkehr auf 192.168.1.5 umgeleitet wird, auch wenn ihre IP vom DHCP des Routers festgelegt wird und ihr Gateway 192.168.1.1 wird. Mit anderen Worten, Clients innerhalb von 192.168.1.128/25 sollten so funktionieren, als ob ihr Gateway 192.168.1.5 wäre.

Wie iptablesund / oder muss route addder Router dies tun (der Router führt Tomato 3.4-138 aus)? Dies sind die Router-Einstellungen:

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 

Route

(Router sitzt hinter WAN-Modem)

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 
0

1 Antwort auf die Frage

2
Nevin Williams

Sie können die von DHCP bereitgestellte Standardroute (die eine / 0 ist) schnell überschreiben, indem Sie dem VPN-Gateway zwei / 1-Routen hinzufügen:

route -n add -net 0.0.0.0 192.168.1.5 128.0.0.0

route -n add -net 128.0.0.0 192.168.1.5 128.0.0.0

Während die von DHCP bereitgestellte Standardroute weiterhin vorhanden ist, wird wegen des kürzeren Präfixes einer der / 1-Adressen für IPv4-Verkehr bevorzugt.

Ich benutze diesen Hack derzeit als Proof-of-Concept; Ich bin immer noch online und eine Tabellenabfrage zeigt, dass die / 1-Route verwendet wird.

[nevin-mac-mini: ~] root # route -n add -net 0.0.0.0 192.168.2.1 128.0.0.0 add net 0.0.0.0: Gateway 192.168.2.1 [nevin-mac-mini: ~] root # route -n add -net 128.0.0.0 192.168.2.1 128.0.0.0 add net 128.0.0.0: Gateway 192.168.2.1 
[nevin-mac-mini: ~] root # netstat -rn Routing-Tabellen  Internet: Ziel-Gateway-Flags Refs Verwenden Sie Netif Expire 0/1 192.168.2.1 UGSc 3 0 de0 Standardeinstellung 192.168.2.1 UGSc 4 0 de0 127 127.0.0.1 BKS 0 0 lo0 127.0.0.1 127.0.0.1 UH 1 6576 lo0 128.0 / 1 192.168.2.1 UGSc 1 0 de0 ... 
[nevin-mac-mini: ~] root # route -n erhalten 200.200.200.200 Route bis: 200.200.200.200 Ziel: 128.0.0.0 Maske: 128.0.0.0 Gateway: 192.168.2.1 Schnittstelle: en0 Flaggen:  recvpipe sendpipe ssthresh rtt, mssec rttvar hopcount mtu verfallen 0 0 0 0 0 0 1500 0  [nevin-mac-mini: ~] root #  
Nicht sicher, ob ich folge. Diese Routen zum Pi hinzufügen? Gaia vor 7 Jahren 0
Fügen Sie sie zu jedem Gerät hinzu, das den .5-Host als Gateway verwenden möchte, anstelle des .1-Geräts, das von DHCP bereitgestellt wird. Nevin Williams vor 7 Jahren 0