Centos 7 安装 Wireguard
生活随笔
收集整理的這篇文章主要介紹了
Centos 7 安装 Wireguard
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
經網友需求
官方安裝文檔:
https://www.wireguard.com/install/ 系 統: centos 7.x 內核要求: > 3.10 (uname -r)### Method 1: a signed module is available as built-in to CentOS's kernel-plus: $ sudo yum install yum-utils epel-release $ sudo yum-config-manager --setopt=centosplus.includepkgs=kernel-plus --enablerepo=centosplus --save $ sudo sed -e 's/^DEFAULTKERNEL=kernel$/DEFAULTKERNEL=kernel-plus/' -i /etc/sysconfig/kernel $ sudo yum install kernel-plus wireguard-tools $ sudo reboot### Method 2: users wishing to stick with the standard kernel may use ELRepo's pre-built module: $ sudo yum install epel-release elrepo-release $ sudo yum install yum-plugin-elrepo $ sudo yum install kmod-wireguard wireguard-tools### Method 3: users running non-standard kernels may wish to use the DKMS package instead: $ sudo yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm $ sudo curl -o /etc/yum.repos.d/jdoss-wireguard-epel-7.repo https://copr.fedorainfracloud.org/coprs/jdoss/wireguard/repo/epel-7/jdoss-wireguard-epel-7.repo $ sudo yum install wireguard-dkms wireguard-toolswireguard 配置:
# 3.1) 創建目錄: mkdir -p /etc/wireguard# 3.2) 創建server端的公私鑰: wg genkey | tee privatekey-server | wg pubkey > publickey-server # 3.3) 創建client端的公私鑰: wg genkey | tee privatekey-client | wg pubkey > publickey-client# 3.4) 創建配置文件:[root@bj-vnp wireguard]# cat wg0.conf [Interface] Address = 10.10.0.1/24 SaveConfig = false DNS = 8.8.8.8 PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE ListenPort = 51820 PrivateKey = UG0DrMJ1jQmaExSy6LOOwanDFyplfSgBtzCUKmL772k=# 添加新用戶,就新生成一組秘鑰對,此處加入peer,后面可以有很多. # office [Peer] PublicKey = zy3IkHgq6SdM AllowedIPs = 10.10.0.2 # home [Peer] PublicKey = t6ab6f6j2 AllowedIPs = 10.10.0.3################################################################################################ Interface: 服務端的配置端口 DNS IP 規則, 私鑰都在這個欄目下配置 Address : 服務端IP地址, 主要要加上 子網掩碼,內網服務可以寫內網地址,在路由器上做好端口映射即可. SaveConfig: DNS : 取得的DNS地址 8.8.8.8 PostUp : 服務端啟動后,添加這個規則,用于偽裝和轉發各種流量. PostDown : 服務端關閉后,執行這個命令規則,清理啟動時添加的規則. ListenPort: wireguard 默認端口51820. PrivateKey: 注意此處填寫的是服務端的私鑰.[Peer] : 聲明一個節點 PublicKey: 該節點的公鑰 ALLowedIPs: 連接后獲取的地址. 注意此處只需要分配一個固定的IP地址即可.# 3.5) 開啟內核轉發功能,系統其它設置打開轉發:echo 1 > /proc/sys/net/ipv4/ip_forward echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf echo "net.ipv4.conf.all.proxy_arp = 1" >> /etc/sysctl.conf sysctl -p啟動,停止,查看狀態:
# 4.0 )不中斷活躍連接的情況下重新加載配置文件: wg syncconf wg0 <(wg-quick strip wg0)# 4.1 ) 啟動 wireguard: wg-quick down wg0 && wg-quick up wg0wg-quick up wg0[root@bj-vpn wireguard]# wg-quick up wg0 [#] ip link add wg0 type wireguard [#] wg setconf wg0 /dev/fd/63 [#] ip -4 address add 10.10.0.1/24 dev wg0 [#] ip link set mtu 1420 up dev wg0 [#] mount `8.8.8.8' /etc/resolv.conf [#] iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE# 4.2 ) 停止 wireguard: wg-quick down wg0[root@bj-vpn wireguard]# wg-quick down wg0 [#] ip link delete dev wg0 [#] umount /etc/resolv.conf [#] iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE# 4.3 ) 查看wireguard 客戶端狀態: wg[root@bj-vpn wireguard]# wg interface: wg0public key: sIPp+stGXBzprivate key: (hidden)listening port: 51820peer: zy3IkHgq6Sdallowed ips: 10.10.0.2/32peer: t6ab6f6j2Rwallowed ips: 10.10.0.3/32客戶端的下載安裝配置
# windows: https://download.wireguard.com/windows-client/wireguard-installer.exe打開軟件 - 左下角 新建空隧道 - (填寫內容) - 起個名字 [Interface] PrivateKey = < 這里填寫 Client 上 privatekey 的內容 > ListenPort = 51820 Address = 10.10.0.2/24 DNS = 8.8.8.8 # 連接后使用的 DNS, 如果要防止 DNS 泄露,建議使用內網的 DNS 服務器[Peer] PublicKey = < 這里填寫 Server 上 publickey 的內容 > AllowedIPs = 10.10.0.0/16, 192.168.10.0/24, 192.168.2.0/23 # 指定要訪問的服務端網段,或者設置0.0.0.0/0來進行全局代理. Endpoint = 公網IP:51820 # 服務端公網暴露地址,51280 指定的端口,可以更改. PersistentKeepalive = 25*** 如果有其他的就按照上面的[Peer]繼續添加即可.保存后直接點-連接-就能看到是否連接上,日志項也能查看過程.**** 重要提示 ****:server 端[Peer]下的AllowedIPs 是寫鏈接過來后獲取的IP地址. 類似分配一個固定的IP地址client 端[Peer]下的AllowedIPs 是寫的那些網段的路由可以通過WG0轉發,如果全局都要走wireguard就設置成0.0.0.0/0 。總結
以上是生活随笔為你收集整理的Centos 7 安装 Wireguard的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 哪些职业适合转行产品经理?
- 下一篇: Centos(6、7) —— yum源的