问题原文
原帖链接 · Johannes Ernst · CC BY-SA 3.0
I have two OpenVPN client setups, controlled by systemd services openvpn.foo and openvpn.bar. They connect to different VPNs and may or may not be active at any point in time.
I'd like to set up different iptables firewall rules for them. The trouble is that the first OpenVPN process seems to grab the tun0 interface, regardless of whether that turns out to be configuration foo or bar. The problem is I can't attach iptables rules to the interface because I don't know whether it goes with VPN foo or bar at the moment.
Questions:
- is there a way to get OpenVPN to always issue the same interface names for a given configuration? I was looking for an option in the config file, but couldn't find one.
persist-tunseems insufficient as it does not seem to survive a reboot. - is there a way to determine which interface goes with which configuration after the fact?
- given that the IP addresses I'm obtaining aren't entirely predictable either, I can't attach the rules to those either. Can anybody think of a trick where to attach them instead?
Thanks!
已采纳解答
原帖链接 · Uwe Burger · CC BY-SA 3.0
You can give the tun device name in the .ovpn configuration file:
Edit the file /etc/openvpn/server-vpngw.conf and add such lines:
dev tun3
client-config-dir /etc/openvpn/ccd
Then create the following file /etc/openvpn/ccd/vpn-name and edit it like so:
ifconfig-push 10.8.2.202 10.8.2.201
push "route 172.16.12.0 255.255.255.0"
push "route 10.2.4.0 255.255.255.0"
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
