WireGuard 端到端平等的網絡隧道,測試地址 ca.6tu.meandroid
---------------------------------------------
服務器:遠程 Ubuntu18 , 要求 Linux Kernel ≥3.10,vim
# 安裝 wireguard服務器
add-apt-repository ppa:wireguard/wireguard apt-get update apt-get install wireguard
# 生產私鑰網絡
wg genkey
# 配置文件
vim /etc/wireguard/wg0.confapp
[Interface] PrivateKey = <Private Key> Address = 10.0.0.1/24 ListenPort = 56660 PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; ip6tables -A FORWARD -i wg0 -j ACCEPT; ip6tables -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; ip6tables -D FORWARD -i wg0 -j ACCEPT; ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE SaveConfig = true
啓動服務端 WireGuard測試
wg-quick up wg0
# 檢查啓動參數ui
wg
# 返回以下google
private key: (hidden) public key: nizEyMf6rv2xyCgdVxfG6sKEMVTUdTe+jVmXYcSkEyw= listening port: 56660
---------------------------------------------
客戶端: 安卓手機code
# 安裝
https://play.google.com/store/apps/details?id=com.wireguard.android
https://f-droid.org/en/packages/com.wireguard.android/server
# 配置,是兩個部分,創建自身的虛擬網卡和添加遠端節點的參數
點擊 "+" --> "Create from scratch"(鉛筆圖形)
"Name" --> android
點擊 "GENERATE" 生產 --> Private key:
Public key:
"Addresses" --> 10.0.0.3/24
"DNS servers" --> 8.8.8.8
點擊 "ADD PEER",填寫在服務器(遠程 Ubuntu18)上執行 wg 後的返回信息
"Public key" --> nizEyMf6rv2xyCgdVxfG6sKEMVTUdTe+jVmXYcSkEyw=
"Allowed IPs" --> 0.0.0.0/0
"Endpoint" --> <Server Public IP>:56660
點擊右上角保存配置,並啓動運行。安卓手機配置完畢
---------------------------------------------
接下來在服務端(遠程 Ubuntu18)上添加客戶端信息,執行以下命令
wg set wg0 peer 安卓自身的"Public key" allowed-ips 10.0.0.3/24
# 可能須要打開轉發
vim /etc/sysctl.conf
net.ipv4.ip_forward=1 net.ipv6.conf.all.forwarding=1
sysctl -p
以後在安卓手機上打開谷歌試試看