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

How to automatically add a local route after OpenVPN start?

· 52CE 我爱测

I have a container which routes all its traffic via OpenVPN. This is done by OpenVPN via a combo of 0.0.0.0/1 via 10.8.8.17 dev tun0 128.0.0.0/1 via 10.8.8.17 dev tun0 which masks the default route (which is still there when Open…

问题原文

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

I have a container which routes all its traffic via OpenVPN. This is done by OpenVPN via a combo of

0.0.0.0/1 via 10.8.8.17 dev tun0 
128.0.0.0/1 via 10.8.8.17 dev tun0 

which masks the default route (which is still there when OpenVPN shuts down)

I need to explicitly add a route for a local network which would direct packets via eth0 and not tun0.

This is manually done via

ip route add 10.10.10.0/24 via 10.10.11.254 dev eth0

after OpenVPN has started.

How can I do that automatically upon OpenVPN start?

I tried to add

route 10.10.10.0 255.255.255.0

to mu .ovpn config file, but this leads to a new route via tun0 (which is quite understandable as there was no specific information about the NIC to route through - but I did not see anything available in the doc either)

# ip route
(...)
10.10.10.0/24 via 10.8.8.17 dev tun0 

Is what I want to achieve doable though OpenVPN configuration or do I need to do it somehow outside the OpenVPN startup process?

已采纳解答

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

If it is a locally reachable network, then you can just have a persistent local route to it irrespective of openvpn and should work as expected. Depending on your system, you can configure the route so that it will be loaded when the relevant interface is up.

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

资料来源与适用范围

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

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

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