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

Name of the tun interface when running openvpn?

· 52CE 我爱测

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…

问题原文

原帖链接 · 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-tun seems 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"

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

资料来源与适用范围

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

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

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