我遵循上面列出的 iptables 规则https://community.openvpn.net/openvpn/wiki/BridgingAndRouting
这是输出iptables -L -v
Chain INPUT (policy ACCEPT 1236 packets, 145K bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 407 packets, 25288 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT all -- any any anywhere anywhere ctstate RELATED,ESTABLISHED
0 0 ACCEPT all -- eth0 eth1 192.168.0.0/24 anywhere ctstate NEW
0 0 ACCEPT all -- tun0 eth1 10.8.0.0/24 anywhere ctstate NEW
0 0 ACCEPT all -- tun0 eth0 10.8.0.0/24 192.168.0.0/24 ctstate NEW
Chain OUTPUT (policy ACCEPT 1691 packets, 230K bytes)
pkts bytes target prot opt in out source destination
Chain LOGGING (0 references)
pkts bytes target prot opt in out source destination
这是的输出如果配置:
eth0 Link encap:Ethernet HWaddr 00:90:e8:45:96:79
inet addr:192.168.0.10 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::290:e8ff:fe45:9679/64 Scope:Link
UP BROADCAST RUNNING ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:47251 errors:0 dropped:341 overruns:0 frame:0
TX packets:35463 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:6700218 (6.3 MiB) TX bytes:6348389 (6.0 MiB)
eth1 Link encap:Ethernet HWaddr 00:90:e8:45:96:7a
inet addr:213.179.150.110 Bcast:213.179.150.111 Mask:255.255.255.248
inet6 addr: fe80::290:e8ff:fe45:967a/64 Scope:Link
UP BROADCAST RUNNING ALLMULTI MULTICAST MTU:1500 Metric:1
RX packets:431735 errors:0 dropped:1629 overruns:0 frame:0
TX packets:515499 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:55214512 (52.6 MiB) TX bytes:93401691 (89.0 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:124 errors:0 dropped:0 overruns:0 frame:0
TX packets:124 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:12872 (12.5 KiB) TX bytes:12872 (12.5 KiB)
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.8.0.1 P-t-P:10.8.0.1 Mask:255.255.255.0
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:105 errors:0 dropped:0 overruns:0 frame:0
TX packets:239 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:8100 (7.9 KiB) TX bytes:18522 (18.0 KiB)
路线-n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 213.179.150.105 0.0.0.0 UG 0 0 0 eth1
10.8.0.0 0.0.0.0 255.255.255.0 U 0 0 0 tun0
192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
213.179.150.104 0.0.0.0 255.255.255.248 U 0 0 0 eth1
我有一个正在运行的客户端,并且隧道似乎已建立,因为我可以 ping 客户端的 tun 接口:
PING 10.8.0.2 (10.8.0.2) 56(84) bytes of data.
64 bytes from 10.8.0.2: icmp_req=8 ttl=64 time=704 ms
64 bytes from 10.8.0.2: icmp_req=9 ttl=64 time=824 ms
64 bytes from 10.8.0.2: icmp_req=10 ttl=64 time=704 ms
64 bytes from 10.8.0.2: icmp_req=11 ttl=64 time=723 ms
64 bytes from 10.8.0.2: icmp_req=12 ttl=64 time=725 ms
64 bytes from 10.8.0.2: icmp_req=13 ttl=64 time=665 ms
但是我无法从 eth0 ping “10.8.0.2”,即 192.168.0.10:
PING 10.8.0.2 (10.8.0.2) from 192.168.0.10 eth0: 56(84) bytes of data.
From 192.168.0.10 icmp_seq=1 Destination Host Unreachable
From 192.168.0.10 icmp_seq=2 Destination Host Unreachable
From 192.168.0.10 icmp_seq=3 Destination Host Unreachable
我的猜测是,ping 失败是因为默认网关与 eth0 不在同一子网中。但是来自eth0的流量不应该转发到tun0吗?我在这里缺少什么?
我尝试添加从 eth0 到 tun0 的转发规则:Chain FORWARD (policy ACCEPT 0 packet, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 all -- eth0 tun0 anywhere anywhere
但无济于事!
我忘了提及:
sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
这是我的 NAT 表:
Chain PREROUTING (policy ACCEPT 1 packets, 28 bytes)
pkts bytes target prot opt in out source destination
Chain INPUT (policy ACCEPT 1 packets, 28 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 MASQUERADE all -- any tun0 anywhere 10.8.0.0/24
0 0 MASQUERADE all -- any eth1 10.8.0.0/24 anywhere
0 0 MASQUERADE all -- any tun0 192.168.0.0/24 anywhere