使用socat进行单个端口的转发 支持tcp和udp

2020年03月17日

转载文章:https://www.moerats.com/archives/97/
用socat工具来完成端口转发,如果你只有少数几个端口要转发的话,那么socat就是比较好的选择了。socat唯一麻烦的地方就是好像我没找到如何转发端口段,只能一个命令一个端口。不过如果只是自用转发少量端口的话还是蛮好用的。
socat安装

#CentOS系统
yum install -y socat

#Ubuntu或Debian系统
apt-get update
apt-get install -y socat

 

socat的使用

1、转发TCP

nohup socat TCP4-LISTEN:10000,reuseaddr,fork TCP4:1.1.1.1:10000 >> socat.log 2>&1 &

 

TCP4-LISTEN:10000监听ipv4的10000TCP端口。10000改成你自己需要转发的端口
fork TCP4:1.1.1.1:10000`转发到1.1.1.1的10000端口,根据需求修改自行修改ip和端口
nohup后台运行。可以把这个命令写到/etc/rc.local里面开机启动启动。

 

2、转发UDP

nohup socat -T 600 UDP4-LISTEN:10000,reuseaddr,fork UDP4:1.1.1.1:10000 >> socat.log 2>&1 &

 
把tcp改成udp就是转发udp了。说明如上。也可以直接写到/etc/local里面开机自动启动。


sicnature ---------------------------------------------------------------------
Your current IP address is: 54.166.223.204
Your IP address location: 美国弗吉尼亚阿什本
Your IP address country and region: 美国 美国
Your current browser is:
Your current system is:
Original content, please indicate the source:
同福客栈论坛 | 蟒蛇科普海南乡情论坛 | JiaYu Blog
sicnature ---------------------------------------------------------------------
Welcome to reprint. Please indicate the source http://myzhenai.com/post/3181.html

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注