当前位置:网站首页>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] |
至此,服务端、客户端配置已完成。
边栏推荐
猜你喜欢

DSPE-PEG-Thiol DSPE-PEG-SH phospholipid-polyethylene glycol-thiol liposome for later use

crontab timing operation

2021-09-30

十分钟教你玩转分支语句!!!!!小白速进,新手福利!!

Learn how to get a database connection with JDBC

【博学谷学习记录】超强总结,用心分享 | 软件测试 抓包

UR3机器人运动学分析之正运动学分析

Pytorch study notes 13 - Basic_RNN

Pytorch learning notes 09 - multiple classification problem

Picture-in-Picture API in the browser
随机推荐
软件测试之登录测试详解
Unity加载GIf动画
【博学谷学习记录】超强总结,用心分享 | 软件测试 UnitTest框架
【源码笔记】痛苦来源于比较——什么是相等,hashCode() 和 equals(Object)
ES6-对象
VRchat_udon脚本介绍:傻瓜式教程教你如何实现VRchat地图的功能
ImportError: cannot import name 'Xxxx' from partially initialized module 'xx.xx.xx'
file和stat命令的使用,文件类型:代表字符,以及英文
力扣.有效的字母异位词
WIN10,配置adb环境
通过js禁止ctrl+滚轮放缩浏览器页面,禁止用手势放大
alert弹框处理,div块处理,上传文件
钉钉H5微应用免登鉴权
cenos版本查询,及离线安装zip和unzip
APP测试:测试流程及常规测试内容
滑动窗口法
这些数组技巧,我爱了
911崩了,自养号测评环境IP有哪些更好的选择
安装显卡过程中遇到问题汇总
简单计算器,单层循环输出乘法表,字符串方法的使用,格式化输出