Skip to content

Instantly share code, notes, and snippets.

@willwhui
Last active May 29, 2023 02:19
Show Gist options
  • Save willwhui/1febd37a3dd79a503cc8544c3bb18ece to your computer and use it in GitHub Desktop.
Save willwhui/1febd37a3dd79a503cc8544c3bb18ece to your computer and use it in GitHub Desktop.
在Openwrt中配置Openvpn客户端
@huozhong-in
Copy link

安装和配置文件

ssh [email protected] 到路由器,开始安装

# 更新源,如果被屏蔽了,更新不了,就要想办法在局域网里面搭建一个源
opkg update
# 安装以下2个包中的一个,装的上哪个装哪个
# opkg install openvpn-openssl
# opkg install openvpn-polarssl
# 我装了openvpn-polarssl
opkg install openvpn-polarssl

然后:

# 创建配置文件
vi /etc/openvpn/my-vpn.ovpn

并将以下内容贴入:

dev tun
proto udp
remote xxx.xxx.xxx.xxx yyyy  <---这里的xxx.xxx.xxx.xxx是open vpn服务器的域名或地址,yyyy是端口号
resolv-retry infinite
nobind
persist-key
persist-tun
ca /etc/openvpn/ca.crt
cert /etc/openvpn/client.crt
key /etc/openvpn/client.key
ns-cert-type server
comp-lzo
verb 3
sndbuf 0
rcvbuf 0
mute 20

然后从open vpn的服务器上获取ca.crt, client.crt, client.key,放入路由器的/etc/openvpn目录中
获取方式参考https://github.com/martincai/blogs/blob/master/openwrt%2Bopenvpn%2Bazure.md
最后,输入以下命令接入vpn

openvpn --cd /etc/openvpn --config /etc/openvpn/my-client.ovpn &

针对有用户名密码验证的openvpn server:
openvpn --cd /etc/openvpn --config /etc/openvpn/my-client.ovpn --auth-user-pass userpass.txt &
其中userpass.txt的内容为:

<username>
<password>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment