31 · Exploring Layer 3 Redundancy探索第 3 層備援

Understanding HSRP認識 HSRP

HSRP is an FHRP that facilitates transparent failover of the first-hop IP device (default gateway). When you use HSRP, you configure the host with the HSRP virtual IP address as its default gateway, instead of using the IP address of the router.

HSRP 是一種 FHRP,可讓第一跳 IP 裝置(預設閘道)達成透明容錯移轉。使用 HSRP 時,你會將主機的預設閘道設定為 HSRP 虛擬 IP 位址,而不是使用路由器本身的 IP 位址。

HSRP Overview

HSRP 概觀

HSRP defines a standby group of routers, while one router is designated as the active router, as depicted in this figure.

HSRP 定義了一個待命群組,其中一台路由器會被指定為作用中路由器,如下圖所示。

HSRP provides gateway redundancy by sharing IP and MAC addresses between redundant gateways. The protocol consists of virtual IP and MAC addresses that the two routers that belong to the same HSRP group share between each other.

HSRP 透過在備援閘道之間共用 IP 位址與 MAC 位址來提供閘道備援。該協定包含虛擬 IP 位址與虛擬 MAC 位址,由屬於同一個 HSRP 群組的兩台路由器彼此共用。

Hosts on the IP subnet that are protected by HSRP have their default gateway configured with the HSRP group virtual IP address.

受 HSRP 保護的 IP 子網路上的主機,其預設閘道會設定為 HSRP 群組的虛擬 IP 位址。

When IPv4 hosts use ARP to resolve the MAC address of the default gateway IPv4 address, the active HSRP router responds with the shared virtual MAC address. The packets that are received on the virtual IPv4 address are forwarded to the active router.

當 IPv4 主機使用 ARP 解析預設閘道 IPv4 位址的 MAC 位址時,作用中的 HSRP 路由器會以共用的虛擬 MAC 位址回應。傳送到虛擬 IPv4 位址的封包,會被轉送到作用中的路由器。

The HSRP active and the standby router perform the following functions:

HSRP 的作用中路由器與待命路由器執行以下功能:

  • Active router:作用中路由器:
    • Responds to default gateway ARP requests with the virtual router MAC address.以虛擬路由器 MAC 位址回應預設閘道的 ARP 請求。
    • Assumes active forwarding of packets for the virtual router.負責作用中轉送虛擬路由器的封包。
    • Sends hello messages between the active and standby routers.在作用中路由器與待命路由器之間傳送 hello 訊息。
    • Knows the virtual router IPv4 address.知道虛擬路由器的 IPv4 位址。
  • Standby router:待命路由器:
    • Sends hello messages.傳送 hello 訊息。
    • Listens for periodic hello messages.監聽定期的 hello 訊息。
    • Assumes active forwarding of packets if it does not hear from active router.若未收到作用中路由器的訊息,便接手負責轉送封包。
    • Sends Gratuitous ARP message when standby becomes active.待命路由器轉為作用中時,會傳送免費 ARP(Gratuitous ARP)訊息。

The standby router sends a Gratuitous ARP (GARP) when it becomes active. This is so all the access switches in the Layer 2 domain must send the traffic to the new active router. To do so, the switches must update their MAC address table entry for the HSRP Virtual Mac Address with the correct interface to reach the new HSRP active router.

待命路由器轉為作用中時會傳送免費 ARP(GARP),目的是讓第 2 層網域中所有的存取交換器都能將流量傳送到新的作用中路由器。為此,這些交換器必須更新其 MAC 位址表中 HSRP 虛擬 MAC 位址的項目,使其指向可到達新 HSRP 作用中路由器的正確介面。

HSRP routers send hello messages that reach all HSRP routers. The active router sources hello packets from its configured IPv4 address and the shared virtual MAC address. The standby router sources hellos from its configured IPv4 address and it is burned-in MAC address (BIA). Hence, the HSRP routers can identify who is the active and who is the standby router.

HSRP 路由器會傳送 hello 訊息,讓所有 HSRP 路由器都能收到。作用中路由器所傳送的 hello 封包,來源為其自身設定的 IPv4 位址與共用的虛擬 MAC 位址。待命路由器所傳送的 hello 封包,來源則為其自身設定的 IPv4 位址與其燒錄 MAC 位址(BIA)。因此,HSRP 路由器能藉此辨識誰是作用中路由器、誰是待命路由器。

The following table summarizes the HSRP terminology:

下表整理了 HSRP 的相關術語:

HSRP Terminology

HSRP 術語

