NCNU-OpenSource
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- tags: 1101, lsa --- - Book mode https://hackmd.io/@ncnu-opensource/book # Week 10(2021/11/25) [TOC] ## wordpress - PPA : 個人套件庫(Personal Package Archive) > 可以下載這個壓縮檔 `.tar.gz` ![](https://i.imgur.com/QFp6cxV.png) >記得加`;`,才會知道指令結束 ![](https://i.imgur.com/gKmzlNT.png) ## TCP/IP 四層架構 ![](https://i.imgur.com/IPghNG9.png =200x) 明確規範網路上傳送封包的格式 > 五層協議的網路體系結構,方便學習網路原理,綜合OSI和TCP/IP ### link layer #### 服務 - link 連接 - 只能傳給附近的人 - **move packages** between the Internet layer interfaces of two different hosts on the **same link** > 要送到哪? **MAC address (physical address)** - size:6 bytes(48bits) - 以 16 進位表示 > ![](https://i.imgur.com/aI6g7Yv.png) > 只寫網卡卡號的話,這種感覺就像你寄信住址只寫中山路13號 > 但全台灣有很多條中山路... > 所以網卡卡號只能在一個小區域使用 - 1 張網卡, 一個MAC address - 理論上是唯一,但會重複 - 只在區網使用 (若要寄給外網的人,需要將 MAC Address 轉成 IP Address) - ARP: IP address轉為 MAC address :::info ## MAC address - 48 bits - 第 1 bit 為廣播位址(0) / 群播地址(1) - 第 2 bit 為廣域位址(0) / 區域位址(1) - 3~24 bits 由 IEEE 決定如何分配給每一家製造商,且不重複 - 最後24 bits 由實際生產該網路裝置的廠商自行指定且不重複 - 區域網路位址(LAN Address)、Ethernet Address 或 Physical Address ::: **LAN(local Area Network)** - 連接住宅、學校等有線區域內電腦的網路 - Ethernet (乙太網路) - Ethernet 為 LAN 中最為常使用的一種技術 - 相關規範由IEEE 訂定,收錄於IEEE 802.3 標準中 - 相關規範由IEEE訂定,收錄於802.3標準中 ![](https://i.imgur.com/llYv6eM.png) - broadcast 群播 > 安全問題 - 半雙工 (half-duplex) > 資料傳輸方式 - 允許二台裝置之間雙向傳輸資料,但不能同時進行 - collision detection - 偵測資料再傳送時有沒有和其他人撞到,如果沒有撞到-> 傳送成功 - **CSMA/CD**(Carrier Sense Multiple Access/**Collision Detection**) - Carrier Sense - 要送資料之前要檢查網路上是否有其他人在傳送訊號在跑 - Mulitiple Access - access(連線),好幾個人同時連接 - 一邊丟資料要一邊接收訊號,判斷丟出去的跟接到的一樣,以免有別人在丟資料 - **被動偵測**: 要傳資料的時候才開始偵測有沒有撞到 >![](https://i.imgur.com/c12UPg2.png) - 用於容易碰撞的網路環境 - 通常用於有線網路 > 同一條線 - **CSMA/CA**(Carrier Sense Multiple Access /**Collision Avoidance**) - 主動**避免**碰撞 - 不易準確偵測是否有碰撞發生的環境 ex. 無線網路 :::info ### 無線網路 - 透過空氣中的電波傳輸資料 - 較容易受到干擾 - 傳輸裝置收到另外一個裝置傳送的資料,就要回傳一個 ACK Frame ::: - 傳送步驟 1. 偵測是否有 idle 2. 是,則在等待一段時間(Interval Frmae Space,IFS),並再次確認頻道是否idle > 不同傳輸媒介的IFS不同 3. 若頻道仍idle就傳輸資料 4. 資料傳送完成後,傳送裝置會等待一小段時間接收確認封包(ACK),有收到才代表成功,如果一段時機都沒有收到 ACK 就有可能是發生了隱藏碰撞,則傳輸端會重新傳送1次資料 - switch - 可以建立 MAC address table - 找目的地網卡在哪個port - But table 是用學習的 - 傳送過資料的mac address會記錄進table之中 - 找不到就broadcast - 每個port 都是獨立的collision domain - 因為不會有碰撞問題,故不需要CSMA/CD - 每一台主機隨時都可以傳送/接收(雙工) +switch 就不用 CSMA/CD </br>![](https://i.imgur.com/cen5hMI.png =400x) ### Internet Layer **IP Address** - `ifconfig` ![](https://i.imgur.com/YqX7jNl.png) > 紅色框框: IPv6 的 IP - `ip` - `ip link show` - 後面加網卡名稱 - `ip a`: 查看MAC ![](https://i.imgur.com/eRgCxQu.png) > 藍色框框: 網卡名稱 > 紅色框框: IP - 32 bit `0/1` -> w.x.y.z - 類似你家地址 - 應該早就用完了,所以有了IPv6,但是因為神奇的技術所以沒用完 > IPv4 能提供約 42.9 億個 IP,2018 1月全球上網人數已達 40.21 億 :::info **IPv6** - 主要是為了解決 IPv4 用完的問題 - 128 bit - 表達形式一般採用32個十六進制數 ::: **IP 網段** - [wiki](https://zh.wikipedia.org/wiki/IP%E5%9C%B0%E5%9D%80) - classful - class A-E <br/> HostID:該 Class 可以隨便發的;NetID: ![](https://i.imgur.com/oKPqBEn.png) > **class A 128.0.0.0** : 第一個byte是固定的(2進位: 前八個bit固定)<br/> > ex:class A 範圍: **128**.0.0.0 - 128.255.255.255 <br/> > **class B 128.0.0.1** 2進位:前面 16 bits 是固定的,後面 16 bits 可以隨意更動<br/> > **class C 128.1.0.1** > 2進位:只剩後面的 8 bits 可以更動,前面都不可以 - 預設 Net Mask - A Class 的 mask 是 255.0.0.0 - B Class 的 mask 是 255.255.0.0 - C Class 的 mask 是 255.255.255.0 :::success ## 題目: ### 如何取各個 class的 net ID - 真值表 |A|B|A∧B| |:-:|:-:|:-:| |0|0|0| |0|1|0| |1|0|0| |1|1|1| - class A 1.2.3.4 $\xrightarrow{要變成}$ 1.0.0.0 ||1.2.3.4| |-|-| |轉乘二進位|00000001.00000010.00000011.00000100| |AND|11111111.00000000.00000000.00000000| |結果|00000001.00000000.00000000.00000000| - class B 1.2.3.4 $\xrightarrow{要變成}$ 1.2.0.0 ||1.2.3.4| |-|-| |轉乘二進位|00000001.00000010.00000011.00000100| |AND|11111111.11111111.00000000.00000000| |結果|00000001.00000010.00000000.00000000| - class c 1.1.1.000000000 - 1.1.1.01111111 - 想算出 1.1.1.000000000 - 1.1.1.12/**25** - 25 代表找 net ID 時,(2進位)先需要補幾個1 <br/> :arrow_right: 11111111.11111111.11111111.10000000 <br/> :arrow_right: net mask 就可以表示成 255.255.255.128 ||1.1.1.12| |-|-| |轉乘二進位|00000001.00000001.00000001.00001100| |AND|11111111.11111111.11111111.10000000| |結果|00000001.00000001.00000001.00000000| ::: - classless - EX: - IP 為 10.20.0.0/16 - mask = 255.255.0.0 - 10.20.0.0 ~ 10.20.255.255 - IP 00001010.00010100.00000000.00000000 - class B mask :11111111.11111111.00000000.00000000 - 網段 00001010.00010100.00000000.00000000 - 特殊網段 - `192.168.0.0/16` 家庭、小型 - `/` 後面的16 表示遮罩轉成二進位前面 16 bits 都是 1 - ![](https://i.imgur.com/jOiUn5d.png) > 遮罩 netmask 255.255.255.0 $\xrightarrow{轉成二進位 }$ 11111111.11111111.11111111.00000000,可以看到前面有 24 個 1 <br/><br/> > $\xrightarrow{可以表示成}$ 10.0.2.15/24 <br/> > **如果遮罩相同代表在同一個網域下** - `10.0.0.0/8` 大型區網,ex:學校 - `.0` 整個網段 (並非 router) - `.255` broadcast - 好用的工具 - [IP calculator](http://jodies.de/ipcalc) #### 服務 - 決定傳送路徑(route) - routing table - `route -n`: > ![](https://i.imgur.com/nxbIhEN.png) :::info `route` : 放置、新增、刪除從內核的 TCP/IP 的 routing table 去下指令 `iptables`:displays, adds, and deletes entries from Netfilter, the Linux kernal's packet filtering and manipulating subsystem. It handles NAT. ::: ### ARP (Address Resolution Protocol) - address resolution (位址解析) - IP address -> MAC address - ARP Cache - Layer 3的設備 - 儲存相對應的IP與MAC位址 - ARP table - **broadcast** 廣播,要查詢的IP - 附上自己的IP addr.& MAC addr. - 更新發送者的 IP addr. & MAC addr. (自己的 ARP table) - 回復 ARP reply (unicast) - 漏洞 - **不會驗證**收到的ARP封包 - ARP Spoofing: - 讓送至特定IP的流量被送到攻擊者所取代的地方 - passive sniffing(被動監聽) - man-in-the-middle attack - 篡改後再傳送 - 將封包引導到不存在的 MAC 地址,阻斷服務 - 因為傳送封包時,switch 是看 MAC 位址去傳送封包 - `arp` - `sudo arp` - 系統上目前的ARP紀錄: IP對應到的MAC address > ![](https://i.imgur.com/J8jqB21.png) - `sudo arp -s <IP> <網卡?>` 新增 IP - `sudo arp -s 192.168.1.1 3c:22:3f:5d:f6:77` - 手動設定特定主機的 arp 紀錄 - `sudo arp -d <想要刪掉的IP>` - `sudo arp -d 192.168.1.1` - 刪除arp 紀錄 **ICMP(Internet Control Message Protocal)** - 因為IP沒有太多控制,對控制回報不足,所以需要ICMP - ping 回傳接收到封包,代表伺服器正常 - `ping lsa.kija.io` - `ping <網址>` - `traceroute` - `sudo apt install traceroute` - `traceroute <網址>`: - 去這個網站沿路經過的路徑都列出來 - 試試看 `traceroute www.google.com` ![](https://i.imgur.com/VzNbqHI.png) **Conneting device** - router - 以 IP address 為基礎的 routing table - 可以跨subnet一定要用router - 安裝 `sudo apt install traceroute` - `traceroute google.com` - 可以看你送封包給 google.com 的沿路風光 :::success 作業 80 nginx (看到 wordpress) 8091 apache2 8092 lighttpd 先確認三台伺服器可以開啟 ***詳細內容之後再說*** ::: ### Transport Layer ### Application Layer ## OSI 七層

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully