跳转到主要内容
你行网

Main navigation

  • 首页
  • Drupal
  • 编程与开发
  • 数据库
  • 操作系统与应用
  • 服务器与运维
  • 社区
User account menu
  • 登录

面包屑

  1. 首页

WireGuard 使用命令

由 hrs, 3 三月, 2025

1. 启动 WireGuard 接口
使用 wg-quick 工具启动配置文件中的 WireGuard 接口:

bash
复制
sudo wg-quick up <配置文件名称>
例如:

bash
复制
sudo wg-quick up wg0
配置文件通常位于 /etc/wireguard/ 目录下,例如 /etc/wireguard/wg0.conf。

启动后,WireGuard 会自动配置网络接口、路由和 DNS。

2. 停止 WireGuard 接口
停止正在运行的 WireGuard 接口:

bash
复制
sudo wg-quick down <配置文件名称>
例如:

bash
复制
sudo wg-quick down wg0
3. 查看 WireGuard 接口状态
使用 wg 命令查看当前 WireGuard 接口的状态和对等节点信息:

bash
复制
sudo wg
输出示例:

复制
interface: wg0
 public key: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 private key: (hidden)
 listening port: 51820

peer: yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
 endpoint: 203.0.113.1:51820
 allowed ips: 0.0.0.0/0
 latest handshake: 1 minute ago
 transfer: 1.23 MiB received, 456.78 MiB sent
4. 生成密钥对
WireGuard 使用公钥和私钥进行加密通信。可以使用以下命令生成密钥对:

生成私钥:

bash
复制
wg genkey
从私钥生成公钥:

bash
复制
echo "<私钥>" | wg pubkey
例如:

bash
复制
wg genkey | tee privatekey | wg pubkey > publickey
privatekey 文件保存私钥。

publickey 文件保存公钥。

5. 手动添加对等节点
使用 wg set 命令手动添加对等节点(Peer):

bash
复制
sudo wg set <接口名称> peer <对等节点公钥> allowed-ips <允许的IP范围> endpoint <对等节点地址:端口>
例如:

bash
复制
sudo wg set wg0 peer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx allowed-ips 10.0.0.2/32 endpoint 203.0.113.1:51820
6. 删除对等节点
使用 wg set 命令删除对等节点:

bash
复制
sudo wg set <接口名称> peer <对等节点公钥> remove
例如:

bash
复制
sudo wg set wg0 peer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx remove
7. 修改 WireGuard 配置
WireGuard 的配置文件通常位于 /etc/wireguard/ 目录下。你可以直接编辑配置文件:

bash
复制
sudo nano /etc/wireguard/wg0.conf
配置文件示例:

ini
复制
[Interface]
PrivateKey = <你的私钥>
Address = 10.0.0.1/24
ListenPort = 51820
DNS = 8.8.8.8

[Peer]
PublicKey = <对等节点公钥>
AllowedIPs = 10.0.0.2/32
Endpoint = 203.0.113.1:51820
修改后,重新加载配置:

bash
复制
sudo wg-quick down wg0
sudo wg-quick up wg0
8. 查看网络接口信息
使用 ip 命令查看 WireGuard 接口的网络信息:

bash
复制
ip addr show <接口名称>
例如:

bash
复制
ip addr show wg0
9. 查看路由表
WireGuard 会自动添加路由规则。你可以使用以下命令查看路由表:

bash
复制
ip route
或者查看特定接口的路由:

bash
复制
ip route show dev wg0
10. 启用持久化配置
WireGuard 的配置在重启后不会自动保存。如果需要持久化配置,可以将配置写入配置文件,并使用 systemd 启用服务:

bash
复制
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
11. 调试 WireGuard
如果遇到问题,可以使用以下命令调试:

查看日志:

bash
复制
sudo journalctl -u wg-quick@wg0
使用调试模式启动:

bash
复制
sudo WG_QUICK_USERSPACE_IMPLEMENTATION=boringtun WG_SUDO=1 wg-quick up wg0
12. 卸载 WireGuard
如果需要卸载 WireGuard,可以使用以下命令:

bash
复制
sudo apt remove wireguard
sudo apt autoremove

  • 登录或注册以发表评论
内容类型分类
技术文章
文章归类
操作系统与运用

文章标签

  • WireGuard

评论

文章标签

CSS
Excel
ubuntu
php
vim
五笔
Linux
VPN
command
HTML
drupal 8
drupal 7
centos
composer
Mysql
drush
模块(module)
Drupal
JavaSrcipt
apache
drupal 9
英语
nerdtree
SEO
network
果树种植
surround
drupal10
主题(theme)
ssh
phpmyadmin
yum
二进制
权限
声音
ssl
selinux
HTML5
WireGuard
password
Dreamweaver
DDEV
flameshot
翻译
颜色
uploadprogress
firewalld
kernel
邮件验证
视图(views)
快捷键
gzip
xdebug
错误
电脑基础
ckeditor
C语言
简介
源地址
mbstring
certbot
php扩展
git
csharp
httpd
apt
电子秤
压缩解压
breadcrumb
表单
短信验证
AI
firmware
摄影
diff
superfish
重定向
drupal 11
网站备份
docker
版本号
tagclouds
java
RSS
adsense
端口
电脑技巧
simple_adsense
KVM
算法
youtube
JavaScript
cookie
badblocks
网站运营
计算机基础
RFID
zip
标签优化
VUE
dns
gimp
form
mod_expires 模块
赚钱
ip
http验证
curl
重定向,301
netstat
字段
maven
input
nginx
哈希值
npm
wps
更多

相关文章

  • 因权限问题导致drupal cms 无法正常安装,那么该如何解决这个问题
  • kvm虚拟机启动失败:default网络未激活
  • ubuntu 安装kvm 虚拟机
  • 匿名函数(Anonymous Functions)详解
  • foreach 是 PHP 循环语句使用方法
  • implode() 函数的定义和用法
  • Drupal 11 主题制作教程
  • 检查 Composer 是否为官方源
  • 在 Drupal 中权重(Weight)是怎样排序的
  • 解决 Drupal 主题缺失问题
RSS源

友情链接 网站地图 版权信息 联系我们 网址导航 社区

Copyright © 2019 - 2021 你行网 版权所有  粤ICP备19072650号