windows端、ubuntu,wireguard配置文件示例

默认分类 · 2024-11-08

1.UBUNTU使用wireguard

1.安装

apt install wireguard

会自动安装wireguard-tools

2.创建配置文件

touch /etc/wireguard/wg0.conf

3.生成私钥公钥

wg genkey | tee /etc/wireguard/private | wg pubkey > /etc/wireguard/public

4.将生成的私钥写入配置文件,公钥写入对端的PEER中

5.连接和断开

wg-quick up wg0 #连接wg
wg-quick down wg0 #断开WG

2.配置文件如下

服务器端

[Interface]
#本地私钥
PrivateKey = aMvQI2MC33Rz3VcG7I2Q/7dXyCgnWDhJ8PpQGTJugUQ=
#监听的端口,需要在防墙中放行。
ListenPort = 9999
#本机ip
Address = 192.168.99.1/24

[Peer]
#客户端公钥
PublicKey = Seqx0m/+yr9pes4ziJxSch5eP44UlM6vwOSKjxakmxI=
#要路由的ip,如果是单机的话,掩码必需是32位的,ipv6前缀必需是128
AllowedIPs = 192.168.99.2/32

客户端

[Interface]
#本机私钥
PrivateKey = SLJ4DZ0d9wUa6rY1JZV5ulfyWJyCJWbGXoAvQ35s6EM=
#本机ip
Address = 192.168.99.2/24

[Peer]
#对端公钥
PublicKey = BdoyQ6Fv9FlSxQm7WlVJ6GJ39u8jkWxSfFfOOcjP7CI=
#要路由的ip
AllowedIPs = 192.168.99.0/24
#服务器ip和端口,ipv6要用[]号括起来
Endpoint = [240e:335:24a:a690::7d3]:9999
#握手时间,如不加这个,过段时间,服务器会ping不通客户端
PersistentKeepalive = 25

windows下载对应的wireguard客户端,在配置中写入信息即可

Theme Jasmine by Kent Liao