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

openvpn: How to not use VPN for domains with multiple IP addresses

· 52CE 我爱测

I want to route around openvpn for a specific domain. I have tried: allow-pull-fqdn route specificdomain.com 255.255.255.255 net_gateway But this simply does a DNS lookup of the domain and adds whatever IP it gets to the routing …

问题原文

原帖链接 · David Ljung Madison Stellar · CC BY-SA 3.0

I want to route around openvpn for a specific domain. I have tried:

allow-pull-fqdn
route specificdomain.com 255.255.255.255 net_gateway

But this simply does a DNS lookup of the domain and adds whatever IP it gets to the routing table to use a default route.

The problem is, the specific domain has multiple IP addresses, and they don't seem to be on a simple network that I could just use a netmask for.

I've also tried to:

push "route specificdomain.com 255.255.255.255 net_gateway"

Though I confess from reading the docs I still haven't figured out what the difference is - though here it doesn't show up in my routing table and it doesn't work (even if I use a domain with a single IP address)

Is there a way to get openvpn to not route domains with multiple IP addresses like this, or is it too late in the routing for openvpn to know what the domain was that we were initially requesting and my best bet is to try to come up with a collection of IP addresses that currently match the domain?

社区高分解答

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

What you want is, sadly, impossible. Routing works based on IP addresses, and the domain name simply isn't present in the IP packets, so it cannot be used to make routing decisions.

When adding routes, you can add a route to a specific domain name, but that name gets DNS resolved into an IP address before it is added to the routing table. Also note that your routing table will not get updated if the IP address in the DNS entry changes.

Basically your options are:

1: at VPN startup, add a route to all the specific host names that you are going to access without VPN. The names will immediately get resolved, but that might not matter, unless the IP addresses change really quickly.

2: figure out all the netblocks that the target domain uses and setup routing without VPN for them. In some cases it is impossible to figure the netblocks out, though.

3: reverse your routing logic: drop the "route everything through vpn" rule, only route specific netblocks through vpn (you are more likely to know these than the netblocks of a specific domain you don't control), and let the default route take all non-vpn traffic to the internet without vpn.

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

资料来源与适用范围

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

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

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