
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 스푸핑과 같은 방법을 사용하려는 사람들에게 흔히 발생하는 문제인 것 같습니다. 하지만 웹은 그런 식으로 작동하지 않습니다.
깨끗한 해결책은 모든 것을 넣는 것입니다뒤에라즈베리 파이:
Router --- [eth0] RaspPi [eth1] --- Switch +--- Client1
+--- Client2
+--- Client3
기본적으로 RaspPi를 두 번째 라우터로 사용하고 싶습니다. 즉, 두 번째 LAN 인터페이스가 필요합니다. 라우터에 DHCP 서버를 설치하고 VPN의 RaspPi에서 NAT를 활성화하여 서브넷을 처리하면 모든 준비가 완료됩니다.
또 다른 방법은 VPN을 활성화하는 것입니다.존재하다라우터 자체(루트 액세스 권한을 얻거나 OpenWRT 등을 플래시할 수 있는 경우)
또 다른 옵션은 라우터에서 DHCP 서버를 비활성화하는 것입니다. 그러면 RaspPi와 라우터를 동일한 LAN 세그먼트에 연결할 수 있으며 RaspPi에는 하나의 LAN 인터페이스만 필요합니다.