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 New
    • 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 Note Insights Versions and GitHub Sync 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: 1091, lsa --- - Book mode https://hackmd.io/@ncnu-opensource/book Week 05(2020/10/22) === :::info **預習方向** :face_with_monocle: **輸入 URL 後的奇妙世界** 1. 域名解析(Domain_Name --> IP) - 透過 DNS Server 解析 domain_name 對應的 IP 2. 根據 IP 向 web server 發送 request - 傳送過程 TCP/IP 四層架構 - `Link` 根據封包 Mac_address switching (ARP table) - `Network` 根據封包 IP Routing (Routing table) - `Transport` 常見通訊協定為 UDP,TCP,根據不同 port 來連接不同服務 - `Application` 應用解析封包並處裡,常見應用 HTTP, FTP, SSH, telnet... 3. web server 對 request 進行處理並 response - Web Server 的介紹 (nginx, apache2, lighttpd) - Web Server 的設定 - `Virtual host` 透過 domain_name, port, IP 等方式,讓一台或多台 host 可以提供多個服務 - `proxy` 藉由 proxy 設定將封包導向後方主機。可以達到 load balance 或 保護後方主機 的效果 ::: :::warning 問題: 1. UDP 和 TCP 封包有什麼差異特性?封包最大可以到多大? 2. ARP / RARP 在哪一層?作用是什麼? 3. A / AAAA / PTR 紀錄在哪一層?作用是什麼? 4. HTTP 協定在哪一層?有哪些特性? ::: ## 輸入網址: - [FQDN](https://zh.wikipedia.org/wiki/%E5%AE%8C%E6%95%B4%E7%B6%B2%E5%9F%9F%E5%90%8D%E7%A8%B1) = [host name](https://zh.wikipedia.org/zh-tw/%E4%B8%BB%E6%A9%9F%E5%90%8D%E7%A8%B1) + [domain name](https://zh.wikipedia.org/wiki/%E5%9F%9F%E5%90%8D) - domian name轉IP : 向 DNS 伺服器查詢 - `cat /etc/nsswitch.conf` - 可以知道這台電腦是怎麼一步一步去查的 - 預設查找順序 /etc/hosts -> mdns -> dns - ![](https://i.imgur.com/K1ESIIN.png) - host + 網址: 找尋紀錄 - `sudo vim /etc/hosts ` : 可以為domain、host name指定ip - EX: - 當加入 `1.2.3.4 google.com` 之後每次查詢 google.com 都會連到ip為1.2.3.4的電腦,連不上 https://google.com - DNS記錄 - A記錄 : Domain name指定到某IPv4 - AAAA記錄 : Domain name指定到某IPv6 - CNAME記錄 : 將某個Domain name映射到另一個Domain name上 - MX記錄 : 為Domain設定Mail Server位置 - SRV記錄 : 為某個特定服務指定到其他伺服器及port,權限高於其他記錄 - PTR 記錄 : ip 轉 domain name - `dig` + domain name - 出來是 A/AAAA 記錄 - ![](https://i.imgur.com/F8aMRhs.png) - `dig +trace`:把整個路徑都查出來 - `dig @8.8.8.8 +trace www.bluet.org` - 回傳不只一個路徑,挑一個連(用 DNS 分散流量) - `dig www.bluet.org AAAA` - `dig bluet.org ns`: 這個Domain的 name server 是哪一台 - `dig bluet.org mx`: 這個mail exchange - `host ocisly` : not found - 至 `cat /etc/nsswitch.conf` 的 `hosts` 中的 `myhostname` 查詢 - `#files` : 在 `etc /host` 改東西無效 - `cat /etc/resolv.conf` : - nameserver 127.0.0.53(會回傳127.x.x.x,只要是127開頭的都屬於自己的網域) - `route` : 查Routing table(會將 ip address 轉回 domain name) - `route -n`: 查 Routing table(不會將 ip address 轉回 domain name,比較清楚,因為通常不會知道 domain name 指的是誰) - `ifconfig` : 查網卡IP - ![](https://i.imgur.com/feWeBEu.png) - lo: flags底下 - `inet`: 必為127.0.0.1 - `netmask`: 必為255.0.0.0 - ![](https://i.imgur.com/kfOztrl.png) - `nslookup` : 查詢DNS記錄(查詢域名系統以獲得域名或IP地址映射或其他DNS記錄)。 - ~~`sudo vim /etc/nsswitch.conf`裡頭~~ - `sudo vim /etc/resolv.conf` 裡頭 - ![](https://i.imgur.com/p8mcPbq.png) - search xxx.xxx.xxx - 當你 host 不到位置時,它會自動幫你加上xxx.xxx.xxx - eg: host www - ![](https://i.imgur.com/CJiB7aj.png) - [arp](https://zh.wikipedia.org/wiki/%E5%9C%B0%E5%9D%80%E8%A7%A3%E6%9E%90%E5%8D%8F%E8%AE%AE) - `arp -an`: 目前電腦連線過的 ip 對上 MAC address - 只能用在區網(一般 router 不會幫你轉送) - [`arp spoofing`](https://zh.wikipedia.org/wiki/ARP%E6%AC%BA%E9%A8%99) >在學校不要亂用,計中很厲害抓的到。在外租屋就...[name=BlueT] - `arp -n`: 將主機名稱以 IP 的型態顯示 - [rarp](https://zh.wikipedia.org/wiki/%E9%80%86%E5%9C%B0%E5%9D%80%E8%A7%A3%E6%9E%90%E5%8D%8F%E8%AE%AE): 從 mac address 查 ip (與 arp 相反) - 如何知道 IP 是否在某個網段內? - 1. 看網卡 - 2. `route -n` : 查 router 表 - ![](https://i.imgur.com/xoZWWxh.png) - `Genmask: 0.0.0.0` 表示需要有 0 bit 符合 => 顧名思義就是任何 IP 都屬於這網段 (EX: <IP>/0 ) - 查表時如果發現IP非自己網域,就會將封包透過連接對外網域的 gateway 傳出去,而 gateway 在 router 表中的 destination 是 0.0.0.0,也就是所有IP皆會符合,所以其他的找不到才會去配對0.0.0.0的 gateway - 先從 destination 跟 genmask 檢查要送的封包會送去哪,再看 Use Iface 看要送出封包的網卡位置 - `Gateway:192.168.1.1` 代表封包要透過192.168.1.1 傳出去 - 在 IP(Network 層) 紀錄的是 google IP 再往下傳 Gate way 的 MAC address,非自己 IP 就轉送 ,Gateway 會再去查 route table,再看要送往哪裡 - 除非在內網不然都會經過Gate way傳送 - DNS 查看要經過IP->==UDP(**預設**)== - TCP([三向交握!](https://notfalse.net/7/three-way-handshake)+詢問+取得資料,總共5次封包傳送) - UDP(不需三向交握,總共2次封包傳送!對方僅依據 source IP 來判斷來源) - 相對不安全,但速度快 - 被利用作反射式DoS攻擊 : 向Server丟大量、但小的封包,偽造 source IP,Server會將反饋的資料全部丟到被僞造的source IP - ![](https://i.imgur.com/UgWLSxr.png) - > [LMGTFY](https://en.lmgtfy.app/#gsc.tab=0) 超棒的 [name=BlueT] - `telnet`: 以純文字連線 - `telnet google.com 80`: 經由 telnet 將 google.com 經由 80 port 以明文方式傳送 - 對方把網頁內容傳給我們 - `GET /HTTP/1.0`: 使用HTTP/1.0以GET的方式取得/預設內容 - Server 會回覆網頁狀況 EX: HTTP/1.0 200 OK - [HTTP return code](https://en.wikipedia.org/wiki/List_of_HTTP_status_codes) - `telnet ammon.bluet.org 80`:會回傳 OK (不一定,會有 400 bad request 等狀況,依據 GET 打的內容或網頁 server 狀況) - `GET / HTTP/1.0` - `Host: bluet.org` - [virtual host](https://zh.wikipedia.org/zh-tw/%E8%99%9A%E6%8B%9F%E4%B8%BB%E6%9C%BA) - 一台Server上,可以執行多個網站與服務 - 經由 client 端傳送不同的指令(Host:...)而導到不同的顯示內容 - 當 client 傳送的 host 內容, server 這沒有辦法提供,則直接回傳預設的 host - ![](https://i.imgur.com/vgGpDHG.png) > 西北多的[name=BlueT] ## 指令補充 - `ps`:觀察 process 的資訊、狀態、包含pid(只會顯示正在執行的 process) - 過濾自己要的東西出來 - 假設要過濾所有chro的字串輸出: `ps aux | grep chro` - `|`: pipe,將左邊指令的輸出傳到右邊指令的輸入 - `>`: 把後面檔案洗掉,把前面指令的標準輸出重新導向並寫入 - `2>`: 和上面一樣,但是把標準Error輸出重新導向並寫入 - `>>`: 和上面同理,但是不會洗掉檔案,而是把前面的標準輸出插入到後面檔案的最後面 - `grep`: 搜尋有沒有包含或符合某個字串 - `grep -i 1H`: - `-i`:**不分大小寫**的搜尋 ~~- 搜尋特定字母(不是ㄅ)~~ - `grep -irn us ./` - `-r`: 包含子目錄 - `-n`: 顯示行數 - `grep chro > lala`: 重導到lala中 - `>`: 將標準輸出 I/O 的內容,重新導向,把後面檔案的內容洗掉(在這裡目標檔案為 lala) - `grep -c` :計數(在資料裡有幾個搜尋字) - `wc`: 查詢有多少個字元、多少個單字 - ex: `wc lala` - `grep chro >> lala`: - `>>` : 把輸出接在後面 - `tail -n 10 lala`:印出檔案最後幾行(10行) - `ls &`: 把檔案丟背景執行 - `ls &&`:先執行完第一個指令再執行第二個指令 - `watch -n X ls` :每固定X秒數幫我執行ls幾次(X) - `kill PID` (process id) : 終止特定的process - `kill -9 PID`: 強制終止 - `awk` : LINUX 的文字處理工具 - `xargs`: 把輸出,串在後續輸入指令的後面,例如,刪除這個目錄下所有 html 檔:`ls | grep .html | xargs rm` # Linux 輸入輸出特性 - 標準表代碼: - `0`: 輸入 - `1`: 標準輸出 - `2`: 標準Error輸出 - 就是跑出error訊息 - 1、2都是預設直接顯示出來 - `2>&1`: 把這個放到指令最後就可以把標準Error輸出導到標準輸出 - eg.`ls /var/log/lala > lala 2>&1`: 把錯誤的訊息(2) merge 到正確的訊息(1) - eg.`ls /var/log/lala > lala 2>lala2` > ==很多小指令(就像積木一樣),只做一件簡單的事,可以串起來執行,靈活變化==[name=BlueT] > linux有甚麼做不到,除了殺人放火...ㄟ好像也可以[name=BlueT] > 媽的不管,我一定要 [name=BlueT] > 幹,對不起,我現在不太能思考 [name=BlueT] ## Q & A * 可以用 telnet 連到 https 的網站嗎? * 不行,因為沒有SSL加密,但是可以使用 `openssl s_client -connect <domain_name>`,連上 https 的 443 port

    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