免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1196 | 回复: 4
打印 上一主题 下一主题

NAT怎么在CentOS4上面不能工作了? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-06-01 02:21 |只看该作者 |倒序浏览
最近刚装了CentOS4,想把以前在Fedora Core 1上面的NAT功能移过来

eth0是外网的网卡
eth1是内网

把dhcpd.conf复制到CentOS4上,已经可以工作了,内网的电脑已经可以取到ip地址了

NAT功能设置也很简单把原来Fedora1上的rc.local文件中的几行复制过来

route add -host 255.255.255.255 dev eth1 >;/dev/null
echo 1 >; /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

重新启动CentOS4,可内网的机器,怎么也ping不出去,很奇怪,相同的设置,在Fedora上怎么就可以工作呢?

iptables 的设置如下

iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
RH-Firewall-1-INPUT  all  --  anywhere             anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
RH-Firewall-1-INPUT  all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain RH-Firewall-1-INPUT (2 references)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     icmp --  anywhere             anywhere            icmp any
ACCEPT     ipv6-crypt--  anywhere             anywhere            
ACCEPT     ipv6-auth--  anywhere             anywhere            
ACCEPT     udp  --  anywhere             224.0.0.251         udp dpt:5353
ACCEPT     udp  --  anywhere             anywhere            udp dpt:ipp
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ftp
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:smtp
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited




iptables -t nat -L
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination      


敬请高手指点一二,多谢多谢!!

论坛徽章:
0
2 [报告]
发表于 2005-06-01 08:13 |只看该作者

NAT怎么在CentOS4上面不能工作了?

首先,你先确定是否 eth0 就是你的 WAN 口
其次,仅仅添加那两句话是不行的,要考虑之前的策略

论坛徽章:
0
3 [报告]
发表于 2005-06-01 08:23 |只看该作者

NAT怎么在CentOS4上面不能工作了?

非常感谢,

eth0确实是WAN口,

我有一点不明白的,是那一句
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
在2.4和2.6内核上会有不同吗?

另外
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
RH-Firewall-1-INPUT  all  --  anywhere             anywhere            

是不是应该说明我已经允许所有的FORWARD ?
我看了
http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO.txt

好像也没有特别指出,想做个伪装还需要什么指令呀?

敬请高手指点一二,

另外,如果想知道netfilter的工作状态,用什么命令呀,

比如,我在内往ping一网址,如果能在linux下看到我的报文被怎么扔掉,就好了

多谢多谢

论坛徽章:
0
4 [报告]
发表于 2005-06-01 08:33 |只看该作者

NAT怎么在CentOS4上面不能工作了?

执行顺序实际是这样的

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
RH-Firewall-1-INPUT  all  --  anywhere             anywhere            

Chain RH-Firewall-1-INPUT (2 references)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     icmp --  anywhere             anywhere            icmp any
ACCEPT     ipv6-crypt--  anywhere             anywhere            
ACCEPT     ipv6-auth--  anywhere             anywhere            
ACCEPT     udp  --  anywhere             224.0.0.251         udp dpt:5353
ACCEPT     udp  --  anywhere             anywhere            udp dpt:ipp
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ssh
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:http
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:ftp
ACCEPT     tcp  --  anywhere             anywhere            state NEW tcp dpt:smtp
REJECT     all  --  anywhere             anywhere            reject-with icmp-host-prohibited

但是为什么不通我就不清楚了
NAT有 2 种方法,一是用-j MASQUERADE,二是用-j SNAT --to x.x.x.x
如果你想看被拦截了,可以用-j LOG,使撞击的包记录到messages.log里(如果你启动了syslog的话)

论坛徽章:
0
5 [报告]
发表于 2005-06-01 08:37 |只看该作者

NAT怎么在CentOS4上面不能工作了?

请教

iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

两句工作会不同吗?有点不懂
第一句不用指定从哪里走?第二句不用指定从哪里来?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP