OpenVPN 网络之间的路由流量

OpenVPN 网络之间的路由流量

目标是拥有主 OpenVPN 服务器和多个主服务器客户端可访问的 OpenVPN 子网。所有子网的服务器也是主服务器的客户端。

以下是配置:

  • 主服务器配置

port 1194 proto udp dev tun ca ca.crt cert server.crt key server.key dh dh2048.pem server 10.0.0.0 255.255.0.0 push "route 10.0.0.0 255.255.0.0" push "route 10.1.0.0 255.255.0.0" client-config-dir ccd client-to-client keepalive 10 120 tls-server tls-auth ta.key 0 comp-lzo

  • ccd/subserver1

ifconfig-push 10.0.0.6 10.0.0.5 iroute 10.1.0.0 255.255.0.0

  • 子服务器配置(作为主服务器客户端)

client dev tun proto udp remote <ip> 1194 remote-random resolv-retry infinite nobind persist-key persist-tun ca ca.crt cert subserver1.crt key subserver1.key tls-client tls-auth ta.key 1 cipher BF-CBC comp-lzo verb 3 pull

  • 子服务器配置(作为子网服务器)

port 1195 proto udp dev tun ca ca.crt cert server.crt key server.key dh dh2048.pem server 10.1.0.0 255.255.0.0 push "route 10.0.0.0 255.255.0.0" push "route 10.1.0.0 255.255.0.0" client-to-client keepalive 10 120 tls-server tls-auth ta.key 0 comp-lzo persist-key persist-tun

  • 主服务器上的 IP 表规则

iptables -t nat -A POSTROUTING -s 10.0.0.0/16 -o eth0 -j MASQUERADE

我想,iptables 中缺少了一些东西,我没有足够的经验来解决这个问题。最简单的方法应该是使用push "dhcp-option DNS 10.1.0.1"主服务器配置中的选项。有没有办法通过 OpenVPN 服务器设置 DNS 服务器?或者还有其他方法可以解决这个问题?

更新(2016.03.2)

以下是我所取得的成就: 网络图

主要服务器路线:

0.0.0.0 <external ip> 0.0.0.0 UG 0 0 0 eth0 10.0.0.0 10.0.0.2 255.255.0.0 UG 0 0 0 tun0 10.0.0.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 10.1.0.0 10.0.0.2 255.255.0.0 UG 0 0 0 tun0 10.2.0.0 10.0.0.2 255.255.0.0 UG 0 0 0 tun0

Subserver1 路线:

0.0.0.0 <external ip> 0.0.0.0 UG 0 0 0 eth0 10.0.0.0 10.0.0.5 255.255.0.0 UG 0 0 0 tun1 10.0.0.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun1 10.1.0.0 10.1.0.2 255.255.0.0 UG 0 0 0 tun0 10.1.0.2 0.0.0.0 255.255.255.255 UH 0 0 0 tun0 10.2.0.0 10.0.0.5 255.255.0.0 UG 0 0 0 tun1

Client1 路线:

0.0.0.0 <external ip> 0.0.0.0 UG 0 0 0 eth0 10.1.0.0 10.1.0.5 255.255.0.0 UG 0 0 0 tun0 10.1.0.5 0.0.0.0 255.255.255.255 UH 0 0 0 tun0

这样,我就可以使用 tun0 和 tun1 ips 从超级用户 ssh 到子服务器(这让我很困惑)。之后我可以连接到客户端,但现在是直接连接。我肯定我错过了最后一步,但想不通。

iptables -A FORWARD -s 10.0.0.0/16 -d 10.1.0.0/16 -j ACCEPT在 subserver1 上没有任何改变。

更新(2016 年 3 月 3 日)

  • 主服务器:

root@stage:~# iptables -L -nv Chain INPUT (policy ACCEPT 212K packets, 40M bytes) pkts bytes target prot opt in out source destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination 74 5416 ACCEPT all -- tun0 eth0 10.0.0.0/16 10.1.0.0/16 ctstate NEW

Chain OUTPUT (policy ACCEPT 223K packets, 34M bytes) pkts bytes target prot opt in out source destination root@stage:~# iptables -t nat -L -nv Chain PREROUTING (policy ACCEPT 9664 packets, 695K bytes) pkts bytes target prot opt in out source destination

Chain INPUT (policy ACCEPT 9641 packets, 694K bytes) pkts bytes target prot opt in out source destination

Chain OUTPUT (policy ACCEPT 29987 packets, 2269K bytes) pkts bytes target prot opt in out source destination

Chain POSTROUTING (policy ACCEPT 29828 packets, 2260K bytes) pkts bytes target prot opt in out source destination 179 11363 MASQUERADE all -- * * 10.0.0.0/16 10.1.0.0/16

所有其他机器都没有任何 iptables 规则。

相关内容