免除程序使用活动VPN连接

当我连接到VPN时,我的所有网络流量都会自动通过它进行路由。 有没有办法增加豁免? 我不知道添加exception是否与VPN协议有关,但我使用的VPN是OpenVPN协议。

说到OpenVPN,为什么不像PPTP那样默认安装Ubuntu安装?

我无法获得IRCHighWay的服务器列表,这是我在运行运行bash脚本时尝试连接XChat的结果:

* Looking up irc.irchighway.net * Connecting to irc.irchighway.net (65.23.153.98) port 6667... * Connected. Now logging in... * You have been K-Lined. * *** You are not welcome on this network. * *** K-Lined for Open proxies are not allowed. (2011/02/26 01.21) * *** Your IP is 173.0.14.9 * *** For assistance, please email banned@irchighway.net and include everything shown here. * Closing Link: 0.0.0.0 (Open proxies are not allowed. (2011/02/26 01.21)) * Disconnected (Remote host closed socket). 

IP 173.0.14.9是由于我的VPN。 在运行脚本之前我忘了检查ip route list ,这是运行它之后的那个:

 ~$ ip route list 99.192.193.241 dev ppp0 proto kernel scope link src 173.0.14.9 173.0.14.2 via 192.168.1.1 dev eth1 proto static 173.0.14.2 via 192.168.1.1 dev eth1 src 192.168.1.3 192.168.1.0/24 dev eth1 proto kernel scope link src 192.168.1.3 metric 2 169.254.0.0/16 dev eth1 scope link metric 1000 default dev ppp0 proto static 

哦,运行脚本返回此输出:

 ~$ sudo bash irc_route.sh Usage: inet_route [-vF] del {-host|-net} Target[/prefix] [gw Gw] [metric M] [[dev] If] inet_route [-vF] add {-host|-net} Target[/prefix] [gw Gw] [metric M] [netmask N] [mss Mss] [window W] [irtt I] [mod] [dyn] [reinstate] [[dev] If] inet_route [-vF] add {-host|-net} Target[/prefix] [metric M] reject inet_route [-FC] flush NOT supported 

我连接到VPN后运行脚本。

创建一个包含以下内容的文件irc_route.sh:

 #!/bin/bash # script to make connections to irc.irchighway.net go via DEV. DEV=eth0 GW=$(ip route list | sed "s/.* via \([0-9.]*\) dev $DEV.*/\1/;t;d"|head -1) route add -host irc.irchighway.net gw $GW $DEV 

将DEV更改为您从中获取Internet连接的接口(可能是wlan0,eth1,eth0,ppp0中的任何一个)。 然后使用sudo bash irc_route.sh运行脚本,可以通过运行ip route list之前和之后检查结果。

DEV设备上用于互联网流量的默认网关的IP存储在变量GW中,然后用于通过默认GW而不是您拥有的OpenVPN连接路由到irc.irchighway.net服务器的所有流量。

要使其适用于所有IRCHighWay服务器,您必须获得所有服务器的列表。

server_list.txt:

  irc.irchighway.net caliburn.pa.us.irchighway.net 

脚本:

 #!/bin/bash # script to make connections to irchighway go via DEV. DEV=eth0 GW=$(ip route list | sed "s/.* via \([0-9.]*\) dev $DEV.*/\1/;t;d"|head -1) cat server_list.txt| xargs -iSERVER route add -host SERVER gw $GW $DEV 

有一个“更简单”的解决方案,你可以根据它来标记端口和路由,请参阅iproute2教程,但我没有使用它。 如果您不知道自己在做什么,那么这种路由存在一些问题。

您无法阻止特定程序通过VPN建立连接,但如果他们想要访问特定的主机或端口号,则可能。 我将假设最坏的情况,您希望某些应用程序绕过防火墙。

通过禁止来自一个程序的网络连接,使用SELinux可以做到这一点。 我不知道有什么好的工具可以进行这种配置,也不知道如何动态更改它。

我认为iptables中曾经有一个模块可以匹配发送程序,但我有一段时间没见过它。