大网数据广告活动
服务器运维问答

Any way to make separate OpenVPN connections use separate gateways?

· 52CE 我爱测

I have a bunch of private networks, all on the 172.XXX.XXX.XXX IP space. When I connect via OpenVPN sometimes the VPNs end up connecting through the same gateway which only allows traffic from the first VPN to work. Example: $ ne…

问题原文

原帖链接 · David Xu · CC BY-SA 3.0

I have a bunch of private networks, all on the 172.XXX.XXX.XXX IP space. When I connect via OpenVPN sometimes the VPNs end up connecting through the same gateway which only allows traffic from the first VPN to work.

Example:

$ netstat -nr
Routing tables

Internet:
Destination        Gateway            Flags        Refs      Use   Netif Expire
............
172.31             10.8.0.5           UGSc            1        0   utun3
172.32             10.8.0.5           UGSc            1        0   utun3

here 172.31.XXX.XXX and 172.32.XXX.XXX are using the same gateway/interface, which only allows traffic from the first connected VPN to transfer.

OpenVPN config for server #1:

push "route 172.32.0.0 255.255.0.0"

OpenVPN config for server #2:

push "route 172.31.0.0 255.255.0.0"

Is there any way to make the two use different tunnels/gateways? Sometimes when I disconnect and connect a bunch of times they will eventually use different tunnels, but it doesn't happen every time and it's also a pain to have to connect and disconnect until things work.

The VPN configs are just the Sample configs with the extra push directive.

已采纳解答

原帖链接 · Lacek · CC BY-SA 3.0

Since you mentioned that the config files are the default, except for the push lines, I'm thinking that both of them contains the default

server 10.8.0.0 255.255.255.0

line, which makes the two openvpn servers use the same pool. For this reason, when you connect to the servers, both of them will assign the first available address, which is 10.8.0.5, and instructs the client to route all connections through that. This would explain the random "now this works" moments, because if the server thinks that the address is used (e.g. you reconnect too fast), it will use the next available address in the pool, thus you get an other address assigned.

Simply change the server line to be different on the two servers, so the client will have IP address from different subnets.

This is slightly offtopic, but you may wonder why 10.8.0.5 is the first address. Openvpn assigns p2p addresses from a /30 subnet, so for every connection, a separate /30 subnet is used. The first is reserved for the server itself, so x.x.x.1 and x.x.x.2 will never gets assigned to a client. The next /30 subnet has two available address, x.x.x.5 and x.x.x.6, one of which will be assigned to the client, and the other is to the server peer address.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。