FREEBSD做NAT

NAT指Network Address Translate,类似于linux的ip masquerade,都是为了
解决现在ip紧张的问题.它允许你的local network共用一个ip访问internet
当然这只是short-term solution,如果要long-term,我们恐怕还是得等ipv6
不管怎么样,用NAT对于一个负载不太重的localnet来说,还是一个不错的解决
办法.
在FreeBSD下你需要重新编译你的内核,使它支持你的两块网卡,并加入下面两
项options:
options         IPFIREWALL
options         IPDIVERT
编译内核请参考FreeBSD的handbook(/usr/share/doc/handbook/handbook.html)
make install新内核后,编辑/etc/rc.conf,打开gateway_enable和
firewall_enable,并注意把你的ed1添加到network_interfaces,并给它指定ip
和掩码,然后重新启动机器使新内核生效.留心一下启动信息或是进去后用dmesg
看看你的网卡是否找到.这时你ping你的localnet里的机器应该是通的.然后在
/etc/services里面加上一行:

natd    6668/divert
假定你的ed0连接校园网作为globle address,ed1接localnet,那么你需要编辑
你的/etc/rc.local加上以下几行:
ipfw -f flush
ipfw add 1000 divert natd all from any to any via ed0
ipfw add 1100 pass all from any to any
natd -interface ed0
然后执行rc.local或直接运行上面几行命令就可以了,赶快用你的localnet上的
机器试一把能不能上BBS:)
已知NAT支持下列协议:
ICMP,TELNET,FTP,HTTP
这些服务对我们来说已经足够了,如果有什么不支持的,那就只好telnet到你的
NAT上来运行了
 
--

<返回>