linux配置端口转发

时间:2023-12-03 09:24:08

一、使用rinted进行端口转发

将10.50.13.13 80请求转到10.50.13.11 80上

1、安装rinetd

$ tar zxf rinetd.tar.gz
$ cd rinetd
$ make
$ make install

2、编辑配置文件

$ vi /etc/rinetd.conf  添加如下内容
$ 0.0.0.0 10.50.13.11 #本机IP为10.50.13.

3、启动rinetd服务

$ rinetd -c /etc/rinetd.conf

二、使用iptables进行端口转发

将10.50.13.13 80请求转到10.50.13.11 80上,配置如下:

iptables -t nat -A PREROUTING -d 10.50.13.13 -p tcp --dport  -j DNAT --to-destination 10.50.13.11:
iptables -t nat -A POSTROUTING -s 0.0.0.0/ -p tcp --dport -j SNAT --to-source 10.50.13.13
/etc/init.d/iptables save
echo > /proc/sys/net/ipv4/ip_forward #打开路由转发功能