Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1352280
  • 博文数量: 244
  • 博客积分: 10311
  • 博客等级: 上将
  • 技术积分: 3341
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-14 21:50
文章分类

全部博文(244)

文章存档

2013年(6)

2012年(5)

2011年(16)

2010年(11)

2009年(172)

2008年(34)

分类: LINUX

2009-03-13 11:03:44

RHLE5操作系统下IPtables做NAT简单做法

实现:Linux主机做路由,为子网实现共享上网。2个IP,一个公网IP(22.33.44.55),一个内外网关(192.168.0.254)。

首先打开路由转发,并且为了保证开机重启后生效。如下操作:

1:修改/etc/sycctl.conf,打开路由转发。
[root@kook ~]# vi /etc/sysctl.conf
net.ipv4.ip_forward = 1

2:立即生效
[root@kook ~]# sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
kernel.sysrq = 0
kernel.core_uses_pid = 1
net.ipv4.tcp_syncookies = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
kernel.shmmax = 4294967295
kernel.shmall = 268435456

添加iptables的NAT,同样保证开机路由生效。

1:添加iptable的NAT
[root@kook ~]# iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o eth0 -j MASQUERADE

2:修改默认iptables,保障重启开机后仍然生效。
[root@kook ~]# iptables-save > /etc/sysconfig/iptables

3:让iptables开机启动
[root@kook ~]# chkconfig iptables on
[root@kook ~]# chkconfig --list iptables
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off

在子网下测试,是否可以上网。完成。
阅读(716) | 评论(0) | 转发(0) |
0

上一篇:iptables的移植

下一篇:iptables学习笔记

给主人留下些什么吧!~~