Ubuntu iptables 内网端口映射

系统 Linux
在使用Ubuntu iptables,我们可以实现Ubuntu内网端口映射,本文将提到他们实施的具体步骤!

使用Ubuntu iptables 有许多地方能进行运作,比如:内网端口映射

  1.系统环境

  内网两台服务器:

  A 172.16.119.128

  B 172.16.119.129

  希望将A机器的80端口映射到B机器的8013端口。

  2.设置步骤

  2.1./etc/sysctl.conf配置文件修改

  删除“# net.ipv4.ip_forward = 1”行前面的“#”。 默认该行被注释掉的。

  2.2.查看现有配置信息

  iptables -L

  如果显示内容如下:

  Chain INPUT (policy ACCEPT)

  target prot opt source destination

  Chain FORWARD (policy ACCEPT)

  target prot opt source destination

  Chain OUTPUT (policy ACCEPT)

  target prot opt source destination

  表示无任何设置,可以继续下一步操作。

  否则执行:

  iptalbes -F

  iptalbes -X

  iptalbes -Z

  2.3.设置端口映射

  分别执行:

  iptables -t nat -A PREROUTING -d 172.16.119.128 -p tcp --dport 80 -j DNAT --to-destination 172.16.119.129:8013

  iptables -t nat -A POSTROUTING -d 172.16.119.129 -p tcp --dport 8013 -j SNAT --to 172.16.119.128

  iptables -A FORWARD -o eth0 -d 172.16.119.129 -p tcp --dport 8013 -j ACCEPT

  iptables -A FORWARD -i eth0 -s 172.16.119.129 -p tcp --sport 8013 -j ACCEPT

  2.4.验证端口映射

  此时,访问http://172.16.119.128/abc.htm,应该能访问到对应129服务器上端口为8013网站的abc.htm页面。

  3.设置开机自动加载iptables的配置文件

  3.1 保存配置

  执行命令:

  # iptables-save > /etc/init.d/iptables.up.rules

  将当前配置保存再iptables.up.rules文件中,文件名可以自己决定。

  3.2 修改网卡配置文件

  在网卡IP配置文件/etc/network/interfaces末行加入(/etc/init.d/iptables.up.rules可改成自己定义的配置文件位置和名称)

  pre-up iptables-restore < /etc/init.d/iptables.up.rules

  3.3 重启服务器验证

  shutdown -r now

通过是正文的三大步介绍,我们清楚的知道了Ubuntu iptables 内网端口映射的组建情况!希望对你们有用!

【编辑推荐】

 

责任编辑:赵鹏 来源: 网络转载
相关推荐

2011-03-16 13:09:10

iptables 端口

2011-03-16 13:29:33

iptables 端口

2011-03-17 13:55:23

iptablesNAT端口映射

2011-03-16 12:55:00

iptables 端口

2009-09-16 08:49:29

linux端口映射linux端口linux

2011-03-17 09:35:35

iptables 映射Linux内核

2019-07-25 15:15:54

端口映射服务器

2010-09-02 14:47:56

2020-11-19 10:35:19

LinuxWindows端口映射

2011-03-17 09:54:02

iptables 映射外网内网

2011-08-25 14:35:04

Nth端口映射ftp服务器

2021-08-17 00:02:11

LinuxWindows服务器

2011-03-17 09:06:58

iptables映射端口

2009-12-02 18:51:11

2009-12-15 16:36:12

路由器端口映射

2009-12-15 16:15:56

2009-12-15 16:09:54

水星MR804端口映射

2013-06-07 17:25:46

路由技术路由器

2010-08-05 10:39:32

路由端口

2009-12-15 15:50:22

路由器端口映射
点赞
收藏

51CTO技术栈公众号