搬家后电信取消了我的ipv4的公网ip,搞得我所有依赖公网ip的服务全部失效了。 于是我在休息了一阵后开始捣鼓恢复的事情。
首先得需要的是一个有公网ip的服务器,我是在腾讯云上买的,轻量云服务器,2核1G 峰值带宽320mbps 每个月40左右,然后使用GIthub上开源的 WG 安装脚本: Github
bashcurl -O https://raw.githubusercontent.com/angristan/wireguard-install/master/wireguard-install.sh
chmod +x wireguard-install.sh
./wireguard-install.sh
按照脚本执行即可,贴一下我自己的配置:
config[Interface] Address = 10.66.66.1/24,fd42:42:42::1/64 ListenPort = 49198 PrivateKey = - PostUp = iptables -I INPUT -p udp --dport 49198 -j ACCEPT PostUp = iptables -I FORWARD -i eth0 -o wg0 -j ACCEPT PostUp = iptables -I FORWARD -i wg0 -j ACCEPT PostUp = iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostUp = ip6tables -I FORWARD -i wg0 -j ACCEPT PostUp = ip6tables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D INPUT -p udp --dport 49198 -j ACCEPT PostDown = iptables -D FORWARD -i eth0 -o wg0 -j ACCEPT PostDown = iptables -D FORWARD -i wg0 -j ACCEPT PostDown = iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE PostDown = ip6tables -D FORWARD -i wg0 -j ACCEPT PostDown = ip6tables -t nat -D POSTROUTING -o eth0 -j MASQUERADE ### Client Realme [Peer] PublicKey = - PresharedKey = - AllowedIPs = 10.66.66.2/32,fd42:42:42::2/128 ### Client LapBottom [Peer] PublicKey = - PresharedKey = - AllowedIPs = 10.66.66.3/32,fd42:42:42::3/128 ### Client reno [Peer] PublicKey = - PresharedKey = - AllowedIPs = 10.66.66.4/32,fd42:42:42::4/128 ### Client MacOS [Peer] PublicKey = - PresharedKey = - AllowedIPs = 10.66.66.5/32,fd42:42:42::5/128 ### Client KDE [Peer] PublicKey = - PresharedKey = - AllowedIPs = 10.66.66.6/32,fd42:42:42::6/128,192.168.0.0/24 #可访问192.168.0.0段 ### Client WinOS [Peer] PublicKey = - PresharedKey = - AllowedIPs = 10.66.66.7/32,fd42:42:42::7/128 ### Client bb [Peer] PublicKey = - PresharedKey = - AllowedIPs = 10.66.66.8/32,fd42:42:42::8/128
最后使用各设备客户端连接就行。
本文作者:Maxwell
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 CC BY-NC 4.0 许可协议。转载请注明出处!