CentOS 使用 rinetd 端口映射

CentOS 使用 rinetd 端口映射

一般映射采用两种方式,iptables 或者 rinetd 来实现转发,我建议使用 rinetd 来实现,因为 iptables 使用 PREROUTING 链来桥接,这回导致本地无法访问,需要单独映射端口,比较麻烦

iptables

这里只给出相关脚本

iptables -t nat -A PREROUTING --dst 192.168.1.4 -p tcp --dport 3306 -j DNAT --to-destination 192.168.1.227:3306
iptables -t nat -A POSTROUTING --dst 192.168.1.227 -p tcp --dport 3306 -j SNAT --to-source 192.168.1.4
service iptables save
service iptables restart

rinetd

配置源

vim /etc/yum.repos.d/nux-misc.repo

[nux-misc]
name=Nux Misc
baseurl=http://li.nux.ro/download/nux/misc/el6/x86_64/
enabled=0
gpgcheck=1
gpgkey=http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro

安装 rinetd

yum --enablerepo=nux-misc install rinetd

配置

[bindaddress] [bindport] [connectaddress] [connectport]
绑定的地址 绑定的端口 连接的地址 连接的端口
[Source Address] [Source Port] [Destination Address] [Destination Port]
源地址 源端口 目的地址 目的端口

配置规则

vim /etc/rinetd.conf

0.0.0.0 8080 172.19.94.3 8080
0.0.0.0 2222 192.168.0.103 3389
1.2.3.4 80 192.168.0.10 80

allow *.*.*.*
logfile /var/log/rinetd.log

说明:

0.0.0.0 表示本机绑定所有可用地址

将所有发往本机 8080 端口的请求转发到 172.19.94.3 的 8080 端口
将所有发往本机 2222 端口的请求转发到 192.168.0.103 的 3389 端口
将所有发往 1.2.3.4 的 80 端口请求转发到 192.168.0.10 的 80 端口
allow 设置允许访问的 ip 地址信息,... 表示所有IP地址

logfile 设置打印的 log 的位置

启动和关闭

/etc/init.d/rinetd start
/etc/init.d/rinetd stop
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GettingReal

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值