2008年9月11日星期四

Linux+Cisco3550交换机配置指南

Linux+Cisco3550交换机,实现多个子网互相访问,并且每个子网对应一个外网IP地址共享上网。

一、软硬件设施
Linux服务器(系统为Centos5.2, P4.17G以上CPU,256M以上内存,两块网卡)
Cisco3550三层交换机(本实验为24口的标准交换机)
服务器的内网卡和交换机Vlan2端口进行连接,设置内网卡地址为220.100.1.1 255.255.255.0。
服务器的外网卡地址为 210.45.79.241、210.45.79.242、210.45.79.243 绑定这3个IP地址。

二、交换机配置
第一步:创建VLAN:
Switch>en
Switch#
Vlan Database
Switch(Vlan)>Vlan 2 Name Nat
Switch(Vlan)>Vlan 3 Name work01
Switch(Vlan)>Vlan 4 Name work02
Switch(Vlan)>Vlan 5 Name work03

第二步:设置VLAN IP地址:
Switch#Config T
Switch(Config)>Int Vlan 2
Switch(Config-vlan)Ip Address 220.100.1.254 255.255.255.0
Switch(Config-vlan)No Shut
Switch(Config-vlan)>Int Vlan 3
Switch(Config-vlan)Ip Address 220.102.1.1 255.255.255.0
Switch(Config-vlan)No Shut
Switch(Config-vlan)>Int Vlan 4
Switch(Config-vlan)Ip Address 220.102.2.1 255.255.255.0
Switch(Config-vlan)No Shut
Switch(Config-vlan)>Int Vlan 5
Switch(Config-vlan)Ip Address 192.168.0.254 255.255.255.0
Switch(Config-vlan)No Shut
Switch(Config-vlan)Exit

/*注意:由于此时没有将端口分配置到VLAN2,3,4,5所以各VLAN会DOWN掉,待将端口分配到各VLAN后,VLAN会起来*/

第三步:设置端口全局参数
Switch(Config)Interface Range Fa 0/1 - 24
Switch(Config-if-range)Switchport Mode Access
Switch(Config-if-range)Spanning-tree Portfast

第四步:将端口添加到VLAN2,3中
/*将端口1添加到VLAN 2*/
Switch(Config)Interface Range Fa 0/1
Switch(Config-if-range)Switchport Access Vlan 2
/*将端口2-10添加到VLAN 3*/
Switch(Config)Interface Range Fa 0/2 - 10
Switch(Config-if-range)Switchport Access Vlan 3
/*将端口11-16添加到VLAN 4*/
Switch(Config)Interface Range Fa 0/11 - 16
Switch(Config-if-range)Switchport Access Vlan 4
/*将端口17-24添加到VLAN 5*/
Switch(Config)Interface Range Fa 0/17 - 24
Switch(Config-if-range)Switchport Access Vlan 5

配置3550作为DHCP服务器
/*VLAN 3可用地址池和相应参数的配置。有几个VLAN要设几个地址池*/
Switch(Config)Ip Dhcp Pool Work01
/*设置可分配的子网*/
Switch(Config-pool)Network 220.102.1.0 255.255.255.0
/*设置DNS服务器*/
Switch(Config-pool)Dns-server 202.38.64.1
/*设置该子网的网关*/
Switch(Config-pool)Default-router 220.102.1.1
/*配置VLAN 4所用的地址池和相应参数*/
Switch(Config)Ip Dhcp Pool Work02
Switch(Config-pool)Network 220.102.2.0 255.255.255.0
Switch(Config-pool)Dns-server 202.38.64.1
Switch(Config-pool)Default-router 220.102.2.1
/*配置VLAN 5所用的地址池和相应参数*/
Switch(Config)Ip Dhcp Pool Work03
Switch(Config-pool)Network 192.168.0.0 255.255.255.0
Switch(Config-pool)Dns-server 202.38.64.1
Switch(Config-pool)Default-router 192.168.0.254

第五步:设置DHCP保留不分配的地址
ip dhcp excluded-address 220.102.1.254
ip dhcp excluded-address 220.102.1.1 220.102.1.10
ip dhcp excluded-address 220.102.2.1 220.102.2.2
ip dhcp excluded-address 192.168.0.1 192.168.0.10
ip dhcp excluded-address 192.168.0.254

第六步:启用路由
/*路由启用后,各VLAN间主机可互相访问*/
Switch(Config)Ip Routing

第七步:NAT
让Vlan3,Vlan4,Vlan5段通过Linux服务器路由上网。
Ip router 0.0.0.0 0.0.0.0 220.100.1.1

三、Linux服务器配置
echo 1 > /proc/sys/net/ipv4/ip_forward

/sbin/iptables -F/sbin/iptables -F -t nat/sbin/iptables -P INPUT ACCEPT/sbin/iptables -P OUTPUT ACCEPT

sudo /sbin/iptables -t nat -A POSTROUTING -o eth0 -s 220.102.1.0/24 -j SNAT --to 210.45.79.241

sudo /sbin/iptables -t nat -A POSTROUTING -o eth0 -s 220.102.2.0/24 -j SNAT --to 210.45.79.242

sudo /sbin/iptables -t nat -A POSTROUTING -o eth0 -s 192.168.0.0/24 -j SNAT --to 210.45.79.243

/sbin/modprobe ip_nat_ftp/sbin/iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

/sbin/iptables -A FORWARD -p tcp --dport 80 -j ACCEPT

/sbin/iptables -A FORWARD -p tcp --dport 21 -j ACCEPT

sudo /sbin/iptables -A FORWARD -p udp --dport 53 -j ACCEPT

/sbin/route add -net 220.102.1.0/24 dev eth1
/sbin/route add -net 220.102.2.0/24 dev eth1
/sbin/route add -net 192.168.0.0/24 dev eth1

可把以上代码放入 /etc/rc.local 里面,每次启动系统可自动执行。

以上参数设置后,所有子网段之间均可以互相访问,每个网段都可自动获取相应的IP地址,并通过指定的外网IP地址进行互联网的访问。

端口2-端口10:
地址段:220.102.1.0 255.255.255.0
网关: 220.102.1.1
DNS: 202.38.64.1
指定的外网IP:210.45.79.241

端口11-端口16:
地址段:220.102.2.0 255.255.255.0
网关: 220.102.2.1
DNS: 202.38.64.1
指定的外网IP:210.45.79.242

端口17-端口24:
地址段:192.168.0.0 255.255.255.0
网关: 192.168.0.254
DNS: 202.38.64.1
指定的外网IP:210.45.79.243

作者:yearshu

没有评论: