Over the past few years ,one of the most written-about network topics has been IP. But even with all this attention, few, if any ,stories have traced the protocol's basic workings, that is ,how routers and Layer 3 switches act upon IP information to move Ethernet packets across the network.

As a point of referenced, bear in mind that IP is a member of the TCP/IP protocol suite.

TCP functions at the Open Systems Interconnection(OSI)transport layer, or Layer 4.Its chief responsibility is to ensure reliable end-to-end connectivity. IP, located one layer down, at the OSI network layer, or Layer 3, communicates the addresses of each packet's sender and receiver to the routers along the way. Routers and Layer 3 switches can read IP and other Layer 3 protocols .This information ,combined with routing tables and other network intelligence ,is all it takes to get across the room or around the world via TCP/IP.

The routing process begins with an IP address that is unique to the sending end station .End stations may be assigned permanent IP addresses or they may borrow them as needed from a Dynamic Host Configuration Protocol (DHCP) server or other service.

Each packet carries a source address, which under current (IPv4) specifications is 32 bits long .In its header, each packet also carries the IP address of the final destination.

If the sending end station determines that the destination address is not local ,the packet goes to a first-h(huán)op router ,typically one that is close and has been preassigned to the sender.

The router inspects the packet's IP address and performs a route table lookup to see if the destination end station resides on the local (physically connected) network, typically called an IP subnet .An IP subnet usually is assigned to each of the router's network interfaces.

If the destination IP address is local ,the router searches an internal store of IP addresses and local-device Media Access Control(MAC) addresses. This store is known as the Address Resolution Protocol (ARP) cache. ARP is the universal tool for matching IP addresses to MAC addresses. If the destination's MAC address appears, the router installs that MAC address in the packet header (removing its own MAC address because that's no longer needed) and sends the packet to the destination end station.

In the event that the destination MAC address does not appear in the ARP cache ?it might have timed out ,for instance? the router must broadcast an ARP request to the subnet referenced by the packet's destination IP address .The end station with that IP address responds, sending back its MAC address .The router updates its cache, installs the new MAC address into the packet header and launches the packet. If the route table lookup shows that the packet is destined for a non-local subnet, the router forwards the packet to the next-h(huán)op router using the next-h(huán)op router's MAC address. Routing tables are continuously built and rebuilt by intelligent discovery protocols, such as Routing Information Protocol or Open Shortest Path First (OSPF). Each router's routing table shows the best route to the destination address ;for addresses that may be several hops away, it shows the best next-h(huán)op router.

在過(guò)去幾年中,寫得最多的網(wǎng)絡(luò)題目之一就是IP。但是,即使引起了這么多的注意,仍很少有(如果有的話)文章介紹此協(xié)議的基本工作原理,即路由器和第三層交換器是如何對(duì)IP信息起作用,以便在整個(gè)網(wǎng)絡(luò)中傳遞以太網(wǎng)包的。

作為參考,請(qǐng)記住,IP是TCP/IP整套協(xié)議中的一個(gè)協(xié)議。

TCP完成開放系統(tǒng)互連(OSI)模型中傳輸層,即第四層的功能。它的主要責(zé)任是確保端至端之間的可靠連接。IP位于下一層,在OSI的網(wǎng)絡(luò)層,即第三層,把每個(gè)包的發(fā)送者和接收者地址告訴一路上各個(gè)路由器。路由器和第三層交換器可以讀出IP和其他的第三層協(xié)議。這些信息與路由表以及其他網(wǎng)絡(luò)智能結(jié)合在一起,能通過(guò)TCP/IP在整個(gè)房間或圍繞地球進(jìn)行傳遞。

路由過(guò)程始于對(duì)發(fā)送端站而言是唯一的一個(gè)IP地址,端站可以被分配永久的IP地址,或者按需要從動(dòng)態(tài)主機(jī)配置協(xié)議(DHCP)服務(wù)器或其他服務(wù)中借用。

每個(gè)包攜帶一個(gè)源地址,在目前(IPv4)規(guī)范下,包長(zhǎng)度是32位。在報(bào)頭中,每個(gè)包也攜帶最終目的地的IP地址。

如果發(fā)送端站確定目的地址不在本地,該包就被送到第一跳路由器,一般來(lái)說(shuō),該路由器是在附近的,并已被預(yù)先分配給發(fā)送者。

該路由器檢查包的IP地址,查找路由表,看看目的端點(diǎn)是否位于本地(物理位置)網(wǎng)絡(luò),它通常叫做IP子網(wǎng),IP子網(wǎng)一般被分配到路由器的每個(gè)網(wǎng)絡(luò)接口上。

如果目的IP地址為本地的,該路由器就搜尋存儲(chǔ)著IP地址和本地設(shè)備介質(zhì)訪問(wèn)控制(MAC)地址的內(nèi)部存儲(chǔ)器,這個(gè)存儲(chǔ)器叫作地址分辨協(xié)議(ARP)高速緩存。ARP是把IP地址映射到MAC地址的通用工具。如果目的地的MAC地址出現(xiàn)了,該路由器就把這個(gè)MAC地址裝進(jìn)包的報(bào)頭中(取掉自己的MAC地址,因?yàn)椴辉傩枰?,把該包送到目的端站。

萬(wàn)一目的地的MAC地址沒(méi)有出現(xiàn)在ARP高速緩存中(例如,有可能超時(shí)了),路由器必須向與包的目的IP地址有關(guān)的子網(wǎng)廣播一個(gè)ARP請(qǐng)求,擁有此IP地址的端站就作出響應(yīng),把MAC地址發(fā)送回去,路由器因此更新高速緩存,把新的MAC地址裝進(jìn)包的報(bào)頭并發(fā)送該包。

如果查找路由表顯示包的目的地不在本地子網(wǎng),路由器就利用下一跳路由器的MAC地址把包轉(zhuǎn)發(fā)給下一跳路由器。路由表由智能發(fā)現(xiàn)協(xié)議,如路由信息協(xié)議或者開放最短路徑優(yōu)先協(xié)議,不斷地被建立和再建立。每個(gè)路由器的路由表顯示了到達(dá)目的地址的最佳路徑,對(duì)于要有幾跳的地址,它顯示出最佳的下一跳路由器。