端口映射工具 redir/socat/xinetd - 运维技术 - 开源中国社区

端口映射工具 redir/socat/xinetd - 运维技术 - 开源中国社区mysql

    端口映射工具 redir/socat/xinetd     10人收藏此文章, 我要收藏 发表于3天前(2013-08-30 14:09) , 已有96次阅读 ,共0个评论         过去习惯每台服务器都有外网IP,等服务器数量增多以后有所收敛。迎面而来的须要就是:服务好一个大内网。         NAT网关,一般用iptables实现,但性能不好不适合用于生产环境。可经过硬件设备或小米开源的dsnat完成。         端口映射的需求也常有,经过也是用iptables实现。但是iptables过重,性能是个大问题,且每次更新都须要重启。         此时,咱们须要一个工具来实现端口映射。若是纯粹是HTTP协议,那么直接用Nginx便可。像MySQL、MongoDB之类则不适用。Google一翻,答案知晓:redir 、socat 。         其中 redir 只支持TCP协议,但使用很是简单。好比将外网的2669端口映射对内网1台MySQL服务器,一键搞定:     view source     print?     1    redir --lport=2669 --caddr=10.58.66.32 --cport=3306       还有一点高级功能就去自行查阅帮助吧。        socat则更强大,支持ipv四、ipv六、tcp、udp、unix-socks、socket等等了。出于“The simpler the better”的观念,恭喜redir入围!       若是映射量比较大,须要易维护、搞攻击,就必须想到xinted了。配置 /etc/xinetd.d/mysql-portmap 以下:     view source     print?     01    service mysql-portmap {     02        id = 1     03        disable = no     04        type = UNLISTED     05        socket_type = stream     06        protocol = tcp     07        wait = no     08        redirect = 10.33.66.88 3306     09        bind = 183.68.36.138     10        port = 2669     11        user = nobody     12        group = nobody     13        flags = NODELAY KEEPALIVE NOLIBWRAP IPv4     14        log_type = FILE /data/log/xinetd/tcp-portmap.log     15        cps = 100 30     16    }        每一个映射能够有独立配置文件来管理,修改只须要reload便可!当受到攻击时,在系统日志 /var/log/messages 中会看到:         xinetd[26269]: Starting reconfiguration         xinetd[26269]: Swapping defaults         xinetd[26269]: readjusting service rsync         xinetd[26269]: service mysql-portmap deactivated         xinetd[26269]: mysql-portmap: svc_release with 0 count         xinetd[26269]: Reconfigured: new=1 old=1 dropped=1 (services)         xinetd[26269]: Deactivating service mysql-portmap due to excessive incoming connections.  Restarting in 10 seconds.         xinetd[26269]: Activating service mysql-portmap        用xinetd来管理端口映射简单太完美了!
相关文章
相关标签/搜索