路由
route
或route PRINT
Destination(ip/网段) |
Gateway(网关) |
Genmask(子网掩码) |
Iface(网卡) |
192.168.123.110 |
10.8.0.2 |
255.255.255.255(ip) |
tun0 |
192.168.123.0 |
10.8.0.1 |
255.255.255.0(网段) |
tun0 |
解释
第一条:访问192.168.123.110将从tun0网卡的10.8.0.2的网关转发出去
第二条:访问192.168.(1~255)内所有的ip将从网卡tun0网卡的10.8.0.1的网关转发出去
服务配置
1 2 3 4 5 6
| push "route 192.168.123.110 255.255.255.255"
push "route 192.168.123.0 255.255.255.0"
route 192.110.10.1 255.255.255.255 10.8.0.1
|
####客户端配置
服务端需要添加配置client-config-dir ccd
指定客户端配置目录为ccd
配置文件名为直接客户端的名字没有.conf和任何后缀
1 2 3 4 5
| ifconfig-push 10.8.0.7 255.255.255.0
iroute 192.168.123.0 255.255.255.0 route 192.168.123.0 255.255.255.0
|
我的设置如下
10.8.0.1 服务器
10.8.0.8 家
10.8.0.5 工作
server.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| port 1194 proto tcp dev tun sndbuf 0 rcvbuf 0 ca ca.crt cert server.crt key server.key dh dh.pem auth SHA512 tls-auth ta.key 0 topology subnet server 10.8.0.0 255.255.255.0
push "route 10.8.0.0 255.255.255.0" push "route 192.168.123.0 255.255.255.0" route 192.168.123.0 255.255.255.0 10.8.0.8 client-config-dir ccd client-to-client keepalive 10 120 cipher AES-256-CBC comp-lzo user nobody group nobody persist-key persist-tun status openvpn-status.log verb 3 crl-verify crl.pem
|
client
1 2 3
| ifconfig-push 10.8.0.8 255.255.255.0 iroute 192.168.123.0 255.255.255.0 route 192.168.123.0 255.255.255.0
|