目标是让主服务器客户端可以访问主OpenVPN服务器和多个OpenVPN子网。 所有子网的服务器也是主服务器的客户端。
这里是configuration:
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
iptables -t nat -A POSTROUTING -s 10.0.0.0/16 -o eth0 -j MASQUERADE
我想,iptables中缺less一些东西,我没有足够的经验来解决这个问题。 最简单的事情应该是在主服务器configuration中使用push "dhcp-option DNS 10.1.0.1"选项。 有没有办法通过OpenVPN服务器设置DNS服务器? 还是以其他方式来处理这个?
更新(2.03.2016)
这是我设法达到的: networking图
主要服务器路由:
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
有了这个,我可以ssh到超级用户使用tun0和tun1ip(这使我很困惑)的子服务器。 之后,我可以连接到客户端,但现在有直接的连接。 我相信我已经错过了最后一步,但无法弄清楚。
iptables -A FORWARD -s 10.0.0.0/16 -d 10.1.0.0/16 -j ACCEPT subserver1上的iptables -A FORWARD -s 10.0.0.0/16 -d 10.1.0.0/16 -j ACCEPT没有任何改变。
更新(3.03.2016)
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的规则。