当前位置:网站首页>Debian 搭建 WireGuard 服务端
Debian 搭建 WireGuard 服务端
2022-07-31 05:19:00 【wdhqwe520】
CONTENTS
本文以 Debian 10 为例,介绍如何搭建 WireGuard 服务端,并说明对应的客户端搭建方法和配置文件的格式。Ubuntu 20.04 系统与之大同小异。
注:请先参照 Debian & Ubuntu 服务器的初始化配置 一文对服务器进行各种必要的配置。本文以 sammy 用户为例,进行 WireGuard 的部署,并默认已按初始化配置文章对服务器进行了配置。
准备工作
安装步骤所需软件包:
1 2 | sudo apt update sudo apt install apt-transport-https vim -y |
安装 WireGuard
添加 backports 源:
1 | sudo sh -c "echo 'deb https://deb.debian.org/debian buster-backports main contrib non-free' > /etc/apt/sources.list.d/buster-backports.list" |
安装软件包:
1 2 | sudo apt update sudo apt -t buster-backports install wireguard -y |
配置服务端
切换到 root 用户:
1 | sudo -i |
创建私钥、公钥:
1 2 3 | cd /etc/wireguard umask 077 wg genkey | tee privatekey | wg pubkey > publickey |
记录私钥、公钥:
1 2 | cat privatekey # 服务端私钥 cat publickey # 服务端公钥 |
创建配置文件,并添加内容:
1 2 | exit # 退出 root 用户 sudo vim /etc/wireguard/wg0.conf |
/etc/wireguard/wg0.conf
1 2 3 4 5 6 7 | [Interface] Address = 10.0.0.1/24 SaveConfig = true PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE ListenPort = 自定义端口 PrivateKey = 服务器私钥 |
防火墙配置:
1 | sudo ufw allow 自定义端口/udp |
启动服务:
1 2 | sudo systemctl enable [email protected] sudo systemctl start [email protected] |
查看服务状态:
1 | sudo systemctl status [email protected] |
查看实际效果:
1 2 | sudo wg sudo ip a show wg0 |
至此,服务端的配置大体完成,稍后还需要在客户端配置后,在服务端添加客户端的节点信息。
客户端配置
Debian 10 下客户端的安装流程、私钥公钥生成方法,和服务端的步骤类似,此处不再赘述。
创建配置文件,并添加内容:
1 | sudo vim /etc/wireguard/wg0.conf |
/etc/wireguard/wg0.conf
1 2 3 4 5 6 7 8 9 | [Interface] PrivateKey = 客户端私钥 Address = 10.0.0.2/24 DNS = 8.8.8.8 [Peer] PublicKey = 服务端公钥 AllowedIPs = 0.0.0.0/0 Endpoint = 服务器 IP 地址:服务器自定义端口 |
启动服务:
1 2 | sudo systemctl enable [email protected] sudo systemctl start [email protected] |
查看服务状态:
1 | sudo systemctl status [email protected] |
服务端再配置
在服务器上:
1 2 | sudo systemctl stop [email protected] sudo vim /etc/wireguard/wg0.conf |
增加 [Peer] 信息,修改后总体如下:
/etc/wireguard/wg0.conf
1 2 3 4 5 6 7 8 9 10 11 | [Interface] Address = 10.0.0.1/24 SaveConfig = true PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE ListenPort = 服务端自定义端口 PrivateKey = 服务端私钥 [Peer] PublicKey = 客户端公钥 AllowedIPs = 10.0.0.2/32 |
启动服务:
1 | sudo systemctl start [email protected] |
至此,服务端、客户端配置已完成。
边栏推荐
- Attention based ASR(LAS)
- Log jar package conflict, and its solution
- Pytorch study notes 7 - processing input of multi-dimensional features
- DSPE-PEG-Thiol DSPE-PEG-SH phospholipid-polyethylene glycol-thiol liposome for later use
- 【Latex】TexLive+VScode+SumatraPDF 配置LaTex编辑环境
- MySQL free installation download and configuration tutorial
- 等待,信息打印,浏览器操作,键盘事件
- Unity导入我的世界模型,简单图解教程(包括调整材质贴图和光照和添加碰撞)
- UR3机器人雅克比矩阵
- 什么样的人不适合入行编程?你真的适合学习编程吗?
猜你喜欢

C语言静态变量static

IDEA概述和安装及调试

Log jar package conflict, and its solution

2022年软件测试现状最新报告

Chemical Reagent Phospholipid-Polyethylene Glycol-Amino, DSPE-PEG-amine, CAS: 474922-26-4

力扣.两数之和/四数相加||

The solution to the IDEA console not being able to enter information

Image binarization processing of opencv

APP测试:测试流程及常规测试内容

Wlan实验(ENSP)
随机推荐
UE5 最新动态虚幻引擎全新版本引爆互联网
Pytorch study notes 10 - detailed explanation of convolutional neural network and application of multi-classification task of mnist dataset
DOM操作案例1-点击,使表格的颜色切换(点击单元格,整行或整列颜色切换)
Pytorch study notes 7 - processing input of multi-dimensional features
ES6-02-let和const关键字
企业级 DevOps 究竟是什么?
力扣151. 颠倒字符串中的单词
ES6-Map和Set
a:自我介绍
TCP与UDP协议的区别,以及TCP的三次握手和四次挥手
面试总爱问的一个问题,你为什么离职上一份工作?
【Rhapsody学习笔记】1:Hello World
Use usb_cam to open multiple cameras at the same time
Unity Text一个简单的输入特效
911崩了,自养号测评环境IP有哪些更好的选择
Three methods of accessing image pixels in opencv
Unity软件中UGUI和NGUI的多语言开发
DOM操作-案例:切换背景图片
【Rhapsody学习笔记】4:Relations
PyTorch Study Notes 08 - Loading Datasets