Definition

  1. HUB: 將網線集結起來的作用,並對接收到的信號進行再生放大,以擴大網絡的傳輸距離。
  2. Switch: 智能集線器,可以分析目的地位置(MAC),用來隔離衝突域,連接的所有設備同屬於一個廣播域(子網),負責子網內部通信。
  3. Router: 用來隔離廣播域(子網),連接的設備分屬不同子網,工作範圍是多個子網之間,負責網絡與網絡之間通信。

Ref: Hub vs Switch vs Router: What’s the Difference?

HUB & Switch & Router

Connection

小A與小B想要互相通信,因此他使用網線接在彼此的端口,實現了兩台電腦的互連。

HUB

現在小C也想加入通信,但因為每台電腦只有一個網口,所以需要另一台【微型機器】,將彼此的網線集中分發實現最初級的網絡互通。


集線器是最簡單、最便宜、最基礎的設備,因此被廣泛使用,但多年來與交換機(Switch)的價格日漸縮小、相差無幾,以至於時至今日運用範圍越來越小。

集線器運作方式也很簡單,運作在物理層,它會將收到的信息發送給其它的所有端口,無論目的地是哪台計算機,集線器本身對傳輸的數據一無所知。 因此,所有計算機都可以接收該消息,並且計算機本身需要決定是否接受該消息。

從運作方式也可以看出來,在集線器線路上的所有設備都可以看到網絡上的所有流量,因此不是很安全。

Switch

如今,越來越多機器加入互相通信的行列,但是集線器有一個缺點,在集線器發送與接收信息的過程中,會屏蔽禁止其他人的通信的行為,否則信息會產生碰撞,引發錯誤。 而且,上述也提到集線器【會將收到的信息發送給其它的所有端口,無論目的地是哪台計算機,集線器本身對傳輸的數據一無所知】,這樣行為導致效率過低,造成不必要的干擾

如果在傳輸信息時就依據位置來傳送,就可以大大提高傳送速度,也解決了信息衝突的問題。

由於交換機(Switch)是根據網卡地址傳送數據,比網線直連多了一個步驟,因此交換機(Switch)位於數據鏈接層(Data Link)。

交換機本質上是一個智能集線器,具有學習的行為,只要接受過第一次傳輸的記錄後,就會了解並學習,從而提高傳輸速度。

【工作原理】:

Router

在小型的網絡範圍中,上述設備運作良好,但如果今天A村與B村想跟C村通信,卻發現彼此的操作系統都不一致,導致信息間傳送的不相容。

解決方式就是統一度量衡,另外設立一個機器,負責將信息經過相同的協議(TCP/IP)加工成統一形式, 並且依據【DHCP】與【NAT】分派【IP】位置尋址,傳送到對方相同的設備,這就是路由器(Router)的功能。

路由器是前兩者最高階、最複雜、最智能的機器設備,它在OSI通信模型的第3層上運行。路由器旨在將多個網絡連接在一起。

【工作原理】:

Collision Domain & Broadcast Domain

衝突域(Collision Domain):

  • 成因:兩個設備在共享的網段同時發送數據包,就會發生衝突
  • 解決:撤換集線器,使用交換機或是路由器


廣播域(Broadcast Domain):

  • 成因:路由器上所有的端口都位於不同的廣播域中,彼此獨立存在不互相影響。在同一個廣播域中,所有的設備都必須聆聽其中一個設備的廣播消息,造成LAN阻塞。
  • 解決:廣播域的數量越多,網絡為所有用戶提供更好的帶寬的效率就越高。


Switch

Spanning Tree

store-and-forward

switched network

Router

Gateway

store-and-forward

Routing

topology

multiplexing vs de-multiplexing

FDM vs TDM

Statistical multiplexing

Router & DHCP v.s. NAT

DHCP

