1.拓撲圖:
<a href="http://blog.51cto.com/attachment/201207/122410488.jpg" target="_blank"></a>
2.接口配置:
①R1、R2:
int f1/0
switchport mode trunk
int f1/1
switchport mode access
switchport access
switchport access vlan 10
int f1/15
switchport access vlan 30
②R3、R4:
switchport access vlan 20
2.HSRP配置:
①R1:
int vlan 10
ip add 10.1.1.1 255.255.255.248
standby 10 ip 10.1.1.5
standby 10 priority 20
standby 10 preempt
standby 10 track fastEthernet 1/1 15
standby 10 authentication md5 key-string cisco
int vlan 30
ip add 192.168.1.1 255.255.255.0
standby 30 ip 192.168.1.254
standby 30 priority 20
standby 30 preempt
standby 30 track fastEthernet 1/1 15
standby 30 authentication md5 key-string cisco
②R2:
ip add 10.1.1.2 255.255.255.248
standby 10 priority 10
ip add 192.168.1.2 255.255.255.0
standby 30 priority 10
③R3:
int vlan 20
ip add 10.1.1.3 255.255.255.248
standby 20 ip 10.1.1.6
standby 20 priority 20
standby 20 preempt
standby 20 track fastEthernet 1/1 15
standby 20 authentication md5 key-string ciscocisco
ip add 192.168.2.1 255.255.255.0
standby 30 ip 192.168.2.254
④R4:
ip add 10.1.1.4 255.255.255.248
standby 20 priority 10
ip add 192.168.2.2 255.255.255.0
⑤驗證HSRP狀态:
R1#show standby
Vlan10 - Group 10
State is Active
2 state changes, last state change 00:21:00
Virtual IP address is 10.1.1.5
Active virtual MAC address is 0000.0c07.ac0a
Local virtual MAC address is 0000.0c07.ac0a (v1 default)
Hello time 3 sec, hold time 10 sec
Next hello sent in 2.592 secs
Authentication MD5, key-string "cisco"
Preemption enabled
Active router is local
Standby router is 10.1.1.2, priority 10 (expires in 8.728 sec)
Priority 20 (configured 20)
IP redundancy name is "hsrp-Vl10-10" (default)
Vlan30 - Group 30
2 state changes, last state change 00:10:58
Virtual IP address is 192.168.1.254
Active virtual MAC address is 0000.0c07.ac1e
Local virtual MAC address is 0000.0c07.ac1e (v1 default)
Next hello sent in 1.060 secs
Standby router is 192.168.1.2, priority 10 (expires in 7.740 sec)
Track interface FastEthernet1/1 state Up decrement 10
IP redundancy name is "hsrp-Vl30-30" (default)
R1#
R2#show standby
State is Standby
1 state change, last state change 00:17:14
Next hello sent in 1.044 secs
Active router is 10.1.1.1, priority 20 (expires in 9.924 sec)
Standby router is local
Priority 10 (configured 10)
1 state change, last state change 00:11:01
Next hello sent in 1.992 secs
Active router is 192.168.1.1, priority 20 (expires in 9.156 sec)
R2#
R3#show standby
Vlan20 - Group 20
2 state changes, last state change 00:06:54
Virtual IP address is 10.1.1.6
Active virtual MAC address is 0000.0c07.ac14
Local virtual MAC address is 0000.0c07.ac14 (v1 default)
Next hello sent in 2.064 secs
Authentication MD5, key-string "ciscocisco"
Standby router is 10.1.1.4, priority 10 (expires in 7.072 sec)
IP redundancy name is "hsrp-Vl20-20" (default)
Virtual IP address is 192.168.2.254
Next hello sent in 2.372 secs
Standby router is 192.168.2.2, priority 10 (expires in 8.684 sec)
R3#
R4#show standby
1 state change, last state change 00:06:22
Next hello sent in 1.740 secs
Active router is 10.1.1.3, priority 20 (expires in 7.792 sec)
1 state change, last state change 00:06:21
Next hello sent in 2.084 secs
Active router is 192.168.2.1, priority 20 (expires in 9.268 sec)
R4#
3.靜态路由配置:
ip route 192.168.2.0 255.255.255.0 10.1.1.6
ip route 192.168.1.0 255.255.255.0 10.1.1.5
③測試
R1#ping 192.168.2.254 source 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.2.254, timeout is 2 seconds:
Packet sent with a source address of 192.168.1.1
.!!!!
Success rate is 80 percent (4/5), round-trip min/avg/max = 20/32/44 ms
R1#traceroute 192.168.2.254 source 192.168.1.1
Tracing the route to 192.168.2.254
1 10.1.1.3 56 msec * 40 msec
4.LINUX主機雙網卡bonding配置:
①LINUX1:
A.編輯虛拟網卡band0的配置檔案ifcfg-bond0,加入以下内容:
[root@Linux1~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=bond0
ONBOOT=yes
BOOTPROTO=none
IPADDR=192.168.1.8
BROADCAST=192.168.1.255
NETMASK=255.255.255.0
NETWORK=192.168.1.0
GATEWAY=192.168.1.254
USERCTL=no
B、編輯eth0和eth1網卡的配置檔案
[root@Linux1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0c:29:e4:65:78
TYPE=Ethernet
MASTER=bond0
SLAVE=yes
PEERDNS=yes
IPV6INIT=no
[root@Linux1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
HWADDR=00:0c:29:e4:65:82
C、修改/etc/modprobe.conf 檔案,加入以下内容:
alias bond0 bonding
options bond0 miimon=100 mode=1
注:
(1)、miimon 是鍊路監測的時間間隔機關是毫秒,miimon=100的意思就是,每100毫秒檢測網卡和交換機之間是否連通,如不通則使用另外的鍊路。
(2)、mode=0 表示負載均衡方式,兩塊網卡都工作,需要交換機作支援。
mode=1 表示備援方式,網卡隻有一個工作,一個出問題啟用另外的。
mode=6 表示負載均衡方式,兩塊網卡都工作,不需要交換機作支援。
D、重新開機網絡:
# service network restart
E、檢視bond0的工作狀态:
[root@Linux1~]# more /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v2.6.3-rh (June 8, 2005)
Bonding Mode: fault-tolerance (active-backup)
Primary Slave: None
Currently Active Slave: eth0
MII Status: up
MII Polling Interval (ms): 100
Up Delay (ms): 0
Down Delay (ms): 0
Slave Interface: eth0
Link Failure Count: 0
Permanent HW addr: 00:0c:29:e4:65:78
Slave Interface: eth1
Permanent HW addr: 00:0c:29:e4:65:82
F、檢視綁定後的結果:
[root@Linux1~]# ifconfig -a
bond0 Link encap:Ethernet HWaddr 00:0C:29:E4:65:78
inet addr:192.168.1.8 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee4:6578/64 Scope:Link
UP BROADCAST RUNNING MASTER MULTICAST MTU:1500 Metric:1
RX packets:874 errors:0 dropped:0 overruns:0 frame:0
TX packets:685 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:74567 (72.8 KiB) TX bytes:62797 (61.3 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:E4:65:78
UP BROADCAST RUNNING SLAVE MULTICAST MTU:1500 Metric:1
RX packets:805 errors:0 dropped:0 overruns:0 frame:0
TX packets:694 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:67571 (65.9 KiB) TX bytes:64199 (62.6 KiB)
Interrupt:185 Base address:0x2024
eth1 Link encap:Ethernet HWaddr 00:0C:29:E4:65:78
RX packets:74 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:7296 (7.1 KiB) TX bytes:0 (0.0 b)
Interrupt:177 Base address:0x20a4
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:760 (760.0 b) TX bytes:760 (760.0 b)
sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
[root@AMS ~]#
②LINUX2
[root@Linux2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-bond0
IPADDR=192.168.2.8
BROADCAST=192.168.2.255
GATEWAY=192.168.2.254
NETWORK=192.168.2.0
[root@Linux2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
HWADDR=00:0c:29:08:48:63
[root@Linux2 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
HWADDR=00:0c:29:08:48:6d
[root@Linux2 ~]# more /proc/net/bonding/bond0
Ethernet Channel Bonding Driver: v3.4.0 (October 7, 2008)
Permanent HW addr: 00:0c:29:08:48:63
Permanent HW addr: 00:0c:29:08:48:6d
[root@Linux2 ~]# ifconfig -a
bond0 Link encap:Ethernet HWaddr 00:0C:29:08:48:63
inet addr:192.168.2.8 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe08:4863/64 Scope:Link
RX packets:233 errors:0 dropped:0 overruns:0 frame:0
TX packets:217 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:18827 (18.3 KiB) TX bytes:25194 (24.6 KiB)
eth0 Link encap:Ethernet HWaddr 00:0C:29:08:48:63
RX packets:165 errors:0 dropped:0 overruns:0 frame:0
TX packets:226 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:14171 (13.8 KiB) TX bytes:26596 (25.9 KiB)
Interrupt:75 Base address:0x2000
eth1 Link encap:Ethernet HWaddr 00:0C:29:08:48:63
RX packets:73 errors:0 dropped:0 overruns:0 frame:0
RX bytes:4956 (4.8 KiB) TX bytes:0 (0.0 b)
Interrupt:59 Base address:0x2080
RX packets:104 errors:0 dropped:0 overruns:0 frame:0
TX packets:104 errors:0 dropped:0 overruns:0 carrier:0
RX bytes:13740 (13.4 KiB) TX bytes:13740 (13.4 KiB)
6.測試配置:
①正常狀态
[root@Linux1 ~]# ping 192.168.2.8
PING 192.168.2.8 (192.168.2.8) 56(84) bytes of data.
64 bytes from 192.168.2.8: icmp_seq=1 ttl=62 time=55.1 ms
64 bytes from 192.168.2.8: icmp_seq=2 ttl=62 time=43.0 ms
--- 192.168.2.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1599ms
rtt min/avg/max/mdev = 43.047/49.103/55.160/6.060 ms
[root@Linux1 ~]# traceroute 192.168.2.8
traceroute to 192.168.2.8 (192.168.2.8), 30 hops max, 40 byte packets
1 (192.168.1.1) 176.939 ms 184.770 ms 194.904 ms
2 (10.1.1.3) 215.089 ms 226.090 ms 235.590 ms
3 (192.168.2.8) 246.020 ms 256.903 ms 270.429 ms
[root@Linux2 ~]# ping 192.168.1.8
PING 192.168.1.8 (192.168.1.8) 56(84) bytes of data.
64 bytes from 192.168.1.8: icmp_seq=0 ttl=62 time=41.0 ms
--- 192.168.1.8 ping statistics ---
2 packets transmitted, 1 received, 50% packet loss, time 1002ms
rtt min/avg/max/mdev = 41.081/41.081/41.081/0.000 ms, pipe 2
[root@Linux2 ~]# traceroute 192.168.1.8
traceroute to 192.168.1.8 (192.168.1.8), 30 hops max, 38 byte packets
1 192.168.2.1 (192.168.2.1) 17.759 ms 27.659 ms 11.916 ms
2 10.1.1.1 (10.1.1.1) 84.242 ms 46.798 ms 41.362 ms
3 192.168.1.8 (192.168.1.8) 65.179 ms 45.004 ms 46.726 ms
②删除R1和R3互聯的線路,并且關閉接口,從日志中可以看出交換機主備發生了切換:
R1(config-if)#
*Mar 1 02:36:22.991: %HSRP-5-STATECHANGE: Vlan10 Grp 10 state Active -> Speak
R1(config-if)#int vlan 20
R1(config-if)#t
*Mar 1 02:36:32.987: %HSRP-5-STATECHANGE: Vlan10 Grp 10 state Speak -> Standby
*Mar 1 02:37:34.891: %HSRP-5-STATECHANGE: Vlan30 Grp 30 state Active -> Speak
*Mar 1 02:37:44.891: %HSRP-5-STATECHANGE: Vlan30 Grp 30 state Speak -> Standby
*Mar 1 00:29:40.651: %HSRP-5-STATECHANGE: Vlan10 Grp 10 state Speak -> Standby
R2(config-if)#
*Mar 1 00:35:53.687: %HSRP-5-STATECHANGE: Vlan30 Grp 30 state Speak -> Standby
*Mar 1 02:33:53.935: %HSRP-5-STATECHANGE: Vlan10 Grp 10 state Standby -> Active
*Mar 1 02:35:05.835: %HSRP-5-STATECHANGE: Vlan30 Grp 30 state Standby -> Active
R3(config-if)#
*Mar 1 02:36:00.499: %HSRP-5-STATECHANGE: Vlan20 Grp 20 state Active -> Speak
R3(config-if)#int vlan 30
R3(config-if)#st
R3(config-if)#standby
*Mar 1 02:36:10.499: %HSRP-5-STATECHANGE: Vlan20 Grp 20 state Speak -> Standby
R3(config-if)#standby 30 t
R3(config-if)#standby 30 tr
R3(config-if)#standby 30 track f
R3(config-if)#standby 30 track fastEthernet 1/1 15
*Mar 1 02:36:20.255: %HSRP-5-STATECHANGE: Vlan30 Grp 30 state Active -> Speak
*Mar 1 02:36:30.255: %HSRP-5-STATECHANGE: Vlan30 Grp 30 state Speak -> Standby
*Mar 1 02:18:42.407: %HSRP-5-STATECHANGE: Vlan20 Grp 20 state Standby -> Active
*Mar 1 02:19:20.379: %HSRP-5-STATECHANGE: Vlan20 Grp 20 state Active -> Speak
*Mar 1 02:19:30.375: %HSRP-5-STATECHANGE: Vlan20 Grp 20 state Speak -> Standby
R4#
*Mar 1 02:34:16.159: %HSRP-5-STATECHANGE: Vlan20 Grp 20 state Standby -> Active
*Mar 1 02:34:35.899: %HSRP-5-STATECHANGE: Vlan30 Grp 30 state Standby -> Active
③再次traceroute,确認路徑也發生了變化:
1 (192.168.1.2) 196.404 ms 204.818 ms 213.794 ms
2 (10.1.1.4) 228.587 ms 272.285 ms 278.259 ms
3 (192.168.2.1) 251.404 ms (192.168.2.8) 305.621 ms 328.609 ms
[root@Linux1 ~]#
[root@Linux2 ~]# traceroute 192.168.1.8
1 192.168.2.2 (192.168.2.2) 64.399 ms 51.977 ms 10.650 ms
2 10.1.1.2 (10.1.1.2) 68.322 ms 42.056 ms 64.082 ms
3 192.168.1.1 (192.168.1.1) 69.768 ms 192.168.1.8 (192.168.1.8) 72.562 ms 61.597 ms
[root@Linux2 ~]#
本文轉自 碧雲天 51CTO部落格,原文連結:http://blog.51cto.com/333234/938325,如需轉載請自行聯系原作者