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

OpenVPN per user rules while not routing Internet traffic

· 52CE 我爱测

EDIT : I know that learn-address is what I would need to use to call a script (as specified in the openvpn-netfilter project) to set the firewall rules. I guess my question is more related to the config.ovpn script. How do you co…

问题原文

原帖链接 · Scott Crooks · CC BY-SA 3.0

EDIT: I know that learn-address is what I would need to use to call a script (as specified in the openvpn-netfilter project) to set the firewall rules. I guess my question is more related to the config.ovpn script. How do you configure the client.ovpn files to simultaneously learn which routes to the user needs, while also keeping Internet traffic to the user's ISP?

I have a question about how to do per user firewall rules, while also not routing Internet traffic through an OpenVPN server. I'm trying to setup a VPN server for a group of friends and I as we work on a project. I will implement something like this Github project: https://github.com/gdestuynder/openvpn-netfilter. This will enable the VPN server to lookup ACLs for a user, and implement them using iptables on the server side. All other traffic would be dropped.

For my own personal home VPN, I know I can use the following in my client.ovpn config to not route Internet traffic through the VPN:

route-nopull
route 192.168.1.0 255.255.255.0

Where 192.168.1.0/24 is my home subnet, and 10.8.0.0/24 (not shown) is the DHCP IP range of the tun adapter. I know placing that in the client's configuration overrides the server setting push "redirect-gateway def1 bypass-dhcp".

This is where I get confused: I already know my home subnet is 192.168.1.0/24, so I can easily place that in the client.ovpn file. But if I have no knowledge of the subnets/IPs I have access to (as most users don't), how does OpenVPN dynamically push per user VPN rules to the client?

In other words, if user1 has acess to 10.0.0.2 and 10.0.2.10 and user2 has access to 10.0.2.10 and 10.0.3.4, how does OpenVPN know to push the right routes to each user, while using the same generic client.ovpn configuration?

已采纳解答

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

You can push individual openvpn directives to your clients using client specific configuration files in the client-config-dir.

In the server config file include the directive:

client-config-dir ccd

and create this directory in case it does not already exist in your openvpn path, for example:

/etc/openvpn/ccd

Now create a config file per client in the ccd directory having the same name as the client's X509 common name. The following options are legal in a client-specific context: push, push-reset, iroute, ifconfig-push, and config.

For example to push routes to a client with CN user1 in his certificate:

echo 'push "route 10.0.0.2 255.255.255.255 10.8.0.1"' >> /etc/openvpn/ccd/user1
echo 'push "route 10.0.2.10 255.255.255.255 10.8.0.1"' >> /etc/openvpn/ccd/user1

For this to work you need to pull configuration directives on your clients from the server using the pull directive.

You may have the directive client in your client-config, which is a helper directive and expands as follows:

pull
tls-client

Do not use route-nopull in combination as it would stop the client pulling routes. If you need redirect-gateway on certain clients to route all traffic through the VPN subnet, you can place this directive just in those client configuration files and not in your server config file for all clients. The redirect-gateway directive automatically executes routing commands to cause all outgoing IP traffic to be redirected over the VPN. See man page.

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

资料来源与适用范围

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

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

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