debian和centos系统socat网络端口转发

安装软件包

1
2
3
4
5
#CentOS系统
yum install -y socat
#Ubuntu或Debian系统
apt-get update
apt-get install -y socat

tcp端口转发

1
2
3
socat  -d  TCP4-LISTEN:8080,reuseaddr,fork TCP4:127.0.0.1:8080
# 后台运行
nohup socat TCP4-LISTEN:8080,reuseaddr,fork TCP4:127.0.0.1:8080 >> socat.log 2>&1 &

udp端口转发

1
2
3
socat -T 600 UDP4-LISTEN:5353,reuseaddr,fork UDP4:114.114.114.114:53
# 后台运行
nohup socat -T 600 UDP4-LISTEN:5353,reuseaddr,fork UDP4:114.114.114.114:53 >> socat.log 2>&1 &