[ 永远的UNIX::UNIX技术资料的宝库 ]

首页 > 应用专题 > Proxy > 正文
 

redhat linux9.0下nat代理的实现!

来源:转载 (2006-06-20 15:04:49)

在双网卡机子上,
一张网卡(eth0)配置61.185.11.101的ip
另一张网卡(eth1)配置配置192.168.16.1这个ip.
虚拟2张网卡(eth1:1和eth1:2)ip分别是192.168.18.1和192.168.19.1
(配置文件在/etc/sysconfig/network-scripts/里。默认第一张网卡的配置文件是ifcfg-eth0。第2张是ifcfg-eth1
这2个文件都是有网卡就可以自动生成的。
最重要的是把虚拟网卡的配置文件写出来。因为linux系统把所有设备都是当作文件的。
所以就在/etc/sysconfig/network-scripts/这个目录里用vi eth1:1,按照eth1的格式写一个eth1:1,只是ip不一样而已。再写个eth1:2
写完以后,都要重起一次网卡才能生效。就用ifdown,和ifup命令。如果关闭网卡eth1就在命令行里输入ifdown eth1
用route这个命令查看路由表。汇东配好了以后的是
[root@router root]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
219.221.176.0 * 255.255.255.0 U 0 0 0 eth0
192.168.19.0 * 255.255.255.0 U 0 0 0 eth1
192.168.18.0 * 255.255.255.0 U 0 0 0 eth1
192.168.16.0 * 255.255.255.0 U 0 0 0 eth1
169.254.0.0 * 255.255.0.0 U 0 0 0 eth1
127.0.0.0 * 255.0.0.0 U 0 0 0 loy
default 219.221.176.1 0.0.0.0 UG 0 0 0 eth0
[root@router root]#
这个是正确的。
这里最关键的是default 219.221.176.1 0.0.0.0 UG 0 0 0 eth0这条路由如果没有的话就自己设置.
route add default gw 61.185.11.97(网关)
这个样子还没有启用转发功能,路由也没有用,需要手动打开。 在命令模式下输入
Echo 1 > /proc/sys/net/ipv4/ip_forward (为了不每次开机都要输入这个就写到启动脚本里。让它一开机自动启动。就把这条命令加到/etc/rc.d/rc.local这个文件里。
好了。这样4个网段就连上了
然后就是配置NAT了。。
NAT就是作个ip伪装。汇动的配置是
[root@router root]# cat /etc/rc.d/rc.locals
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don´t want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
#
ifconfig eth1:1 192.168.18.1 up #开机自动虚拟eth1:1这个网卡
ifconfig eth1:2 192.168.19.1 up #开机自动虚拟eth1:2这个网卡


#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don´ t
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
echo 1 > /proc/sys/net/ipv4/ip_forward
modprobe ip_tables
modprobe ip_nat_ftp
modprobe ip_nat_irc
modprobe ip_conntrack
modprobe ip_conntrack_ftp
modprobe ip_conntrack_irc
/sbin/iptables -F
/sbin/iptables -X
/sbin/iptables -Z
/sbin/iptables -F -t nat
/sbin/iptables -X -t nat
/sbin/iptables -Z -t nat
/sbin/iptables -P INPUT ACCEPT
/sbin/iptables -P OUTPUT ACCEPT
/sbin/iptables -P FORWARD ACCEPT
/sbin/iptables -t nat -P PREROUTING ACCEPT
/sbin/iptables -t nat -P POSTROUTING ACCEPT
/sbin/iptables -t nat -P OUTPUT ACCEPT
#jiazaimokuai
modprobe ip_tables 2> /dev/null
modprobe ip_nat_ftp 2> /dev/null
modprobe ip_nat_irc 2> /dev/null
modprobe ip_conntrack 2> /dev/null
modprobe ip_conntrack_ftp 2> /dev/null
modprobe ip_conntrack_irc 2> /dev/null
#ip weizhuang
/sbin/iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -j MASQUERADE

(http://www.fanqiang.com)



 
 相关文章
如何使用NAT? 2001-04-15 19:56:34
Linux 2.4 NAT HOWTO 2001-05-02 10:05:54
RedHat 7.0 安装 NAT 作法简介 2001-06-05 16:10:00
路由器的NAT的原理及配置 2006-06-07 11:18:07
 

★  感谢所有的作者为我们学习技术知识提供了一条捷径  ★
www.fanqiang.com