需求场景
希望将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