双网卡固定ip ,nat

由 saying 在 03-05-2003 19:50 发表:

双网卡固定ip ,nat

我有个固定ip 202.204.210.8,我打算作一个nat

2块网卡,

eth0是内网

ip:192.168.0.1

掩码:255.255.255.0

eth1是外网

ip :202.204.210.8

掩码:255.255.255.128

网关:202.204.210.1

dns:202.204.200.11

我是这么设定的,然后我用

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

但是设置完了,服务器连网都上不去了.

我想问一下,网卡到底如何设定?


由 BTworm 在 03-06-2003 12:28 发表:


首先,应该确保服务器在没做任何NAT的情况下能上网:

1. 编辑/etc/resolv.conf,使之看来如:

nameserver 202.204.200.11

2. 编辑/etc/nsswitch.conf,确认host一行如下:

host: files nisplus dns

如果你不用nisplus,也可以将起删掉

3. 添加缺省网关:

route add default eth1

如果你的eth1设置正确,你应该能ping到202.204.210.8(你自己的eth1),202.204.210.1(网关), 202.204.200.11(DNS服务器),及INTERNET上的任何主机.

然后做NAT,如果你只用那一条命令是不够的. 下面是一简单的防火墙;

iptables -P INPUT -j ACCEPT

iptables -P OUTPUT -j ACCEPT

iptables -P FORWARD -j DROP

iptables -F

iptables -A INPUT -i eth1 -p tcp --dport 0:1023 -j DROP

iptables -A INPUT -i eth1 -p udp --dport 0:1023 -j DROP

iptables -A FORWARD -i eth0 -j ACCEPT

iptables -A FORWARD -i eth1 -m state --state RELATED,ESTABLISHED -j ACCEPT

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

echo 1 > /proc/sys/net/ipv4/ip_forward

因为你有固定IP, 倒数第二行还可以这样:

iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to 202.204.210.8

================================================

你可以将上面的COPY到一个文件,名为tmpwall, 然后如下启动:

. tmpwall

注意: 是".",空格,文件名. 一切正常的话,应该没有任何输出.

下一步, 将现在的设置保存,以便下次机器启动的时候自动加载:

iptables-save > /etc/sysconfig/iptables

chkconfig --level 345 iptables on


由 saying 在 03-06-2003 20:27 发表:


谢谢,按照你的配置,我做好了

但是就是

echo 1 > /proc/sys/net/ipv4/ip_forward

这句话不知道什么意思,能告诉我吗?

为什么有这么多爱帮助别人的人呢?


由 yejr 在 03-07-2003 01:12 发表:


打开转发功能,是?


由 KornLee 在 03-07-2003 01:53 发表:

<p

Published At
Categories with 服务器类
Tagged with
comments powered by Disqus