Term
術語
Definition
定義
Active router
作用中路由器
The router that is currently forwarding packets for the virtual router
目前負責轉送虛擬路由器封包的路由器
Standby router
待命路由器
The primary backup router
主要的備援路由器
Standby group
待命群組
The set of routers participating in HSRP that jointly emulate a virtual router
參與 HSRP、共同模擬出一個虛擬路由器的一組路由器

The function of the HSRP standby router is to monitor the operational status of the HSRP group and to quickly assume the packet-forwarding responsibility if the active router becomes inoperable. When the primary HSRP router comes back online, it will not regain the active role by default. To transfer the active role to the primary router, you have to configure pre-emption.

HSRP 待命路由器的功能,是監控 HSRP 群組的運作狀態,並在作用中路由器無法運作時,迅速接手負責轉送封包。當主要的 HSRP 路由器恢復連線後,預設不會自動重新取得作用中角色。若要將作用中角色轉移回主要路由器,你必須設定搶占(pre-emption)。

The standby preempt command enables the HSRP router with the highest priority to immediately become the active router. Priority is determined first by the configured priority value and then by the IPv4 address. In each case, a higher value is of greater priority. Pre-emption is recommended because you want your network to have deterministic behavior.

standby preempt 指令可讓優先權最高的 HSRP 路由器立即成為作用中路由器。優先權首先由所設定的優先權數值決定,其次才依 IPv4 位址判定;不論哪種情況,數值愈高代表優先權愈高。建議啟用搶占功能,因為你會希望網路行為具有確定性。

HSRP for IPv4 has two versions: Version 1 and Version 2. The default HSRP version is 1. Because the two versions are not compatible, you must use the same version on your HSRP enabled routers.

IPv4 版的 HSRP 有兩個版本:第 1 版與第 2 版。預設的 HSRP 版本是第 1 版。由於這兩個版本互不相容,你必須在所有啟用 HSRP 的路由器上使用相同版本。

The shared virtual MAC address is generated by combining a specific MAC address range and the HSRP group number. HSRP Version 1 uses a MAC address in the form 0000.0C07.ACXX and HSRP Version 2 use a MAC address in the form 0000.0C9F.FXXX, where XX or XXX stand for the group number. For example, the virtual MAC address for an HSRP Version 2 virtual router in group 10 would be 0000.0C9F.F00A. The A in 00A is the hexadecimal value for 10.

共用的虛擬 MAC 位址是由特定的 MAC 位址範圍與 HSRP 群組編號組合而成。HSRP 第 1 版使用格式為 0000.0C07.ACXX 的 MAC 位址,HSRP 第 2 版則使用格式為 0000.0C9F.FXXX 的 MAC 位址,其中 XX 或 XXX 代表群組編號。舉例來說,群組 10 的 HSRP 第 2 版虛擬路由器的虛擬 MAC 位址會是 0000.0C9F.F00A,其中 00A 中的 A 是 10 的十六進位值。

In addition, routers with HSRP Version 1 send hello packets to the multicast address of 224.0.0.2 (reserved multicast address used to communicate to all routers) on UDP port 1985, while HSRP Version 2 uses the 224.0.0.102 multicast address on UDP port 1985.

此外,執行 HSRP 第 1 版的路由器會在 UDP 連接埠 1985 上,將 hello 封包傳送到群播位址 224.0.0.2(用於與所有路由器通訊的保留群播位址),而 HSRP 第 2 版則使用群播位址 224.0.0.102,同樣使用 UDP 連接埠 1985。

Interactive content from the online course (not available offline)線上課程的互動內容(離線版未收錄)

HSRP Advanced Features

HSRP 進階功能

Besides the default behavior, you can configure some other HSRP features to increase your network availability and performance:

除了預設行為外,你還可以設定其他 HSRP 功能,以提升網路可用性與效能:

  • Load balancing: Routers can simultaneously provide redundant backup and perform load sharing across various subnets and VLANs.負載平衡:路由器可以同時提供備援保護,並在不同子網路與 VLAN 之間執行負載分擔。
  • Interface tracking:When a tracked interface becomes unavailable, the HSRP tracking feature ensures that a router with the unavailable interface will relinquish the active router role.介面追蹤:當被追蹤的介面變成無法使用時,HSRP 追蹤功能可確保該介面所在的路由器放棄作用中路由器的角色。

The following figure illustrates a topology with multiple VLANs that can benefit from the HSRP load-balancing feature.

下圖說明了一個具有多個 VLAN 的拓樸,可從 HSRP 負載平衡功能中受益。

The two Layer 3 switches have HSRP enabled in two separate VLANs. For each VLAN, HSRP allocates a standby group, a virtual IPv4 address, and a virtual MAC address. The active router for each HSRP group is on a different Layer 3 switch. Thus, the hosts in different VLANs use a different Layer 3 switch, which enables load sharing across various subnets and VLANs.

