视频加载失败

【脚本】wireguard配合socat转发端口

241 字
1 分钟
【脚本】wireguard配合socat转发端口
【脚本】wireguard配合socat转发端口

0x0#

之前是使用iptables进行端口转发,但是iptables规则较为麻烦,所以就使用socat进行转发

0x1#

首先,在PostUp选项中启动socat时,将socat的进程ID(PID)保存到一个文件中。然后,在PostDown选项中读取该文件,并使用保 存的PID来关闭socat进程。

示例:

[Interface]
PrivateKey = <PrivateKey>
Address = <IPAddress>
...
PostUp = /usr/bin/python3 /root/socat.py --range '10.13.13.0/24' add 8080 192.168.137.1:8000
# -d -d可以输出详细的调试信息
#PostUp = socat -d -d TCP-LISTEN:8080,range=10.13.13.0/24,fork,reuseaddr TCP:192.168.137.1:8000 & echo $! > /home/rehtt/8080_socat.pid
# 在停止 WireGuard 接口之后执行操作
PostDown = /usr/bin/python3 /root/socat.py --range '10.13.13.0/24' del 8080 192.168.137.1:8000
#PostDown = kill $(cat /home/rehtt/8080_socat.pid) && rm -f /home/rehtt/8080_socat.pid

在示例中,使用/home/rehtt/8080_socat.pid文件来存储socat进程的PID,并在PostUp选项中使用echo $!将其写入文件。然后,在PostDown选项中,我们使用kill $(cat /home/rehtt/8080_socat.pid)命令来杀死socat进程,并使用rm -f /home/rehtt/8080_socat.pid命令删除PID文件

使用封装好的脚本处理

脚本链接

支持与分享

如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!

打赏
【脚本】wireguard配合socat转发端口
https://rehtt.com/posts/266/
作者
Rehtt
发布于
2023-09-12
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
Rehtt
Hello, I'm Rehtt.
公告
欢迎来到我的博客!
分类
标签
最新动态
站点统计
文章
150
分类
17
标签
73
总字数
67,772
运行时长
0 天
最后活动
0 天前
站点信息
构建平台
Local
博客版本
Firefly v6.16.8
文章许可
CC BY-NC-SA 4.0
文章目录