【脚本】wireguard配合socat转发端口
241 字
1 分钟
【脚本】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文件
使用封装好的脚本处理
支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!
相关文章智能推荐
1
【脚本】修改wireguard端口
杂项2023-09-12
2
【Linux】使用iptables进行端口映射
Linux笔记2023-04-21
3
【网络】Caddy + PHP7.3
杂项2019-11-05
4
【脚本】在jetson nano上使用摄像头分段录像并开启端口推流
杂项2026-01-08
5
【NFC】恢复被写入cpu卡SAK的CUID魔术卡
杂项2026-05-10
随机文章随机推荐















加载更多…