DHCP — Dynamic Host Configuration Protocol — is how dynamic IP addresses are assigned. When it first connects to the network, a device asks for an IP address to be assigned to it, and a DHCP server responds with an IP address assignment. A router connected to your ISP-provided internet connection will ask your ISP’s server for an IP address; this will be your IP address on the internet. Your local computers, on the other hand, will ask the router for an IP address, and these addresses are local to your network.

Ref: What’s the Difference Between a Hub, a Switch, and a Router? - Ask Leo!

DHCP —動態主機配置協議 —動態IP地址的分配方式。首次連接到網絡時,設備會要求分配IP地址,而DHCP服務器會以IP地址分配作為響應。 連接到您的ISP提供的Internet連接的路由器將詢問您的ISP的服務器IP地址。這將是您在互聯網上的IP地址。另一方面,您的本地計算機將向路由器詢問IP地址,這些地址對於您的網絡是本地的。

NAT

網絡地址轉換(Network address translation):

Ref: What is Network Address Translation (NAT)?


NAT — Network Address Translation- – is the way the router translates the IP addresses of packets that cross the internet/local network boundary. When computer “A” sends a packet, the IP address that it’s “from” is that of computer “A” — 192.168.0.1, in the example above. When the router passes that on to the internet, it replaces the local IP address with the internet IP address assigned by the ISP — 1.2.3.4, in the example. It also keeps track, so if there’s a response the router knows to do the translation in reverse, replacing the internet IP address with the local IP address for machine “A”, and then sending that response packet on to machine “A”.

A side effect of NAT is that machines on the internet cannot initiate communications to local machines; they can only respond to communications initiated by them. This means that the router also acts as an effective firewall.

Ref: What’s the Difference Between a Hub, a Switch, and a Router? - Ask Leo!

NAT(網絡地址轉換)是路由器轉換跨越Internet / local網絡邊界的數據包的IP地址的方式。在上面的示例中,當計算機”A”發送數據包時,其來自的IP地址就是計算機”A”的IP地址-192.168.0.1。 當路由器將其傳遞到Internet時,它將用ISP分配的Internet IP地址替換本地IP地址:在此示例中為1.2.3.4。 它也保持跟踪,因此,如果有響應,則路由器知道進行反向轉換,用機器”A”的本地IP地址替換Internet IP地址,然後將該響應數據包發送到機器”A”。

NAT的副作用是Internet上的計算機無法啟動與本地計算機的通信。他們只能響應他們發起的通信。這意味著路由器還可以充當有效的防火牆。


總結:

  1. 將一個IP地址空間重新映射為另一個IP地址空間的方法,也就是將內部私人網段分配內部網域的計算機的過程,並且公開一個公共IP位置來訪問外部資源(Internet)
  2. 具有防火墻的功能
  3. 限制組織或公司必須使用的公共IP地址的數量,可以節省IPv4的地址空間

Compare

路由谋短,交换求快。

HUB Switch Router
OSI Layer Physical layer Data link layer Network layer
Function To connect a network of personal computers together, they can be joined through a central hub Allow connections to multiple devices, manage ports, manage VLAN security settings Direct data in a network
Data
Transmission
form
electrical signal or bits frame & packet packet
Port 4/12 ports multi-port, usually between 4 and 48 2/4/5/8 ports
Transmission
type
Frame flooding, unicast, multicast or broadcast First broadcast, then unicast and/or multicast depends on the need At initial Level Broadcast then Uni-cast and multicast
Device type Non-intelligent device Intelligent device Intelligent device
Used in
(LAN, MAN, WAN)
LAN LAN LAN, MAN, WAN
Transmission
mode
Half duplex Half/Full duplex Full duplex
Speed 10Mbps 10/100Mbps, 1Gbps 1-100Mbps (wireless);
100Mbps-1Gbps (wired)
address used for
data
transmission
MAC address MAC address IP address

Ref: What’s the Difference? Hub vs Switch vs Router | FS Community

Reference

Definition & Compare:

Collision Domain & Broadcast Domain:

DHCP v.s. DNS: