Skip to content

Instantly share code, notes, and snippets.

@wujcheng
Forked from cute/wireguard.md
Created September 24, 2018 12:18
Show Gist options
  • Save wujcheng/9cf197271f7fccf26d64ff2f4850f046 to your computer and use it in GitHub Desktop.
Save wujcheng/9cf197271f7fccf26d64ff2f4850f046 to your computer and use it in GitHub Desktop.

1:设置

sudo vi /etc/sysctl.conf
net.ipv4.ip_forward=1
sudo sysctl -p

2:安装

https://www.wireguard.com/install/

3:生成key

wg genkey | tee privatekey | wg pubkey > publickey

#查看私钥
cat privatekey 
#查看公钥
cat publickey

服务端

    私钥:+APhXtu7QecMjC9M7Nv1y3XpvuVIgOSo0SO0BOYZuUw=
    公钥:OAoGS1iYKde4Pp7achtGo/RaJBQMh3RjW3IKJKyB40I=

客户端
    私钥:8HSW0qtVL/hkj/oN8eSAmMiSggM6uGfCew1qamMQMXs=
    公钥:/n83sQyNxrj6wgkTR/XyAfUJSmmoMDkw/e8/gQjLfj8=

4:服务端配置文件

查看interface,替换配置文件里的eth0:

    ifconfig 

sudo vim /etc/wireguard/wg0.conf

内容:

    [Interface]
    Address = 192.168.2.1/24
    PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
    PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
    ListenPort = 51820
    PrivateKey = +APhXtu7QecMjC9M7Nv1y3XpvuVIgOSo0SO0BOYZuUw=

    [Peer]
    PublicKey = /n83sQyNxrj6wgkTR/XyAfUJSmmoMDkw/e8/gQjLfj8=
    AllowedIPs = 10.0.2.1/24


启动:

    sudo wg-quick up wg0

5: ShadowGuard

wg://ip:51820?dns=8.8.8.8&sk=8HSW0qtVL/hkj/oN8eSAmMiSggM6uGfCew1qamMQMXs=&pk=OAoGS1iYKde4Pp7achtGo/RaJBQMh3RjW3IKJKyB40I=&addr=10.0.2.1/24#demo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment