OpenVPN路由設定
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
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,後面要用到
(2)、修改伺服器的配置檔案 在 C:/Program Files (x86)/OpenVPN/config/ server.conf中增加如下
client-config-dir C:/OpenVPN/client-ip-config/ccd然後在 C:/OpenVPN/client-ip-config/ccd 目錄中放針對每個客戶端的個性化配置檔案。
檔名就用客戶端名 生成key的時候輸入的 "Common Name" 名字
要設定客戶端 testClient為 10.8.10.254
只要在 C:/OpenVPN/client-ip-config/ccd/testClient 檔案中包含一行:
ifconfig-push 192.168.2.24 192.168.2.25[ ] [ 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 ]
參考-非常詳細介紹:https://my.oschina.net/stache/blog/1512610