OpenVPN采用默认设置连接时所有的数据都从vpn通道走,造成所有访问都非常慢,但是openvpn支持路由设置。
主要由以下三个参数决定
1. route-nopull
当客户端加入这个参数后,openvpn 连接后不会添加路由,也就是不会有任何网络请求走openvpn.
2.vpn_gateway
当客户端加入 route-nopull 后,所有出去的访问都不从 Openvpn 出去,但可通过添加 vpn_gateway参数使部分IP访问走 Openvpn 出去
route 192.168.1.0 255.255.0.0 vpn_gateway route 172.121.0.0 255.255.0.0 vpn_gateway3.net_gateway
这个参数和 vpn_gateway 相反,表示在默认出去的访问全部走 Openvpn 时,强行指定部分IP访问不通过 Openvpn 出去.
max-routes 参数表示可以添加路由的条数,默认只允许添加100条路由,如果少于100条路由可不加这个参数.
max-routes 1000 route 172.121.0.0 255.255.0.0 net_gateway
比较常用做法是在客户端配置文件中加上 route-nopull 再使用 vpn-gateway 逐条添加需要走Openvpn的ip。
注:若配置中有redirect-gateway deg1则需要先删除
OpenVPN docker地址:https://hub.docker.com/r/kylemanna/openvpn/
github地址为:https://github.com/kylemanna/docker-openvpn/issues/341
使用步骤
Pick a name for the
$OVPN_DATA
data volume container. It's recommended to
use theovpn-data-
prefix to operate seamlessly with the reference systemd
service. Users are encourage to replaceexample
with a descriptive name of
their choosing.OVPN_DATA="ovpn-data-example"
Initialize the
$OVPN_DATA
container that will hold the configuration files
and certificates. The container will prompt for a passphrase to protect the
private key used by the newly generated certificate authority.docker volume create --name $OVPN_DATA docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://VPN.SERVERNAME.COM docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn ovpn_initpki
Start OpenVPN server process
docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
Generate a client certificate without a passphrase
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full CLIENTNAME nopass
Retrieve the client configuration with embedded certificates
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_getclient CLIE
3、通过默认配置获取的IP是动态的,下面介绍如何配置静态ip
(1)、生成一个新的客户端证书,Common Name 要求不一样,并且记住这个Common Name,后面要用到
client-config-dir C:/OpenVPN/client-ip-config/ccd
文件名就用客户端名 生成key的时候输入的 "Common Name" 名字
要设置客户端 testClient为 10.8.10.254
只要在 C:/OpenVPN/client-ip-config/ccd/testClient 文件中包含一行:
[ ] [ 5 , 6 ] [ 9 , 10 ] [ 13 , 14 ] [ 17 , 18 ][ ] [ 25 , 26 ] [ 29 , 30 ] [ 33 , 34 ] [ 37 , 38 ][ ] [ 45 , 46 ] [ 49 , 50 ] [ 53 , 54 ] [ 57 , 58 ][ ] [ 65 , 66 ] [ 69 , 70 ] [ 73 , 74 ] [ 77 , 78 ][ ] [ 85 , 86 ] [ 89 , 90 ] [ 93 , 94 ] [ 97 , 98 ][ ] [ 105 , 106 ] [ 109 , 110 ] [ 113 , 114 ] [ 117 , 118 ][ ] [ 125 , 126 ] [ 129 , 130 ] [ 133 , 134 ] [ 137 , 138 ][ ] [ 145 , 146 ] [ 149 , 150 ] [ 153 , 154 ] [ 157 , 158 ][ ] [ 165 , 166 ] [ 169 , 170 ] [ 173 , 174 ] [ 177 , 178 ][ ] [ 185 , 186 ] [ 189 , 190 ] [ 193 , 194 ] [ 197 , 198 ][ ] [ 205 , 206 ] [ 209 , 210 ] [ 213 , 214 ] [ 217 , 218 ][ ] [ 225 , 226 ] [ 229 , 230 ] [ 233 , 234 ] [ 237 , 238 ][ ] [ 245 , 246 ] [ 249 , 250 ] [ 253 , 254 ]ifconfig-push 192.168.2.24 192.168.2.25
参考-非常详细介绍:https://my.oschina.net/stache/blog/1512610