一、安装Socat
CentOS 环境:
yum -y install socat
Debian/Ubuntu 环境:
apt-get update
apt-get -y install socat
二、使用Socat
转发TCP+设置后台运行
nohup socat TCP4-LISTEN:8888,reuseaddr,fork TCP4:10.0.0.2:8888 >> socat.log 2>&1 &
转发UDP+设置后台运行
nohup socat UDP4-LISTEN:8888,reuseaddr,fork UDP4:10.0.0.2:8888 >> socat.log 2>&1 &
说明
LISTEN:8888 为监听本地的端口,fork TCP4:10.0.0.2:8888 为转发目标的IP地址+端口,可按实际需求修改使用
三、设置开机自启动
CentOS 环境
编辑 /etc/rc.d/rc.local 文件,插入上方代码
Debian/Ubuntu 环境
编辑 /etc/rc.local 文件,插入上方代码
转自:https://saltyfish.ac.cn/archives/47
0