Ubuntu和Debian8+ 上一鍵安裝并配置 WireGuard

WireGuard 內核模塊式的加載, 效率非常高.不過這東西是用UDP發送數據, 所以到了晚上就不會那么友好.作者親測Ubuntu 16.04 LTS Server – 64 Bit和Debian均能完美支持。安裝好后如不能上網,將客戶端的DNS更改成8.8.8.8。

本文測試機器為美國VPS Hostwinds

服務端和客戶端:

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

第三方支持:

https://tunsafe.com/download

部署:

wget --no-check-certificate -qO- 'https://moeclub.org/attachment/LinuxShell/wireguard.sh'| bash

說明:

      1. 使用的是官方默認端口,端口為:51820.
      2. WireGuard 需要 tun 設備才能正常工作.
      3. 配置文件在 /etc/wireguard .
      4. 配置文件 wg0.conf 為腳本自動生成的服務端配置文件.
      5. 服務端已配置自啟動, 啟動服務命令.
        #配置文件為 wg0.conf 則命令中使用 wg0 wg-quick down wg0; wg-quick up wg0
      6. 配置文件 wg0-client.conf 為腳本自動生成的客戶端配置文件.
        將其導入客戶端即可使用.
      7. 客戶端配置文件中Endpoint項可以用域名代替IP地址.
      8. 如果遇到錯誤請嘗試重啟,重新跑腳本.
      9. 如果以下錯誤請嘗試自行更換內核.
        
        RTNETLINK answers: Operation not supported
        Unable to access interface: Protocol not supported
        

        wireguard.sh

#!/bin/bash WG_PORT='51820' IPAddr=`wget --no-check-certificate -qO- http://moeclub.org/address` POOL='https://deb.debian.org/debian/pool/main/w/wireguard/' [ `dpkg -s libc6 |grep '^Version' |grep -o '[0-9\.]\{4\}' |head -n1 |cut -d'.' -f2` -ge "14" ] || exit 0 apt-get update apt-get install -y libmnl-dev libelf-dev linux-headers-$(uname -r) build-essential pkg-config dkms resolvconf dnsmasq qrencode arch=`dpkg --print-architecture` Version=`wget --no-check-certificate -qO- "${POOL}" |grep -o 'wireguard_[0-9\_\.\-]\{1,\}_' |head -n1 |cut -d'_' -f2` [ -n "$Version" ] || exit 1 wget --no-check-certificate -qO "/tmp/wireguard_${Version}_all.deb" "${POOL}wireguard_${Version}_all.deb" wget --no-check-certificate -qO "/tmp/wireguard-dkms_${Version}_all.deb" "${POOL}wireguard-dkms_${Version}_all.deb" wget --no-check-certificate -qO "/tmp/wireguard-tools_${Version}_${arch}.deb" "${POOL}wireguard-tools_${Version}_${arch}.deb" dpkg -i "/tmp/wireguard-tools_${Version}_${arch}.deb" dpkg -i "/tmp/wireguard-dkms_${Version}_all.deb" dpkg -i "/tmp/wireguard_${Version}_all.deb" [ -d /etc/wireguard ] && { command -v wg >/dev/null 2>&1 [ $? == 0 ] || exit 1 sed -i '/#\?net.ipv4.ip_forward/d' /etc/sysctl.conf sed -i '$a\net.ipv4.ip_forward=1' /etc/sysctl.conf sysctl -p cat >/etc/dnsmasq.conf< publickey wg genpsk > presharedkey wg genkey |tee privatekey.client |wg pubkey > publickey.client ServerKey=`cat privatekey` ServerPub=`cat publickey` ServerPsk=`cat presharedkey` ClientKey=`cat privatekey.client` ClientPub=`cat publickey.client` cat >simple.conf</dev/null; wg-quick up wg0\n\n" >>/etc/crontab # Try it! wg-quick down wg0 2>/dev/null; wg-quick up wg0 }
贊(0)
版權聲明:本文采用知識共享 署名4.0國際許可協議 [BY-NC-SA] 進行授權, 轉載請注明出處。
文章名稱:《Ubuntu和Debian8+ 上一鍵安裝并配置 WireGuard》
文章鏈接:http://www.lrracing.com/3141.html
【聲明】:國外主機測評僅分享信息,不參與任何交易,也非中介,所有內容僅代表個人觀點,均不作直接、間接、法定、約定的保證,讀者購買風險自擔。一旦您訪問國外主機測評,即表示您已經知曉并接受了此聲明通告。
【關于安全】:任何 IDC商家都有倒閉和跑路的可能,備份永遠是最佳選擇,服務器也是機器,不勤備份是對自己極不負責的表現,請保持良好的備份習慣。