# chapter 2 - 1

![router icon](https://1018652843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LQ-fdc28IFs7YpOIvZ7%2F-LQ-jmzMtGR6xsndtbjC%2F-LQ-jou9dXMPkEWA-tvh%2Froutericon.png?generation=1540832064618920\&alt=media)

插槽比Hub、Switch少，雖然Router也可以接電腦，但主要是用來連接網路設備(Hub、Switch)

## Logical Address (邏輯位置)

其實就是IP Address(Internet Protocol)

## Router 功能

![router function](https://1018652843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LQ-fdc28IFs7YpOIvZ7%2F-LQ-jmzMtGR6xsndtbjC%2F-LQ-jouBSE_y-DdtaxyF%2Frouterfunction.jpg?generation=1540832064709048\&alt=media)

### 1. 阻擋廣播封包

2號發了一個廣播訊息，會傳給左邊所有人包含Router，Router看到廣播封包，會把它阻擋下來，不會傳到其它網路區域

### 2. Network Segment(劃分網路區域)

Router port接出來的就是一個網路區域。以IP來畫分區域，例如左邊的網路區域編號是192.168.200，所以從192.168.200.1開始編號，1就是主機編號

### 3. Routing(繞送)

要送資料給不同網路區域，就要使用Routing，例如1號要發訊息給5號，透過Routing送達

### 筆記: 網路區域就是廣播區域

## 查IP

![IP](https://1018652843-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LQ-fdc28IFs7YpOIvZ7%2F-LQ-jmzMtGR6xsndtbjC%2F-LQ-jouDDQt2k8bf7LzY%2Fip.jpg?generation=1540832064790450\&alt=media)

1\. 在cmd下`ipconfig`&#x20;

2\. 查看網路屬性

> DHCP: 動態分配IP&#x20;

如果使用DHCP，在cmd下`ipconfig /all`可以看到IP租約取得、租約失效的時間

## IP格式

IPv4: 32bits，每8個bit一組，總共4組最小0最大255的數字，組成如`192.168.200.2`的格式

## MAC 和 IP

MAC屬於L2 (Layer 2)\
&#x20;IP屬於L3 (Layer 3)

L2的設備稱為Switch，只能處理到MAC資訊，但是Switch也有L2與L3之分，L3 Switch的可以處理IP資訊\
&#x20;L3的設備稱為Router

資料傳送真正是靠MAC，IP只是輔助。先透過IP找到網路區域，再透過MAC送達資料

## ARP (Address resolution protocol)

> IP查詢MAC，稱為位址解析協定(侷限在同一網路區域) 1. 發出廣播訊息 2. 所有機器收到廣播訊息，並比對IP 3. IP相同就把MAC資訊傳回給送方。送方就可以加上Destination MAC來傳送訊息

電腦有cache(快取)，存IP對應MAC的資訊，這樣不用每次送資料的時候都要透過ARP來查MAC，在 CMD 輸入 `arp -a` 可以查詢cache table

| Internet Address | Physical Address |
| ---------------- | ---------------- |

| 192.168.1.7 | 0001.c969.0200 |
| ----------- | -------------- |

假如 `0001.c969.0200` 這台電腦IP從`192.168.1.7`換成了`192.168.1.10`，又有其它臺電腦註冊了 192.168.1.7 舊IP，我們還是透過 192.168.1.7 這個IP來傳送資料，會發現無法送達訊息。這時候要透過在CMD輸入 `arp -d` 清除cache

cache會在一段時間，或是電腦關機後失效


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://parkerou.gitbook.io/ccna-notes/di-er-zhang-wang-lu-yuan-li-jie-shao/2-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