這兩台第 3 層交換器在兩個不同的 VLAN 中都啟用了 HSRP。針對每個 VLAN,HSRP 會配置一個待命群組、一個虛擬 IPv4 位址與一個虛擬 MAC 位址。每個 HSRP 群組的作用中路由器分別位於不同的第 3 層交換器上。因此,不同 VLAN 中的主機會使用不同的第 3 層交換器,藉此在不同子網路與 VLAN 之間達成負載分擔。

The active router in HSRP is elected based on the HSRP priority, which is 100 by default and is configurable per HSRP group. In the case of an equal priority, the router with the highest IPv4 address for the respective group is elected as an active router.

HSRP 中的作用中路由器是根據 HSRP 優先權來選出的,預設值為 100,且可依 HSRP 群組個別設定。若優先權相同,則會選出該群組中 IPv4 位址最高的路由器作為作用中路由器。

The HSRP interface tracking feature decreases the priority of the router by a configured value, when a tracked interface becomes unavailable. In this situation, the priority of a standby group router may become higher and it will take the role of active router. Therefore, a router with the unavailable interface will relinquish the active router role.

當被追蹤的介面變成無法使用時,HSRP 介面追蹤功能會將該路由器的優先權降低一個設定的數值。在這種情況下,待命群組中另一台路由器的優先權可能會變得更高,進而取得作用中路由器的角色。因此,介面無法使用的路由器便會放棄作用中路由器的角色。

The following topology has two redundant routers that connect a host to the internet. The routers have HSRP enabled on the interfaces that are facing the host network (interface fa0/0 on each router.)

下列拓樸中有兩台備援路由器,負責將主機連接到網際網路。這兩台路由器都在面向主機網路的介面上啟用了 HSRP(各自的 fa0/0 介面)。

The primary router (Router 1) is configured with priority 110 while the secondary router (Router 2) has a default priority of 100. Router 1 is also configured with the HSRP interface tracking option for the interface Fa0/1, which is connected to the internet. If this interface becomes unavailable, the Router 1 HSRP priority is configured to decrease by 20, which will relinquish the active router role to Router 2, which will have a higher priority during this incident. When interface Fa0/1 on Router 1 comes back online, the router will revert to the configured priority and will become the active router. These changes will happen only if you have enabled pre-emption.

主要路由器(Router 1)的優先權設定為 110,次要路由器(Router 2)則使用預設優先權 100。Router 1 也在連接到網際網路的 Fa0/1 介面上設定了 HSRP 介面追蹤選項。如果這個介面變成無法使用,Router 1 的 HSRP 優先權會依設定降低 20,這將使作用中路由器的角色讓給 Router 2(此時 Router 2 的優先權較高)。當 Router 1 上的 Fa0/1 介面恢復連線後,該路由器會恢復到原本設定的優先權並重新成為作用中路由器。這些變化只有在你啟用搶占功能時才會發生。

HSRP is a Cisco proprietary protocol and VRRP is a standard protocol. VRRP is similar to HSRP, both in operation and configuration, and the differences between HSRP and VRRP are very slight. The VRRP master is analogous to the HSRP active gateway, while the VRRP backup is analogous to the HSRP standby gateway. Other VRRP differences from HSRP include that it allows you to use the actual IP address of one of the VRRP group members as a virtual IP address, and that it uses a different multicast address for communication between peers.

HSRP 是 Cisco 專屬協定,而 VRRP 是一種標準協定。VRRP 在運作方式與設定上都與 HSRP 十分類似,兩者差異非常小。VRRP 的主要路由器(master)相當於 HSRP 的作用中閘道,VRRP 的備援路由器(backup)則相當於 HSRP 的待命閘道。VRRP 與 HSRP 的其他差異包括:VRRP 允許使用 VRRP 群組成員之一的實際 IP 位址作為虛擬 IP 位址,並且在對等體之間的通訊使用不同的群播位址。

Interactive content from the online course (not available offline)線上課程的互動內容(離線版未收錄)
When IPv4 hosts operate on a subnet with routers R1 and R2 configured with HSRP, which IPv4 address should these hosts configure as their default gateway?當 IPv4 主機所在的子網路上有 R1 與 R2 兩台路由器設定了 HSRP,這些主機應將哪個 IPv4 位址設定為預設閘道?
You have enabled HSRP Version 2 between two routers to provide default gateway redundancy to clients. What is the MAC address range that is used for the virtual MAC address, if X represents a variable based on the HSRP group number?你已在兩台路由器之間啟用 HSRP 第 2 版,以提供預設閘道備援給用戶端。若 X 代表根據 HSRP 群組編號而變化的變數,則虛擬 MAC 位址所使用的 MAC 位址範圍為何?