我运行一个服务器,通过 OpenVPN 连接着很多客户端,客户端数量慢慢增长,几天前达到 255 多个。最初设置 VPN 时,我考虑到了这一点,并将子网掩码设置为“255.255.0.0”;然而,有些不对劲,因为我可以连接到具有10.8.0.x
IP 地址的旧客户端,但无法连接到任何具有 IP 地址的新客户端10.8.1.x
。
我的配置中是否遗漏了什么?
/etc/openvpn/server.conf
:port 1194 proto udp dev tun ca ca.crt crl-verify crl.pem cert server.crt key server.key dh dh.pem auth SHA512 tls-auth ta.key 0 cipher AES-256-CBC topology subnet server 10.8.0.0 255.255.0.0 ifconfig-pool-persist ipp.txt push "bypass-dhcp" push "dhcp-option DNS 8.8.8.8" push "dhcp-option DNS 8.8.4.4" push "dhcp-option DNS 10.8.0.1" keepalive 10 120 sndbuf 0 rcvbuf 0 persist-key persist-tun verb 3 log /var/log/openvpn.log status openvpn-status.log # This automatically assigns domain names to clients, based on their names: # NOTE: You have to comment out user and grop lines above for this to even work #user nobody #group nogroup # default is 1 which doesn't allow user-defined scripts script-security 2 learn-address /home/dvida/openvpn_scripts/learn_address.sh
/etc/openvpn/client-common.txt
:client dev tun proto udp remote blah.blah.com 1194 sndbuf 0 rcvbuf 0 mssfix 1160 resolv-retry infinite persist-key persist-tun nobind remote-cert-tls server tls-version-min 1.0 key-direction 1 auth SHA512 cipher AES-256-CBC verb 3
ifconfig
报告此 VPN 接口没有与其他接口的 IP 冲突: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.0.0 UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1 RX packets:71105670 errors:0 dropped:0 overruns:0 frame:0 TX packets:70755978 errors:0 dropped:391 overruns:0 carrier:0 collisions:0 txqueuelen:100 RX bytes:42092973453 (39.2 GiB) TX bytes:42070922921 (39.1 GiB)
答案1
事实证明,这与 OpenVPN 无关,而是与以下 SNAT 规则有关:
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 ! -d 10.8.0.0/24 -j SNAT --to 129.100.40.167
- 我更新了实时
iptables
规则,并修复了其中的问题,/etc/rc.local
因此网络掩码/16
改为/24