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