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
    1
    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 08(2021/11/11) [TOC] ## 作業檢討 :::spoiler 要看解答請點開 1. root > 不行這樣寫 :point_down: > - superuser (superuser 不是只有 root) 2. /etc/passwd >home 看不到其他帳號 只能看到自己的 > 不行這樣寫 :point_down: > - etc/passwd 千萬不要這樣寫!因為沒有寫到根目錄(/) 3. (1) ```chmod 754 text.py``` (2) `chmod u=rwx,g=rx,o=r test.py` > 使用`+`:加上去 賦予他 原本有的權限也還在 > - 直接用 = 取代 4. 硬碟配置 - 不需要把硬碟切割得太細,剩下自動配置 - 硬碟不能混合掛 - apache 網頁檔不在`/etc`(apache 的設定檔在etc) - apache 網頁檔在 `/var/www/` - 優秀答案 1. `/` 掛 500G 的SSD 2. `/var/lib/mysql` 下掛 1.5 T 的SSD 因為 MySQL 常需要快速的讀寫與速度 3. `/var/www/html` 下掛 4T HDD 此為主網頁文件儲存位置 ::: ## SSH ### SSH Tunnel - SSH Tunnel 是一種基於 SSH Protocol 所延伸出來的應用 - 主要運用 : 在兩個端點間建立安全的存取通道 - 讓一些不具有加密存取能力的通訊協定,可以被包覆在ssh協定之中,藉以提供安全的網路服務存取服務(將通訊內容加密避免洩漏) - 讓兩端的通訊能夠穿透過某些限制(例如防火牆) - 防火牆原本希望保護內網,但是不小心把要連線的目標也廢掉 - VPN也是類似的概念 - 分為 3 種類: 1. Local Tunnel 2. Remote Tunnel 3. Dymanic Forward ![](https://i.imgur.com/5v7ztDB.png) >[圖片來源](https://johnliu55.tw/ssh-tunnel.html) ### Local Tunnel (Local Forwarding) 假設 Server 端上有一個 nginx web server (80 port),現在想要**在自己的本機端 (8080 port)執行 server 上的 nginx web server** ![](https://i.imgur.com/sZJ5HEl.png) ![](https://i.imgur.com/klHTumi.png) ```terminal= ssh -L <local IP>:<local port>:<target IP>:<target port> <target server user name>@<target IP> ``` - 裡面連到外面 - 指令參數 - `-N` : 不要另外開啟一個 Shell,ssh 連線後不要執行任何的 command - `-f` : 在背景執行 - `-L` : Local Tunnel - local IP 如果不寫的話,預設就是本機端 localhost #### Demo - 遠端主機 (Target Server) - `sudo apt install nginx` - `service nginx start` - `sudo netstat -ntupl` - 可以透過這個指令看開啟那些port,甚麼服務在用他 - `-r` 列出路由表(route table),功能如同 route 這個指令 - `-n` 不使用主機名稱與服務名稱,使用 IP 與 port number - `-a` 列出所有的連線狀態,包括 tcp/udp/unix socket 等 - `-t` 僅列出 TCP 封包的連線 - `-u` 僅列出 UDP 封包的連線 - `-l` 僅列出有在 Listen (監聽) 的服務之網路狀態 - `-p` 列出 PID 與 Program 的檔名 - `-c` 可以設定幾秒鐘後自動更新一次,例如 `-c` 5 每五秒更新一次網路狀態的顯示 - 看一下 127.0.0.1:80 - `ifconfig` 看 **遠端主機 ip** - 本機 (Client) - `sudo netstat -ntupl` - 8080 ssh - 看一下 127.0.0.1:8080 - 須確保兩台網路可連通 - 把遠端主機當做跳板機(SSH Server) - 本機: `ssh -L 8080:<遠端主機 IP>:80 -Nf <遠端主機使用者>@<遠端主機IP>` - 創造 Local tunnel ,本機(8080)與遠端主機(22)進行 ssh 連線 - 連上之後用底下的指令看開port 的狀況 - `sudo netstat -ntupla` - 可以看到本機 (VM1) 與遠端主機 (VM2) 建立 Tunnel,一條連線 - 這樣我就可以在本機瀏覽器打開 `localhost:8080` 看到遠端主機在 80 port 上跑的服務,如下圖 > ![](https://i.imgur.com/WCLYdQr.png) - Remote tunnal (Remote Forwarding) 跳板機本身沒有開nginx,但她可以開搖控的那台有開nginx的機? ### Remote Tunnel (Remote Forwarding)(Reverse Tunnel) **和 Local Tunnel 相反**,把本地機器上的服務 port 導入到 server 讓他連線。 **在 Server 端(80 port)想讀取 Client 端 (8080 port)的本機服務** ![](https://i.imgur.com/rf4bRuW.png =500x) ![](https://i.imgur.com/ju7EspT.png) ```terminal= ssh -R <server IP>:<server port>:<Client IP>:<Client port> -Nf <Clinet server user>@<Client server IP> ``` - 指令 - `-N`: ssh 連線後不執行任何 command - `-f`: 在背景執行 - -R 的後面 (server IP)沒寫就是預設 localhost - 從 Remote(Server) 端將特定服務的流量透過SSH傳回給Client端的服務 - 把本機(8080)的服務丟到 跳板機jump(22)上,讓跳板機去連 - 在網路上找另外一台跳板機來做為接外面訊息的入口 #### Demo - 遠端主機 - 看一下目前開啟那些port: `sudo netstat -ntupl` - 改設定檔 `sudo vim /etc/ssh/sshd_config` > 要用 sudo 去開,這樣才可以下寫的指令 - 開啟 GatewayPorts - 這樣才能在所有網路介面監聽所有 TCP 通訊埠 ```txt= GatewayPorts yes (預設是no) ``` - `ifconfig` 看IP - 本機 - 看一下目前開啟那些port: `sudo netstat -ntupl` - `ssh -R 8787:localhost:80 -Nf <遠端主機使用者>@<遠端電腦 IP>` - `ssh -R <遠端主機的目標 port>:127.0.0.1:<local port> <遠端主機使用者>@<遠端電腦 IP>` - `N` - 不要執行任何遠端指令。沒有加這個參數時,建立Port Forwarding 的同時也會開啟 Remote Shell, 讓你可以對 SSH Server 下指令,而這個參數可以讓 Remote Shell 不要打開 - `f` - 讓ssh指令在背景執行,讓你可以繼續用 Shell 做事情。通常會搭上面的`-N` 使用 - 遠端主機:`sudo netstat -ntupl` > 可以看到遠端主機 8787 port 與主機進行 sshd 連線 ![](https://i.imgur.com/v4Y1dZF.png) - 在遠端主機瀏覽器打開 `localhost:8787`,這樣就可以看到本機在 80 port 上跑的服務,如下圖 > ![](https://i.imgur.com/qGu1ycQ.png) > 因為我有改本機 80 port 的服務,所以可能跟大家的畫面不太一樣~ :::info **注意** > 要開 port 請開 1024 以上的 port > 0 ~ 1023: 固定的 port > 1024 ~ : 不固定的 port ::: ### Dynamic forward - 只要有一台<span style ="background-color: pink">**位於內網**</span>且<span style ="background-color: pink">**具有外部 IP**</span>的機器,你就可以利用這個方法建立一個 HTTP 代理伺服器,讓你能夠從外面連回內網的所有 HTTP(S) 服務 (跟 local forward 的差別,是可以前往任意網站) (有點像是 VPN) - local tunnel 是一開始連線的時候就有指定的 port - **沒有指定目的地的 port** 的話可以用Dynamic forward ![](https://i.imgur.com/iKePafO.png) > [Dynamic Port Forwarding 圖片來源](https://johnliu55.tw/ssh-tunnel.html) ## FTP (File Transfer Protocol) - 古老的檔案傳輸協定 - 最主要的功能: 讓伺服器與用戶端之間進行檔案的傳輸 - 明文傳輸 (沒有加密) 方式 - 缺點 - 沒加密,安全性不足,如果要登入(帳號密碼)危險 - but 匿名下載就沒差,可以紀錄是誰上傳、下載 - ex:安裝檔案、下載光碟映像檔 - 有些人覺得不記錄誰下載是基本人權(另一部分) - FTP 沒辦法 cache - 但是因為很快,現在還是很常用 - 近年因為匿名性及想cache所以慢慢變少 > 沒辦法做快取的事情 ### FTP的運作流程 - 兩個 port - command port: 預設 21 port,為固定的 port - data port : 預設 20 port,模式不同,開啟的 port 也會不同 - 兩種模式建立連線 - 主動式連線(Active FTP) - 傳統模式 - command port = 20 port,data port = 21 port - Client 端有安全疑慮 - 被動式連線(Passive FTP) - 現在比較多人使用 - command port = 20 port,data port = 不一定是 21 port - Server 端有安全疑慮 - 使用兩個連線,分別是**命令通道**與**資料流通道**(ftp-data) - **命令通道(ftp)** :命令的下達 (預設為 port 21) - **資料流通道(Ftp-data)**: 資料的傳遞(預設port 20) 1. 建立命令通道的連線<br/> ![](https://i.imgur.com/wJpDSX4.png) - 用戶端會隨機取一個大於 1024 以上的 port (port AA) 與 FTP 伺服器端的 port 21 進行連線 - 透過這個連線來對 FTP 伺服器下達指令,包括查詢檔名、下載、上傳等指令 2. 資料流通道的建立(client 在需要資料的情況下) - service 是主動式連線(active)或被動式連線(passive) ### **主動式連線(active)** - 預設是主動連線 > command 通道預設為 21 port > data通道 預設為 20 port > ![](https://i.imgur.com/CQ77Vnw.png) > 藍色線: 命令通道 <br> > 紅色線: 建立連線 <br> > 1:Client 用 1024 port 跟 Server 的 21 port 說「想和 Server 建立連線,等等可以用 1025 port 進行建立連線」 <br> > 2:Server 回復說好,等等和 Client 建立連線(這時候 Client 端收到回覆,就會對外開放 1025 port)<br> > 3:Server 知道 Client 開了 1025 port 就**主動**用 port20 (資料通訊埠)和 Client 1025 port 建立資料連線<br> > 4: Client 傳送資料給 Server ![](https://i.imgur.com/7cGigoM.png) - client 在跟server建立通道的時候就會事先說好等等要用哪個port 做連線 - 兩個port的工作是不一樣的,兩者的連線發起端也是不一樣! - port 20 : FTP伺服器主動連線至客戶端 - port 21 : 主要接受來自用戶端的主動連線 :::danger ### 產生問題 - 需要 server 去主動做連線,Client 在 Server 連線進來之前可能會有人偷跑進來 > 對client的防火牆來說是一個危險的安全警訊,大部分的網路環境,都不允許防火牆外部的系統連線到內部的用戶端的電腦。 - 小故事 : 有人打電話說要來你家,然後你就把你家的門打開了,那這個時候有可能有其他人進來 ::: ### **被動式連線 (Passive)** ![](https://i.imgur.com/kJsceDU.png) - client 須告知 server 要 passive mode - 用戶端藉由**指令通道**告知 FTP Server 要使用"被動式連線",等待 FTP Server 回應 - FTP 伺服器會透過命令通道管道告知 Client 端,Server 已經啟動的 port - Server 可以由管理者決定開啟那些範圍的 port,確保 server 的安全 - client 會隨機取用一個大於 1024 的 port 來進行連線 - 由 client 主動去連 server (防火牆的裡面連到外面) - server 說我開好一個 port 讓 client 用他的port 來連線(因為 client 在防火牆內,所以會由防火牆來避免有人亂跑進來) :::success - 主動式: server 去**主動**連 client - 然後被 client 的防火牆擋住,所以 client 要下指令,說要被動式連線 - 被動式: server **被動**等 client來連線 - 也就是client 主動連線拉~ :::warning **要主動還是被動是 由 client 決定**,,但是 Server 可決定要不要支援這種模式的連線。 ::: ## FTP server - 如果以匿名身分登入ftp服務的話,通常會被限定在 `/var/ftp` 的目錄下,看到的根目錄其實只是`/var/ftp`,至於系統其他如/etc, /home, /usr...等其他目錄你就看不到了! 這樣一來即使這個ftp服務被攻破了,也沒有關係,入侵者還是只能在`/var/ftp`裡面跑來跑去而已,無法使用 Linux 的完整功能 - 改到 `/srv/ftp` 了 - 登入 - 主機登入 - 匿名登入(不推薦) - 危險:陌生人可以隨意連 #### Demo - 上傳目錄 - 連上 server - 要先安裝 ncftp: `sudo apt install ncftp` ```terminal= ncftp -u <user> <ip 位置> ``` - 會進到 `home/<user>` - 常見指令是相通的 ex. ls, cd, pwd - 輸入指令 `lpwd`: 當下這台電腦的路徑在哪裡 - 下載檔案 `get <檔案名稱>` - 如果要一次下載兩個就在後面直接接另一個檔案名稱就好 - 例如: `get <檔案1名稱> <檔案2名稱>` - 一整個資料夾檔案的資料都下載下來 `get -RT <資料夾>` > R: recursive > T: transport 拒絕使用Tar壓縮 - 上傳檔案 ```terminal= put 檔案 ``` ## 更多傳檔案方法 - ftps : ftp 使用 ssl 加密 - 先進行加密再傳輸檔案 - 先打包好再傳輸 - sftp - 在 ssh 建立的狀況下,透過這條線進行傳輸 - `sftp <user>@<server IP>` - ftp - ssh 這條管子裡面進行傳輸 > `sftp`、`ftp` 可以到別人的 server 上查找資料 - scp - 可以在不同的 Linux 主機之間複製檔案 - s = SSH - cp = copy - `cp <來源-要複製的檔案> <目的地>` - 上傳檔案 - `scp <要上傳的檔案路徑> <使用者>@<server IP>` - scp <來源> <目的地> - 下載檔案 ```terminal= scp <使用者>@<server IP>:<伺服器上檔案路徑(來源)> <把抓到的資料放本機的哪(目的)> ``` - `-r` recursion,目錄底下的檔案 ## rsync - 節省流量,避免同樣的檔案又被傳輸到 server - Linux 系統上最常被用來複製與備份檔案的工具 - 可以處理本機或遠端的檔案同步工作 > [來源](https://blog.gtwang.org/linux/rsync-local-remote-file-synchronization-commands/) ### rsync 指令 - `-a` :相當於 -rlptgoD ,所以這個 -a 是最常用的參數了! - 連檔案的權限都會複製過去 (client & server權限都一樣) - 相當於 `scp -r` 的效果,而且由於 rsync 只會傳輸有變動的部份,所以通常在異地備份資料時都會使用這種方式來處理。 :::info **-a** `-r` :備份所有子目錄下的目錄與檔案<br/> `-l` :複製連結檔的屬性,而非連結的目標原始檔案內容;<br/> `-p` :複製時,連同屬性 (permission) 也保存不變!<br/> `-t` :保存原始檔案的時間參數<br/> `-g` :保存原始檔案的擁有群組<br/> `-o` :保存原始檔案的擁有人<br/> `-D` :保存原始檔案的裝置屬性 (device) ::: - `-v` :觀察模式,可以列出更多的資訊,包括鏡像時的檔案檔名等; - `-q` :與 -v 相反,安靜模式,略過正常資訊,僅顯示錯誤訊息; - `-u` :僅更新 (update),若目標檔案較新,則保留新檔案不會覆蓋; - `-z` :在資料傳輸時,加上壓縮的參數! - `-e` :使用的傳輸協定,例如使用 ssh 通道,則 -e ssh - `--progress` - 備份每的檔案的過程就會顯示傳輸的進度、傳輸速度與剩餘時間等資訊: - 如果想要漂亮一點的介面的話 `info=progress2` :::info rsync 和 scp 的差別 : rsync 會先看有那裡不一樣,複製不一樣的部分,可以節省流量與時間 scp 是直接全部覆蓋掉 ::: - 上傳檔案到 server (同步) - `rsync <檔案> <使用者>@<server IP>:<server 目錄位置>/<檔案名稱>`' - 如果不寫`/` 會變成絕對路徑 - 如果`:` 後面不寫目的地,預設的路徑為 Server 的家目錄 - `-a` 如果server 上原本就有那個檔案,傳送同名檔時,權限會寶保留server (目的地)上的權限,需要用 `-a` 才會連同來源的檔案權限一起更改到 Server 上 - `-v` 查看詳細資料,通常都會加,為了知道現在發生甚麼事 - **項目** `sending incremental file list`: 顯示同步的時候有哪些檔案更新與變動過 - `-z` - 壓縮,先壓縮檔案在進行傳送 - 減少網路流量以及頻寬的使用 - 傳過去之後會自動幫你解壓縮 - 傳送過程中會使用掉一些 CPU 的資源, 但可以節省流量 - `--progress` - `-avz` 複製、查看詳細資料、壓縮 :::info 除了用 SSH 連之外,別人也能架一個 rsync server,這樣全世界的人都能來抓你的資料夾,不必知道你的系統使用者名稱。例如 `rsync rsync://ftp.ubuntu-tw.org` ::: - `--info=progress2` - **項目** `sending incremental file list`下會顯示現在的檔案的傳輸速度 - rsync 不會主動幫你刪除檔案(如果 CLient 端和 Server 端檔案列表不一樣的話) > 假設 Server 端有 ff.txt & aa.txt,但是在 Server 只有 aa.txt,如果在 Client 端下 rsync 進行同步,並不會將 Client 端的 ff.txt 進行刪除 - `rsync -avz --info=progress2 --delete <使用者>@<server IP>:<server 目錄位置>/<檔案名稱>` - rsync 加上`--delete` : 才會主動幫你刪除 - `--delete --delete-after`: 新增的東西幫我新增,同步的東西幫我同步,需要刪除的東西再幫我刪除 ## Web Server :::info - 一台主機 - 可以存很多資料or運算力強大 - 可以為大量的使用者提供服務 - 通常以網路作為媒介 - 有很多種類 - file server、FTP server、DNS server - 各式各樣的伺服器提供各式各樣的功能 - 有些伺服器提供的功能,我們幾乎天天用 - 上網查資料 - DNS server 可以透過記錄域名讓我們不用記一串IP也連到網路 - 不過是誰把網站的內容傳給我們的? - web server ::: ## 甚麼是 Web Server - 存放網路伺服器軟體,還有網站檔案的主機 - HTML、圖片、CSS、JavaScript - 透過 HTTP 將網頁資料傳給 client 檔 - 通常 client 端指的是 browser (瀏覽器) ### HTTP - **H**yper**t**ext **T**ransfer **P**rotocol - client 端和 server 端之間 request response 的標準 - 透過 TCP 做為資料的傳輸方式 - 應用層協定 - 預設使用 **80port** 作為通訊的端點 > http vs https ### port - 埠( ㄅㄨˋ )號 :::info - 舉例:郵局 - 一間郵局有多窗口 - 每個窗口辦的事情都不相同 - 如果一號窗口是辦郵政的,你拿存款單過去就會被翻白眼然後請你離開 - 一台電腦也有很多 port (窗口),每一個窗口要服務的內容都不同 - 是系統模擬出來的 port ,不是網路孔的 port - 這些虛擬的 port 可以供各種服務使用 - 0 ~ 65535 個 port - 每個 port 提供的特定服務 - 想 ssh 就使用 22 port,看網頁就用 80 port ::: #### 為何需要 port - 電腦上很多運行的服務會用到網路傳輸資料 - chrome, telegram, game - 一台電腦會有很多port > 不是網路孔的port![name=keke] - 這麼多的資料混在一起,電腦如何分辨出哪些資料是誰的 > 大亂鬥,本來要傳給 telegram 的封包,結果被送到 line 那邊去 - 封包回傳到電腦的時候,會標記要給哪個port - 電腦就會把這個封包分配到目前占用該port的服務 - 這樣就可以知道這個封包是要傳給誰的了 - 0~1023的 port 都有固定的服務 #### 介紹 - port number 以 16bit 來表示 - 共有65536 (2^16^) 個port 可以使用 (0 ~ 65535) - 0 - 保留通訊埠,平常不會啟用 - 1~1023 需要**超級使用者的權限**才能占用的 - 主要用於一些常見的通訊服務 - 1024以上,不須超級使用者權限就能占用這些port - 供其他用途使用 - mysql:3306 - ms-wbt-server : 3389 - Windows RDP(Remote Desktop Protocol) - `/etc/services` - 可以輸入指令`cat /etc/services`查看 - 紀錄各式各樣服務會(被哪些服務)占用的 port - service name, port number, protocol used, aliases - 還會有別名 - IANA制定出來的 :::info **IANA** - internet assigned numbers authority - 管理及維護 Domain Names, Number Resources, Protocol Assignments 的非營利組織 - 定義 port number 註冊表 ::: :::info 小**demo** - `netstat -antupl` - 打開 firefox - 本機到 Local Address 傳過來的封包 ::: - `sudo netstat -ntupl` (沒a) - 看現在有哪些 port number 正在開著,等別人來連 - `sudo netstat -ntupla` (有a) - 我連別人的連線也會顯示 :::warning **DNS連線** - Domain Name System - 用telnet上網 - 瀏覽器上網按enter的過程 ::: ### DNS - 分散式架構 - 查找名稱和地址 > 平常都是使用domain name - 將域名和IP位址相互對應的分散式資料庫,能夠使人方便地存取網際網路 - 所有人都從這13台root查 - 分散式的架構 - 永遠是從點(root)往末端查詢 - ex: root -> tw -> -> edu -> ncnu(...往分支查) - 最後再詢問最後的分支"請問IP是多少" - 如果自己設定的話就不是透過root去查;而是透過自己電腦的cache查,節省流量 - ex. 暨大可以連到google 的是先有一個 cache 來回答你 ![](https://i.imgur.com/mwYfPXK.png) - 世界上有 [**13 台 root DNS**](https://zh.wikipedia.org/wiki/%E6%A0%B9%E7%B6%B2%E5%9F%9F%E5%90%8D%E7%A8%B1%E4%BC%BA%E6%9C%8D%E5%99%A8) (以前有8台) - 在查之前會先看紀錄(快取記憶體) ![](https://i.imgur.com/1F49SRZ.png) - TLD: 高等DNS domain :::info - DNS 基本上是透過 UDP 傳輸封包,若回復的資料超過 512 bytes 時,才會採 TCP 來傳輸 - UDP datagram max size65535 byte - DNS TxT record max size 16384 byte (255 characters * 64 byte) ::: #### 搜尋查找 DNS 流程 - FQDN (Fully Qualified Domain Name) - FQDN = hostname + domain name - `host ammon.bluet.org` > 根據`/etc/nsswitch.conf` 設定 1. `host <domain name>` dns lookup ,查 IP 2. `cat /etc/nsswitch.conf` - 為了查找host跟ip對應 ![](https://i.imgur.com/mM7i5PQ.png) - 圖片的`files`: (先去找files,設定好的檔案放在`/etc/hosts`) - 圖片的`dns`: 如果上面 files (`/etc/hosts`) 找不到,就使用 `/etc/resolv.conf` 的 DNS 伺服器來進行搜尋 - 如果上兩個都找不到,最後就猜你是網域忘了打,幫你加`search ncnu.edu.tw`,看看到底有沒有 3. `sudo vim /etc/hosts` 手動設定主機名稱與對應 IP 位址 >![](https://i.imgur.com/WqwnQtF.png) - 改 google.com 的 IP 位址 - ex:`host google.com` >![](https://i.imgur.com/4dBl6jY.png) - 一開始是寫完整的網址,後面會接一個暱稱(方便之後連線) - ex: 新增 IP: 1.2.3.4 , host aaaa.beba b8b8 - ![](https://i.imgur.com/FzX1c25.png) - ![](https://i.imgur.com/VejCWxU.png) - 輸入`cat /etc/hosts`查看就可看到剛剛新增的host - 上面是IPv4 下面是IPv6 ![](https://i.imgur.com/WjpAZUX.png) > :: 中間的數字都是0,用::省略 4. `cat /etc/resolv.conf` - nameserver - 上限可以設定3個 - 預設為127.0.0.53 - 這個就是跟你說要去找哪個 DNS 的設定檔 > 設定檔都在/etc下 > DNS 連不到或是找不到檔案都可以在這裡找 :::info - cat /etc/hostname - 顯示本機設定的 host 名字 ::: 8.8.8.8(某一台DNS) - `telnet <連線網址IP 位址> <port number>` 連到這個 <IP位址> - 純明文通訊協定 - 輸入 : - GET / HTTP/1.1 - 要在 Host:網址(按兩下Enter) ![](https://i.imgur.com/TUgIWU3.png)

    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