使用socat搭建TCP流量转发服务

  • 需求场景
    希望将A设备的2022端口转发到B设备的22端口,主要是使用socat工具,如下是在ubuntu系统中的安装使用方式

  • 安装
    sudo apt-get install socat -y

  • 手动启动
    socat TCP-LISTEN:2022,fork TCP:<B设备IP>:22
    此时代理搭建成功,只不过是临时性的,如果需要配置开机启动和后台自动启动则需要额外配置:

  • 创建服务文件
    vim /etc/systemd/system/socat-forwarding.service
    添加

[Unit]
Description=Socat Port Forwarding Service
After=network.target
[Service]
ExecStart=/usr/bin/socat TCP-LISTEN:2022,fork TCP:<B设备IP>:22
Restart=on-failure
[Install]
WantedBy=multi-user.target

*重新加载 systemd 并启用服务

sudo systemctl daemon-reload
sudo systemctl enable socat-forwarding.service
  • 启动服务
sudo systemctl start socat-forwarding.service

*检查服务状态:
你可以通过以下命令检查服务的运行状态:

sudo systemctl status socat-forwarding.service
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容