安装WireGuard
按照官方说明,可以使用下列命令装依赖,不够的自己看着装
1 |
apt-get install libmnl-dev linux-headers-$(uname -r) build-essential pkg-config |
直接从git里拉。
1 |
git clone https://git.zx2c4.com/WireGuard |
直接make就行
1 2 3 |
cd WireGuard/src make make install |
配置
参考前一篇文章“WireGuard wg-quick PostUp的高级玩法”,可以直接无视官方和其他各种第三方给的教程。
前文给了一个参考的配置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
[Interface] Address = 192.168.10.1/24 MTU = 1500 PrivateKey = xxx PostUp = echo -n "hello" > /dev/udp/192.168.1.1/80; echo -n "hello" > /dev/udp/192.168.2.1/80 [Peer] PublicKey = xxx AllowedIPs = 192.168.10.40/32, 192.168.1.0/24 Endpoint = 2.2.2.2:12345 [Peer] PublicKey = xxx AllowedIPs = 192.168.10.50/32, 192.168.2.0/24 Endpoint = 3.3.3.3:12345 |
按上述配置,假定的网络环境如下:
服务器:IP 1.1.1.1,WireGuard内网 IP 192.168.10.1,公网环境
节点1: IP 2.2.2.2,WireGuard内网 IP 192.168.10.40,LAN IP 192.168.1.0/24
节点2: IP 3.3.3.3,WireGuard内网 IP 192.168.10.50,LAN IP 192.168.2.0/24
此处,服务器、节点1、节点2均有公网IP。
如果节点IP不固定,或者是没有公网IP,那就改为如下配置
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[Interface] Address = 192.168.10.1/24 MTU = 1500 PrivateKey = xxx ListenPort = 54321 [Peer] PublicKey = xxx AllowedIPs = 192.168.10.40/32, 192.168.1.0/24 [Peer] PublicKey = xxx AllowedIPs = 192.168.10.50/32, 192.168.2.0/24 |
VPS上,将配置文件保存为 /etc/wireguard/wg0.conf,执行下列命令,启用Wireguard:
1 |
wg-quick up wg0 |
为了让网络正常工作,还需要在VPS的公网接口上启用NAT
1 2 3 4 |
iptables -F FORWARD iptables -A FORWARD -j ACCEPT iptables -A POSTROUTING -t nat -o eth0 -j MASQUERADE |
修改 /etc/sysctl.conf,启用 ‘net.ipv4.ip_forward=1‘,然后执行 ‘sysctl -p‘
接下来是大招
You are not authorised to read all content in this post.
Please login…
Ubuntu部署WireGuard by @sskaje: https://sskaje.me/2017/06/deploy-wireguard-on-ubuntu/
Incoming search terms:
Link to this post!