Ubuntu 10.10 设置iptables做NAT

系统 Linux
iptables 是与最新的 2.6.x 版本Linux 内核集成的 IP 信息包过滤系统。本文为大家介绍下Ubuntu 10.10 设置iptables做NAT的具体过程。

我们在用Ubuntu下的iptables时,要想做NAT,就教给大家方法:

  eth0连接ADSL Modem,设成DHCP,同时要让ADSL自动启动,所以eth0就不要自动启动了。eth1做内网连接网卡,IP地址是192.168.3.1,将网关设成0.0.0.0,DNS不要设置。因为ADSL拨号成功之后,会自动获取网关和DNS的设置,所以eth1不能设置网关和DNS。

  设置iptables,如下:

 

  1.   # Generated by iptables-save v1.4.4 on Wed Nov 3 22:07:11 2010  
  2.  

 

  *nat

  :PREROUTING ACCEPT [89:5389]

  :OUTPUT ACCEPT [99:6218]

  :POSTROUTING ACCEPT [99:6218]

  -A POSTROUTING -s 192.168.3.0/24 -o ppp0 -j MASQUERADE

  COMMIT

 

  1.   # Completed on Wed Nov 3 22:07:11 2010  
  2.  
  3.   # Generated by iptables-save v1.4.4 on Wed Nov 3 22:07:11 2010  
  4.  

 

  *filter

  :INPUT ACCEPT [2965:1911992]

  :FORWARD ACCEPT [614:192167]

  :OUTPUT ACCEPT [5625:1000183]

  -A INPUT -i lo -j ACCEPT

  -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT

  -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT

  -A INPUT -m state --state ESTABLISHED -j ACCEPT

  -A INPUT -i ppp0 -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -j DROP

  -A OUTPUT -o lo -j ACCEPT

  -A OUTPUT -p tcp -m tcp --sport 22 -j ACCEPT

  -A OUTPUT -p tcp -m tcp --sport 443 -j ACCEPT

  COMMIT

 

  1.   # Completed on Wed Nov 3 22:07:11 2010  
  2.  

 

  以上设置开通了ssh和https两项服务,其他来自ppp0的连接都将被drop。

  以上设置是输入了iptables命令之后,使用iptables-save生成的,保存以上内容为:/etc/iptables-config,然后修改/etc/rc.local,加入:

 

  1.   echo "1" > /proc/sys/net/ipv4/ip_forward  
  2.  
  3.   iptables-restore < /etc/iptables-config  

通过文章的描述和代码的分析,我们知道Ubuntu 10.10 设置iptables做NAT的具体过程。希望本文对大家有帮助!

【编辑推荐】

  1. iptables与natcheck
  2. iptables限制访问某个IP地址
  3. 用iptables限制黑客破解密码
  4. iptables 菜鸟变大虾
  5. iptables 端口转发
  6. iptables nat 技术笔记

 

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

2011-01-12 09:59:28

Ubuntu Serviptables

2011-03-15 16:26:46

iptablesnat

2011-09-02 15:31:00

ubuntu路由器路由

2011-03-21 10:13:22

Ubuntu自动播放

2011-03-16 09:05:34

iptablesnat

2011-03-17 14:09:03

iptables na

2011-03-16 10:59:57

2011-03-17 13:02:07

iptables na

2011-03-15 14:26:23

iptablesNAT

2011-03-15 09:10:47

iptablesNAT

2011-01-10 10:40:19

Ubuntu

2010-08-27 09:09:15

Ubuntu 10.1

2011-03-16 09:05:29

iptablesNAT

2011-03-17 13:55:23

iptablesNAT端口映射

2011-03-16 09:05:32

RedhatiptablesNAT

2010-07-27 13:56:55

Ubuntu TweaUbuntu 10.1

2011-09-07 13:33:51

ubuntuUbuntu Twea

2010-07-16 13:52:30

Ubuntu 10.1

2011-08-23 09:47:20

UbuntuU盘

2011-09-07 09:47:35

UbuntuAndroid
点赞
收藏

51CTO技术栈公众号