linux配置端口转发

一、使用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 80 10.50.13.11 80  #本机IP为10.50.13.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 80 -j DNAT --to-destination 10.50.13.11:80
iptables -t nat -A POSTROUTING -s 0.0.0.0/0 -p tcp --dport 80 -j SNAT --to-source 10.50.13.13
/etc/init.d/iptables save
echo 1 > /proc/sys/net/ipv4/ip_forward  #打开路由转发功能
原文地址:https://www.cnblogs.com/Eivll0m/p/4627559.html