使用iptables 很容易将TCP 和UDP 端口从防火墙转发到内部主机上。但是如果您需要将流量从专用地址转发到甚至不在您当前网络上的机器上,又该怎么办呢?可以用rinetd;
下载,如果wget http://www.boutell.com/rinetd/http/rinetd.tar.gz下载不了。直接把地址贴到网页下载http://www.boutell.com/rinetd/http/rinetd.tar.gz
下载好解压
tar -xvf rinetd.tar.gz
进入解压目录make && make install;再执行echo $? 看下有没有报错;
添加配置文件
[root@jw rinetd]# vim /etc/rinetd.conf[root@jw rinetd]# cat !$cat /etc/rinetd.conf0.0.0.0 6379 111.111.111.111 6379##说明一下(0.0.0.0表示本机绑定所有可用地址)###将所有发往本机6379端口的请求转发到111.111.111.111的6379端口,即redislogfile /var/log/rinetd.log ?——日志目录[root@jw rinetd]#
配置文件绑定格式
命令格式是
bindaddress bindport connectaddress connectport
绑定的地址 ?绑定的端口 ?连接的地址 ?连接的端口
[root@jw rinetd]# rinetd [root@jw rinetd]# echo $?0[root@jw rinetd]# netstat -antupActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address ??????????????Foreign Address ????????????State ??????PID/Program name ??tcp ???????0 ?????0 0.0.0.0:6379 ???????????????0.0.0.0:* ??????????????????LISTEN ?????3096/rinetd ????????tcp ???????0 ?????0 0.0.0.0:111 ????????????????0.0.0.0:* ??????????????????LISTEN ?????1025/rpcbind ???????tcp ???????0 ?????0 0.0.0.0:22 ?????????????????0.0.0.0:* ??????????????????LISTEN ?????1092/sshd ??????????tcp ???????0 ????52 192.168.3.2:22 ?????????????192.168.3.100:1529 ?????????ESTABLISHED 1120/sshd ??????????tcp ???????0 ?????0 :::111 ?????????????????????:::* ???????????????????????LISTEN ?????1025/rpcbind ???????tcp ???????0 ?????0 :::22 ??????????????????????:::* ???????????????????????LISTEN ?????1092/sshd ??????????udp ???????0 ?????0 0.0.0.0:111 ????????????????0.0.0.0:* ??????????????????????????????1025/rpcbind ???????udp ???????0 ?????0 0.0.0.0:776 ????????????????0.0.0.0:* ??????????????????????????????1025/rpcbind ???????udp ???????0 ?????0 0.0.0.0:68 ?????????????????0.0.0.0:* ??????????????????????????????955/dhclient ???????udp ???????0 ?????0 :::111 ?????????????????????:::* ???????????????????????????????????1025/rpcbind ???????udp ???????0 ?????0 :::776 ?????????????????????:::* ???????????????????????????????????1025/rpcbind ???????[root@jw rinetd]#
执行rinetd命令,可以看到已经启动了6379端口了。
停止rinetd命令
pkill rinetd
rinetd -c /etc/rinetd.conf ?##启动转发
echo rinetd >>/etc/rc.local##添加到开机启动
如果你在阿里云买了一台redis,需要公网访问,可以参考使用rinetd
以下链接:https://help.aliyun.com/document_detail/43850.html
linux 下使用rinetd实现流量转发
原文地址:http://blog.51cto.com/12185273/2106571