大漠知秋的加油站

  • 首页
大漠知秋的加油站
你就当我的烂笔头吧
  1. 首页
  2. Linux
  3. 正文

配置 OpenVPN Client

2020年1月2日 616点热度 0人点赞 0条评论

  获取到客户端的证书及登录信息

$ tree /etc/openvpn/client/
/etc/openvpn/client/
├── ca.crt                  # 服务端提供的 ca 证书
├── client1.crt             # 服务端提供的客户端的证书
├── client1.key             # 服务端提供的客户端的证书密钥
├── passwd                  # 客户端的登录用户名和密码,用户名和密码各一行
└── ta.key                  # 服务端提供(防DDos攻击、UDP淹没等恶意攻击)

0 directories, 5 files

配置

$ cat /etc/openvpn/client/client1.ovpn
client
proto tcp-client
dev tun
auth-user-pass
remote 你的OpenVPN服务端IP 你的OpenVPN服务端端口
ca ca.crt
cert client1.crt
key client1.key
tls-auth ta.key 1
remote-cert-tls server
auth-nocache
persist-tun
persist-key
compress lzo
verb 4
mute 10

### 只需要某些 IP 走 OpenVPN 的线路,这就需要自定义路由了。
## 当客户端加入这个参数后,OpenVPN 连接后不会添加路由
# 也就是不会有任何网络请求走OpenVPN.
route-nopull
## 当客户端加入 route-nopull 后,所有出去的访问都不从 OpenVPN 出去
# 但可通过添加 vpn_gateway参数使部分IP访问走 OpenVPN 出去
route 10.8.0.0 255.255.0.0 vpn_gateway
## 这个参数和 vpn_gateway 相反,表示在默认出去的访问全部走 OpenVPN 时
# 强行指定部分IP访问不通过 OpenVPN 出去.max-routes 参数表示可以添加路由的条数
# 默认只允许添加100条路由,如果少于100条路由可不加这个参数.
#max-routes 1000
#route 10.8.0.0 255.255.0.0 net_gateway

  创建 OpenVPN 客户端 systemctl 服务

$ /usr/lib/systemd/system/openvpn-client.service
[Unit]
Description=OpenVPN Client
Documentation=https://github.com/OpenVPN/openvpn,放入目录:/usr/lib/systemd/system,并执行:systemctl enable openvpn-client.service && systemctl start openvpn-client.service
After=network.target

[Service]
ExecStart=/usr/sbin/openvpn --daemon --cd /etc/openvpn/client --config client1.ovpn --auth-user-pass /etc/openvpn/client/passwd --log /var/log/openvpn.log --log-append /var/log/openvpn.log
Restart=on-failure
RestartSec=5
Type=notify
LimitNOFILE=65536

[Install]
WantedBy=multi-user.target

$ systemctl enable openvpn-client.service && systemctl start openvpn-client.service

  启动之后观察日志和 IP 变化即可。

标签: Client Linux OpenVPN
最后更新:2020年1月2日

大漠知秋

唯黄昏而思烛明,唯覆雪始念日暖,唯放手方知情真,今困苦而怀峥嵘,今飘零而涌乡愁,今孑然而徒唏嘘,唏嘘成愁。

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

文章目录
  • 配置

COPYRIGHT © 2023 大漠知秋的加油站. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

豫ICP备16029200号-2