Centos 7 安装 Wireguard
生活随笔
收集整理的這篇文章主要介紹了
Centos 7 安装 Wireguard
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
經(jīng)網(wǎng)友需求
官方安裝文檔:
https://www.wireguard.com/install/ 系 統(tǒng): centos 7.x 內(nèi)核要求: > 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) 創(chuàng)建目錄: mkdir -p /etc/wireguard# 3.2) 創(chuàng)建server端的公私鑰: wg genkey | tee privatekey-server | wg pubkey > publickey-server # 3.3) 創(chuàng)建client端的公私鑰: wg genkey | tee privatekey-client | wg pubkey > publickey-client# 3.4) 創(chuàng)建配置文件:[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=# 添加新用戶,就新生成一組秘鑰對(duì),此處加入peer,后面可以有很多. # office [Peer] PublicKey = zy3IkHgq6SdM AllowedIPs = 10.10.0.2 # home [Peer] PublicKey = t6ab6f6j2 AllowedIPs = 10.10.0.3################################################################################################ Interface: 服務(wù)端的配置端口 DNS IP 規(guī)則, 私鑰都在這個(gè)欄目下配置 Address : 服務(wù)端IP地址, 主要要加上 子網(wǎng)掩碼,內(nèi)網(wǎng)服務(wù)可以寫內(nèi)網(wǎng)地址,在路由器上做好端口映射即可. SaveConfig: DNS : 取得的DNS地址 8.8.8.8 PostUp : 服務(wù)端啟動(dòng)后,添加這個(gè)規(guī)則,用于偽裝和轉(zhuǎn)發(fā)各種流量. PostDown : 服務(wù)端關(guān)閉后,執(zhí)行這個(gè)命令規(guī)則,清理啟動(dòng)時(shí)添加的規(guī)則. ListenPort: wireguard 默認(rèn)端口51820. PrivateKey: 注意此處填寫的是服務(wù)端的私鑰.[Peer] : 聲明一個(gè)節(jié)點(diǎn) PublicKey: 該節(jié)點(diǎn)的公鑰 ALLowedIPs: 連接后獲取的地址. 注意此處只需要分配一個(gè)固定的IP地址即可.# 3.5) 開啟內(nèi)核轉(zhuǎn)發(fā)功能,系統(tǒng)其它設(shè)置打開轉(zhuǎn)發(fā):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啟動(dòng),停止,查看狀態(tài):
# 4.0 )不中斷活躍連接的情況下重新加載配置文件: wg syncconf wg0 <(wg-quick strip wg0)# 4.1 ) 啟動(dòng) 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 客戶端狀態(tài): 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打開軟件 - 左下角 新建空隧道 - (填寫內(nèi)容) - 起個(gè)名字 [Interface] PrivateKey = < 這里填寫 Client 上 privatekey 的內(nèi)容 > ListenPort = 51820 Address = 10.10.0.2/24 DNS = 8.8.8.8 # 連接后使用的 DNS, 如果要防止 DNS 泄露,建議使用內(nèi)網(wǎng)的 DNS 服務(wù)器[Peer] PublicKey = < 這里填寫 Server 上 publickey 的內(nèi)容 > AllowedIPs = 10.10.0.0/16, 192.168.10.0/24, 192.168.2.0/23 # 指定要訪問的服務(wù)端網(wǎng)段,或者設(shè)置0.0.0.0/0來進(jìn)行全局代理. Endpoint = 公網(wǎng)IP:51820 # 服務(wù)端公網(wǎng)暴露地址,51280 指定的端口,可以更改. PersistentKeepalive = 25*** 如果有其他的就按照上面的[Peer]繼續(xù)添加即可.保存后直接點(diǎn)-連接-就能看到是否連接上,日志項(xiàng)也能查看過程.**** 重要提示 ****:server 端[Peer]下的AllowedIPs 是寫鏈接過來后獲取的IP地址. 類似分配一個(gè)固定的IP地址client 端[Peer]下的AllowedIPs 是寫的那些網(wǎng)段的路由可以通過WG0轉(zhuǎn)發(fā),如果全局都要走wireguard就設(shè)置成0.0.0.0/0 。總結(jié)
以上是生活随笔為你收集整理的Centos 7 安装 Wireguard的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 哪些职业适合转行产品经理?
- 下一篇: dvajs的mock数据使用