上次青云會議 提到七層交換,根據(jù) URL 自定義轉(zhuǎn)發(fā)策略勃黍,可以自由實現(xiàn)負載均衡,本文給出相關(guān)知識點,包括交換技術(shù)抚芦、OSI 七層模型和 TCP/IP贸弥。
Internet protocol suite (TCP/IP)
- Wireshark @ en.wikiversity.org,實用弄息。
- Topology of the Internet痊班;
- TCP 連接斷連問題剖析(IBM Developerworks)
-
IP - Internet Protocol (rfc791),and Relation to Other Protocols.
Published in September 1981. - Answers to Commonly Asked "New Internet User" Questions
- TCP(rfc793)
- Segment (TCP)
In more precise terminology segment refers to the TCP protocol data unit (PDU), datagram (rfc791) to the IP PDU, and frame to the data link layer PDU.
segment (TCP PDU) -> datagram (IP PDU) -> frame (LINK PDU)
The internet layer is a datagram service provided by an IP. For example, UDP is run by a datagram service in the internet layer.
IP is an entirely connectionless, best effort, unreliable, message delivery service. TCP is a higher level protocol running on top of IP that can provide the addition of a connection-oriented service.
The term datagram is often considered synonymous to packet but there are some nuances. The term datagram is generally reserved for packets of an unreliable service, which cannot notify the sender if delivery fails, while the term packet applies to any packet, reliable or not.
Datagrams are the IP packets that provide a quick and unreliable service like UDP, and all IP packets are datagrams;
However, at the TCP layer what is termed a TCP segment is the sometimes necessary IP fragmentation of a datagram, but those are referred to as "packets".
-
Encapsulation of application data (UDP)摹量;
RFC 1122:Requirements for Internet Hosts -- Communication Layers涤伐。
-
NAT:Network Address Translation。What is NAT荆永?How NAT Tables Work废亭?
-
UDP/IP frame and UDP header
-
TCP/IP frame and TCP header
-
TCP Header 詳解
This is a 4-bit field that indicates the length of the TCP header by a number of 4-byte words in the header, i.e if the header is 20 bytes(min length of TCP header), then this field will hold 5 (because 5 x 4 = 20) and the maximum length: 60 bytes, then it’ll hold the value 15(because 15 x 4 = 60). Hence, the value of this field is always between 5 and 15.
OSI Model
- Published in 1984粗恢,ISO 7498, CCITT (ITU-T) X.200.
OSI 和 TCP/IP 的關(guān)系
-
Application欧瘪,Transport眷射,Internet,Link,
- IP corresponds to a subset of OSI Layer 3, the Network Layer.
- TCP corresponds to OSI Layer 4 (transport) and some functions of Layer 5 (session).
- TCP/IP makes no assumptions about what happens above the level of a network session (part of OSI Layer 5), while OSI defines several more layers of standardized functions.
- TCP/IP makes no prescriptions as to the link layers below IP, where OSI specifies two.
- IP defines how computers can get data to each other over a routed, interconnected set of networks.
- TCP defines how applications can create reliable channels of communication across such a network.
- IP defines addressing and routing, while TCP defines how to have a conversation across the link without garbling or losing data.
一句話:IP 協(xié)議保證數(shù)據(jù)的傳輸妖碉,TCP 協(xié)議保證數(shù)據(jù)傳輸?shù)馁|(zhì)量涌庭; - TCP/IP doesn't map cleanly to the OSI model, since it was developed before the OSI model and was designed to solve a specific set of problems, not to be a general description for all network communications.
Network Interface Layer
As its name suggests, this layer represents the place where the actual TCP/IP protocols running at higher layers interface to the local network.
This layer is somewhat “controversial” in that some people don't even consider it a “l(fā)egitimate” part of TCP/IP. This is usually because none of the core IP protocols run at this layer. Despite this, the network interface layer is part of the architecture. It is equivalent to the data link layer (layer two) in the OSI Reference Model and is also sometimes called the link layer. You may also see the name network access layer.
On many TCP/IP networks, there is no TCP/IP protocol running at all on this layer, because it is simply not needed. For example, if you run TCP/IP over an Ethernet, then Ethernet handles layer two (and layer one) functions. However, the TCP/IP standards do define protocols for TCP/IP networks that do not have their own layer two implementation. These protocols, the Serial Line Internet Protocol (SLIP) and the Point-to-Point Protocol (PPP), serve to fill the gap between the network layer and the physical layer. They are commonly used to facilitate TCP/IP over direct serial line connections (such as dial-up telephone networking) and other technologies that operate directly at the physical layer.
地址轉(zhuǎn)換
- arp 表(ip 地址 -> mac 地址)
ARP 協(xié)議功能是:根據(jù) ip 地址獲取對應(yīng)的 mac 地址,在 IP 協(xié)議集中欧宜,劃在 Link layer坐榆,而在 OSI Model 中,在 2-3 層之間冗茸。
通過廣播一個 ARP 協(xié)議請求消息席镀,能匹配到消息中指定 IP 地址的主機要予以回應(yīng),給出對應(yīng)的 MAC 地址夏漱。 - Windows下豪诲,arp -a 可以查看本地 ARP Table;
-a: Displays current ARP entries by interrogating the current protocol data. If inet_addr is specified, the IP and Physical addresses for only the specified computer are displayed. If more than one network interface uses ARP, entries for each ARP table are displayed.
>arp -a
Interface: 192.168.1.204 --- 0x10005
Internet Address | Physical Address | Type |
---|---|---|
192.168.1.1 | cc-34-29-94-11-1a | dynamic |
- DHCP 時挂绰,使用 ARP 協(xié)議進行 ARP probe 和 ARP announcements跛溉,避免 ip 地址沖突。
- mac 表(mac 地址 -> 交換機物理端口)
交換機:mac 地址 -> 交換機物理端口扮授,即交換機從 mac 表查詢到對應(yīng)的端口芳室,將數(shù)據(jù)復(fù)制到該端口即可,連接在該端口上的主機即可收到數(shù)據(jù)刹勃。在每臺主機發(fā)包或回應(yīng)包的時候堪侯,交換機即可自動收集到 mac 地址和對應(yīng)的物理端口的映射關(guān)系。 - 私有IP地址
10.0.0.0 to 10.255.255.255
172.16.0.0 to 172.31.255.255
192.168.0.0 to 192.168.255.255
169.254.0.0 to 169.254.255.255 for Automatic Private IP Addressing (APIPA) use only.
100.64.0.0/10 for use in carrier-grade NAT environments
交換機(Switch)
傳統(tǒng)的 交換機 是一種基于 MAC 地址識別荔仁、屬于數(shù)據(jù)鏈路層的網(wǎng)絡(luò)設(shè)備伍宦。交換機可以簡單的理解為將若干機器連接起來組成一個小局域網(wǎng)。交換機工作原理比較簡單乏梁,通常提到的交換機指的都是二層交換機次洼,其上存在 MAC 表。
- 按所處網(wǎng)絡(luò)架構(gòu)位置劃分:核心交換機遇骑、接入交換機卖毁、匯聚交換機;
核心交換機:放在網(wǎng)絡(luò)主干部分(核心層)的交換機落萎;
接入交換機:直接面向用戶連接或訪問網(wǎng)絡(luò)的部分稱為接入層交換機亥啦;
匯聚交換機:位于接入層和核心層之間的部分稱為分布層或匯聚層; - 按傳輸介質(zhì)和傳輸速度劃分:以太網(wǎng)交換機练链、快速以太網(wǎng)交換機翔脱、千兆(G位)以太網(wǎng)交換機,萬兆以太網(wǎng)媒鼓,40/100 Gbit/s以太網(wǎng)届吁,...
常見的接口:RJ-45错妖,SC(是一種光纖接口 Optical fiber connector); - 按端口結(jié)構(gòu)劃分:固定端口交換機和模塊化交換機疚沐;
固定端口交換機:桌面式和機架式站玄; - 按交換機工作的協(xié)議層劃分: 二層交換機、三層交換機濒旦、四層交換機;
依據(jù) OSI Reference Model再登;
二層交換機是最原始的交換技術(shù)產(chǎn)品尔邓,桌面型交換機一般屬于這類;
所有的交換機在協(xié)議層次上來說都是向下兼容的锉矢,也就是說所有的交換機都能夠工作在第二層梯嗽; - 按是否支持網(wǎng)管功能劃分:網(wǎng)管型和非網(wǎng)管型;
-
廣播域(Broadcast domain)和沖突域(collision domain)
廣播域:在數(shù)據(jù)鏈路層(OSI 二層)沽损,通過廣播所能到達的計算機范圍灯节;連接到同一個交換機(二層交換)的所有計算機都屬于同一個廣播域;路由器或者高層網(wǎng)絡(luò)設(shè)備劃分了不同的廣播域绵估;
沖突域:通常比廣播域小炎疆,且包含在廣播域內(nèi),屬于物理層(OSI 一層)概念国裳;Hub(集線器)的廣播域和沖突域是相同的形入;Hub 是一層設(shè)備;2011年 802.3 已經(jīng)廢棄使用 Hub 和 中繼器(Repeater)作為聯(lián)網(wǎng)設(shè)備缝左;
- 劃分 VLAN 是一種控制廣播域大小的方法亿遂;一個 VLAN 就是一個廣播域;
當(dāng)在交換機上劃分 VLAN 后渺杉,不同 VLAN 間的設(shè)備就如同被物理地分隔開來蛇数。也就是說,連接到同一交換機是越,然而處于不同 VLAN 的設(shè)備耳舅,就像是被物理地連接到兩個位于不同網(wǎng)段的交換機上一樣,彼此之間的通信一定要經(jīng)過路由設(shè)備倚评,否則將無法得知對方的存在挽放,將無法進行任何聯(lián)系。
Cisco 設(shè)備可以通過 VTP 域(VLAN Trunking Protocol蔓纠,也稱 VLAN 管理域)集中管理各個交換機上的 VLAN 配置辑畦;
路由器(Router)
路由器是一種連接多個網(wǎng)絡(luò)或網(wǎng)段的網(wǎng)絡(luò)設(shè)備,它能將不同網(wǎng)絡(luò)或網(wǎng)段之間的數(shù)據(jù)信息進行“翻譯”腿倚,以使它們能夠相互“讀”懂對方的數(shù)據(jù)纯出,從而構(gòu)成一個更大的網(wǎng)絡(luò)。路由技術(shù)實質(zhì)上可概括為兩種功能:決定最優(yōu)路由和轉(zhuǎn)發(fā)數(shù)據(jù)包。路由器上存在路由表暂筝、ARP 表箩言。
路由器和交換機的區(qū)別
路由器和交換機之間的主要區(qū)別就是:交換機工作在 OSI 參考模型第二層,即數(shù)據(jù)鏈路層焕襟;路由器工作在第三層陨收,即網(wǎng)絡(luò)層。路由器默認是不支持二層的鸵赖。
負載均衡
隨著網(wǎng)絡(luò)應(yīng)用環(huán)境的多樣化务漩,出現(xiàn)三層交換機、四層交換機它褪、七層交換機饵骨,也常稱為負載均衡設(shè)備。
- 二層交換機基于 MAC 地址識別茫打,或者說基于 MAC 地址的二層負載均衡居触。
- 三層交換機基于網(wǎng)絡(luò)層 IP 地址來完成端到端的數(shù)據(jù)交換,或者說基于 IP 地址的三層負載均衡老赤。三層交換存在 MAC 表轮洋、路由表、ARP 表抬旺。
- 四層交換機就是基于 IP+端口的負載均衡砖瞧。
- 七層交換機,是高層智能交換嚷狞,實現(xiàn)基于 URL 等應(yīng)用層信息的負載均衡块促。
三層交換
三層交換機就是具有部分路由器功能的交換機,三層交換機的最重要目的是加快大型局域網(wǎng)內(nèi)部的數(shù)據(jù)交換床未,所具有的路由功能也是為這目的服務(wù)的竭翠,能夠做到一次路由,多次轉(zhuǎn)發(fā)薇搁。對于數(shù)據(jù)包轉(zhuǎn)發(fā)等規(guī)律性的過程由硬件高速實現(xiàn)斋扰,而像路由信息更新、路由表維護啃洋、路由計算传货、路由確定等功能,由軟件實現(xiàn)宏娄。
三層交換機不是簡單的二層交換機和路由器的疊加问裕。實際應(yīng)用過程中,典型的做法是:處于同一個局域網(wǎng)中的各個子網(wǎng)的互聯(lián)以及局域網(wǎng)中 VLAN 間的路由孵坚,用三層交換機來代替路由器粮宛,而只有局域網(wǎng)與公網(wǎng)互聯(lián)之間要實現(xiàn)跨地域的網(wǎng)絡(luò)訪問時窥淆,才通過專業(yè)路由器。
四層交換
在四層交換中巍杈,數(shù)據(jù)包的傳輸不僅僅依據(jù) MAC 地址(第二層交換)或源/目標 IP 地址(第三層路由)忧饭,還依據(jù) TCP | UDP 端口地址(第四層地址),也就是說第四層交換除了考慮三層的邏輯地址外筷畦,還要考慮對端口地址的處理词裤。
由于端口地址代表了不同的業(yè)務(wù)協(xié)議,所以第四層交換不僅僅進行了物理上的交換鳖宾,還包括了業(yè)務(wù)上的交換吼砂。
因此,第四層交換是由源端和終端 IP 地址攘滩、TCP | UDP 端口共同決定,四層交換是真正的 “會話交換”纸泡。
七層交換
第七層交換技術(shù)可以定義為:數(shù)據(jù)包的傳送不僅僅依據(jù) MAC 地址(第二層交換)或源/目標 IP 地址(第三層路由)以及依據(jù) TCP | UDP 端口(第四層地址)漂问,還可以根據(jù)內(nèi)容(表示/應(yīng)用層)進行。這樣的處理更具有智能性女揭,交換的不僅僅是端口蚤假,還包括了內(nèi)容,因此吧兔,第七層交換機是真正的“應(yīng)用交換機”磷仰。
七層交換突破了一般意義上的交換的概念,開始進入以進程和內(nèi)容級別為主的交換范圍境蔼。
由于和應(yīng)用相關(guān)灶平,我們說這時候的交換就有了智能性。交換機具有了區(qū)別各種高層的應(yīng)用和識別內(nèi)容的能力箍土。這時的交換機不僅能根據(jù)數(shù)據(jù)包的 IP 地址或者端口地址來傳送數(shù)據(jù)逢享,而且還能打開數(shù)據(jù)包,進入數(shù)據(jù)包內(nèi)部并根據(jù)包中的信息做出負載均衡吴藻、內(nèi)容識別等判斷瞒爬。
簡單模型
- 5-7 應(yīng)用層:HTTP;應(yīng)用報文(Message)沟堡;
- 4 TCP:TCP/UDP侧但;Port(端口地址);Segment(報文段)/Datagram航罗;
- 3 IP:IP地址禀横;IP 路由;Packet(IP 分組)粥血;
- 2 鏈路層:MAC 地址(物理網(wǎng)絡(luò)地址/硬件地址)燕侠;Frame(幀)者祖;
- 1 物理層:Ethernet;802.11绢彤;Bit(位)七问;
參考
按:本文最初于 2015-05-26 發(fā)表在新浪博客饶氏,今日轉(zhuǎn)發(fā)讥耗。