网站首页 > 博客文章 正文
点击上方"walkingcloud"关注,并选择"星标"公众号
一、wireguard简单介绍
什么是 WireGuard?
WireGuard 是一个易于配置、快速且安全的开源 Virtual Private Network,它利用了最新的加密技术。目的是提供一种更快、更简单、更精简的通用 Virtual Private Network,它可以轻松地在树莓派这类低端设备到高端服务器上部署。
IPsec 和 OpenV*P*N 等大多数其他解决方案是几十年前开发的。安全研究人员和内核开发人员 Jason Donenfeld 意识到它们速度慢且难以正确配置和管理。
这让他创建了一个新的开源Virtual Private Network 协议和解决方案,它更加快速、安全、易于部署和管理。
WireGuard 最初是为 Linux 开发的,但现在可用于 Windows、macOS、BSD、iOS 和 Android。除了可以跨平台之外,WireGuard 的最大优点之一就是易于部署。配置和部署 WireGuard 就像配置和使用 SSH 一样容易
WireGuard 受到 Linus 本人的推荐,将整合到最新版Linux Kernel中,安装部署更方便。WireGuard 总共几千行代码,只需十分钟就能搞定一台WireGuard服务器。
Wireguard安全性高。极佳的Virtual Private Network 漫有特性,设备支持广泛。内核级别的端对端隧道加密技术,拥有良好的加密特性。Wireguard配置文件由两部分组成:interface和peer。服务器端、客户端互为平等关系。支持预共享密钥preshared key加密,防攻击
当将 WireGuard 安装为内核模块时,基本上需要你自行修改 Linux 内核并向其添加代码。从 5.6 内核开始,你无需手动添加内核模块。默认情况下它将包含在内核中
所以下面使用Fedora Server 33版本来配置Wireguard
(内核版本5.8.15,默认就支持wireguard)
参考如下连接完成
https://www.linode.com/docs/guides/set-up-wireguard-vpn-on-ubuntu/
拓扑如下
(图片可放大查看)
1) 左侧内网A Fedora33机器的IP 192.168.233.128作为wireguard Server端
2) 在左侧出口路由器上映射192.168.233.128的TCP 22(SSH)和UDP 51820(WireGuard Server通信端口),映射后公网为10.20.90.193(模拟公网IP)
3) 右侧内网B Fedora33机器的IP 192.168.198.131作为wireguard Client端
二、Wireguard Server端配置
1、Server端安装wireguard
内网IP 192.168.233.128
dnf install wireguard-tools
(图片可放大查看)
(图片可放大查看)
2、创建密钥对
1、服务端的私钥
wg genkey | tee /etc/wireguard/server.key
yAQFm+E6gVBCG7c72lhRngaCZy+gVzCCpRbudPmuKms=
2、服务端的公钥
cat /etc/wireguard/server.key | wg pubkey | tee /etc/wireguard/server.pub
BRPmId4mnGBfCgmniDf3Ar+1cvXcS85pntqYH1w0jlM=
3、客户端的私钥
wg genkey | tee /etc/wireguard/client.key
8F3bI2FydYhh8Ps9Xi2IenrdQrH9xXw6wzJaVrRSSHE=
4、客户端的公钥
cat /etc/wireguard/client.key | wg pubkey | tee /etc/wireguard/client.pub
hXhveUdRmz6uQEr+7fQOh1YQ1c56sTiIXfzHVTmeBGs=
(图片可放大查看)
3、创建wg0的接口配置文件
ip addr或者ifconfig
先确认目前的网络接口名称
如下图所示网络接口名称 为ens33
(图片可放大查看)
接下来编辑wg0.conf
vi /etc/wireguard/wg0.conf
#添加如下内容
[Interface]
# specify generated private key for server
PrivateKey = yAQFm+E6gVBCG7c72lhRngaCZy+gVzCCpRbudPmuKms=
# IP address for VPN interface
Address = 172.16.100.1
# UDP port WireGuard server listens
ListenPort = 51820
# possible to set any commands after WireGuard starts/stops
# set routing rules like follows to access to local network via VPN session
# [wg0] ? VPN interface name
# [eth0] ? Ethernet interface name
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o ens33 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o ens33 -j MASQUERADE
[Peer]
# specify public key for client
PublicKey = hXhveUdRmz6uQEr+7fQOh1YQ1c56sTiIXfzHVTmeBGs=
# clients' VPN IP addresses you allow to connect
# possible to specify subnet ? [172.16.100.0/24]
AllowedIPs = 172.16.100.5
4、内核开启IPv4转发
vi /etc/sysctl.conf
添加一行
net.ipv4.ip_forward=1
生效配置
sysctl -p
(图片可放大查看)
5、启动wg-quick服务
systemctl enable wg-quick@wg0
systemctl start wg-quick@wg0.service
ip addr
(图片可放大查看)
三、路由器端口映射配置
1)映射192.168.233.128的TCP 22(SSH)——方便调试
2)UDP 51820(WireGuard Server通信端口)
映射后公网为10.20.90.193(模拟公网IP)
由于是使用VMwareWorkstation虚拟机NAT模式搭建的环境,端口映射的配置方式如下
(图片可放大查看)
(图片可放大查看)
(图片可放大查看)
四、WireGuard客户端配置
1、安装wireguard-tools
dnf install wireguard-tools
(图片可放大查看)
(图片可放大查看)
2、添加wg0.conf配置文件
vi /etc/wireguard/wg0.conf
cat /etc/wireguard/wg0.conf
添加如下配置
[Interface]
# specify private key for client generated on WireGuard server
PrivateKey = 8F3bI2FydYhh8Ps9Xi2IenrdQrH9xXw6wzJaVrRSSHE=
# IP address for VPN interface
Address = 172.16.100.5
[Peer]
# specify public key for server generated on WireGuard server
PublicKey = BRPmId4mnGBfCgmniDf3Ar+1cvXcS85pntqYH1w0jlM=
# IP addresses you allow to connect
# on the example below, set WireGuard server's VPN IP address and real local network
AllowedIPs = 172.16.100.1, 192.168.233.0/24
# specify server's global IP address:port
# (acutually, example of IP below is for private range, replace to your own global IP)
EndPoint = 10.20.90.193:51820
(图片可放大查看)
3、nc探测端口是否通
nc -vuz 10.20.90.193 51820
(图片可放大查看)
4、若端口可通,启动wg0接口
wg-quick up wg0
#关闭则用wg-quick down wg0
(图片可放大查看)
5、wg show查看连接状况并测试是否可以访问到Server端的网络
wg show
(图片可放大查看)
如下图所示,测试OK,WireGuard虚拟专用网搭建成功
(图片可放大查看)
Tips
若Server端没有关闭firewalld防火墙,可能会导致客户端无法访问Server端的LAN网络
需要在Server端关闭firewalld防火墙并重启wg-quick服务
猜你喜欢
- 2024-09-11 教你搭建IPSec 服务端Linux(如何搭建ipsec服务器)
- 2024-09-11 一文读懂:RHEL如何通过control-center建立安全的IPsec VPN连接
- 2024-09-11 出差在外异地办公不愁,蒲公英X6打造最强VPN异地组网
- 2024-09-11 linux下开发一个应用,首先要做什么?
- 2024-09-11 Centos6下搭建openvpn并使用密钥形式登录
- 2024-09-11 使用虚拟专用网络的Python Web抓取
- 2024-09-11 搭建家庭服务器:Linux全攻略(家庭服务器搭建局域网)
- 2024-09-11 CentOS 搭建 OpenVPN 服务(在linux centos 7搭建openvpn服务与管理)
- 2024-09-11 ORB305连接Linux搭建的OpenVPN服务器操作手册
你 发表评论:
欢迎- 06-23MySQL合集-mysql5.7及mysql8的一些特性
- 06-23MySQL CREATE TABLE 简单设计模板交流
- 06-23MYSQL表设计规范(mysql设计表注意事项)
- 06-23MySQL数据库入门(四)数据类型简介
- 06-23数据丢失?别慌!MySQL备份恢复攻略
- 06-23MySQL设计规范(mysql 设计)
- 06-23MySQL数据实时增量同步到Elasticsearch
- 06-23MySQL 避坑指南之隐式数据类型转换
- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)