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
    # Week 11(2020/11/26) 期中考題 part 2 底加拉(上機/筆試) - Book mode https://hackmd.io/@ncnu-opensource/book [TOC] ## 規則: ![](https://i.imgur.com/hJueRO7.png) - 如有問題請舉手發問。 - 請在 AWS 上實作。 - 請勿編輯本頁面。 - 請勿以私訊或聊天室等任何方式彼此溝通。 - 當然也請不要直接實體溝通啦... 那算作弊哦 - 可以上網自由地找資料、補充這學期相對應的共筆頁面。 - 請確定執行正確,再找助教 DEMO,僅 **部份**題目 需要 DEMO - 會標記在題目上 - 除了 Webserver 外,DEMO 時,助教發現答案錯誤便 **無法** 擁有再更改的權利(即為該題錯誤) - 筆試答案的部份請寫在試卷上 **We Are Watching You.** ## SSH 5% - 請建立 3 台 AWS EC2 的 Ubuntu VM - 並將下列 ssh 公鑰寫入各個 VM 的特定檔案中,讓助教能以 **無密碼** 的方式 ssh 進你的所有 server 中 - P.S.: 助教擁有私鑰 :::success ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCMCsWRObWBj5mv8FdWFNEb17TDTnlVH6yT1QAOemfsCsjIc1VTTGi1t7HkQJegSJdORNJe2ezSU1vPYhuOCWsnzC2x7tD2aAhrs3SlecR5pMYyhfCsOW+hP8ypb6aaHFSMK49fQf2QGhg80z3pwF1CDIO/3SfhjZR2eA69IsoopgmZ71Q8XmS790GPCNCsBdMkHRgTqJGp8DloxLkuMJQr8ouzm9JpKnnq2Uh0QCHRuRlonKkt/TQXntLR7htaniHjGe/wOcqfzxYfGTLDsPP7rbgZ3tMdttB0IFqGi1jNCdmnpQH15LSY+GnapaBgQekwtIrXsGucUYhM8e2L9dDz 1091lsamideumtest ::: ## Web server 65% 請建立 3 台 EC2 VM 分別實作 Nginx, Apache, Lighttpd server 請依照要求完成以 IP , domain name, 或 port 區分 virtual host 並呈現出不同顯示畫面,詳細架構連接如下圖: ![](https://i.imgur.com/zDKcJkf.png) ### A. <span class="vm">VM-1</span> Nginx server 1. (10%) 輸入 ==<public_**ip**>== 會得到以下頁面 (請依照下列格式作答並顯示在網頁上): - (10%) 成功輸出並且輸出內容正確 - (5%) 成功輸出但輸出內容錯誤 - (0%) 未成功輸出 ```htmlmixed= <head> <meta charset='UTF-8'> <h1>課程相關</h1> <h2>中文全名:(請填入此處)</h2> <h2>英文全名:(請填入此處)</h2> <h2>英文縮寫:(請填入此處)</h2> </head> ``` 2. (5%)輸入 ==<public_**ip**>:8080== 會 proxy 到 [Mr.郭網頁](https://vincentinttsh.github.io/) :::success 請使用 [NO-IP 免費提供 public domain name]( https://www.noip.com/) 取得兩個如 **題3** 與 **題4** 規定之 domain name EX: (以學號 106213014 為例,請依據自己的學號做替換) 106213014-apache.hopto.org 106213014-lighttpd.hopto.org ::: 3. (20%) 輸入 ==<學號>-apache.hopto.org== 會導向 Apache server 的頁面 **(詳細格式請看 VM-2)** - (10%) ==:80 (port)== : 助教資訊 - (10%) ==:80 (port)/~<username> (預設使用者)== : 學生個人資訊 4. (15%) 輸入 ==<學號>-lighttpd.hopto.org== 會導向 Lighttpd server 的頁面 **(詳細格式請看 VM-3)** - (10%) ==:80 (port)== : 老師相關訊息 - (5%) ==:8080 (port)== : 連到 lsa.bluet.org 5. (15%)輸入 ==<public_domain_**name**>== 會在以下 3 個網頁間做 load balance - (5%) 網頁顯示 — 助教的名字 (Apache) - (5%) 網頁顯示 — 老師的資訊 (Lighttpd) - (5%) 網頁顯示 — 老師的網頁 (Lighttpd proxy) ### B. <span class="vm">VM-2</span> Apache server 1. 在 port = 80 時,請作答並以下列格式顯示內容: ```htmlmixed= <head> <meta charset='UTF-8'> <h1>助教們的中文名字</h1> <h2>(請在此處填寫所有助教名字,包含愛心助教共 5 位)</h2> </head> ``` 2. 網址後增加 `/~<username> (預設使用者)` 可 show 出以下學生資訊: ```htmlmixed= <head> <meta charset='UTF-8'> <h1>本次作答學生資訊</h1> <h2>姓名:(請填寫名字)</h2> <h2>學號:(請填寫學號)</h2> </head> ``` ### C. <span class="vm">VM-3</span> Lighttpd server 1. 在 port = 80(Default) 時,請作答並以下列格式顯示內容: ```htmlmixed= <head> <meta charset='UTF-8'> <h1>LSA 的老師</h1> <h2>中文名字:(請作答)</h2> <h2>英文全名:(請作答)</h2> <h2>常用 ID:(請作答)</h2> <h2>Telegram ID:(請作答)</h2> <h2>Facebook 個人檔案的名稱:(請作答)</h2> </head> ``` 2. 在 port = 8080 時,請 proxy 到 lsa.bluet.org ## 手寫 ### 問答題 26% 1. 2% 請問 Linux kernel 第一版是由誰實作的(使用英文回答) 3. 4% Open Source 主張人們對於軟體應該有什麼權利 Open source licenses affect the way people can ___, _____, ______, and __________ software. In general, open source licenses grant computer users permission to use open source software for any purpose they wish. - use、study、 modify 3. 2% 根網域 DNS 伺服器有幾台(不含中國自己講的) 4. 12% 列舉 3 種 webserver(Nginx, Lighttpd, Apache)各自的優劣處 - Nginx - pros: 輕量,善於處理靜態文件,適合做proxy角色,承接多位使用者的連線 - cons: 不善於處理動態文件 - Lighttpd - pros: 輕量快速 - cons: 與Nginx一樣不善於處理動態文件 - Apache - pros: 模組多樣 (只有這個優點) - cons: 很老很肥(不輕量) 5. 4% 在網路世界裡,DMZ 的特點為何?請舉例一個會放在 DMZ 中的服務以及原因 - 特點: 不得以給外網存取的服務,可放在DMZ - 例子: moodle 6. 2% 8.8.8.8 是什麼主機,是由誰提供到? - DNS,Google ### 子網路遮罩 30% 請根據已知資訊,幫我算算下圖 firewall 三張網卡的 IP 及 subnet mask 吧! - 10% eth1 : - firewall 的對外網卡 - 10.多、192.168多 (不要太誇張都給過) - IP 位址、subnet mask為您自己的主機的 IP 及 subnet mask - 10% eth2 - 格式 ==`172.19._._/_`== - firewall 的對內(DMZ 區域)網卡 - IP 位址為該網段的最後一個可用 IP - Ans : 172.19.31.254 - ==s1(Lighttpd) IP 位址為172.19.18.24/20== - ==s2(DNS) IP 位址為172.19.19.24/20== - ==s3(ssh) IP 位址為172.19.19.25/20== - 10% eth3 - 格式 ==`192.168._._/_`== - firewall 的對內(NAT 區域)網卡 - IP 位址為此網段之第一個可用 IP - - 192.168.0(64、128、192).1/18 - 這網段需要 16384 的 IP space - 32-14(2^14=16384)=18 bits(subnet) ### iptables 50%(依照答案正確程度給分) ![](https://i.imgur.com/JHi7yPD.png) :::info **情境** LSA 學院的校網架構如下,擁有一個內網 (LAN) 讓學生們使用,一個 DMZ 放置網頁服務,兩者都不可直接對外 (BBI) ,校網對外 (BBI) 的流量都需要經過 Firewall 過濾再轉送,此外,Firewall 上有 Nginx 作為 Proxy Server 來接收 HTTP 請求,並往後導向 DMZ 的 lighttpd web 伺服器。 ::: :::success :apple: iptables 所有規則都設定在 firewall 防火牆預期的過濾方式如下,請試著根據要求設定防火牆的 iptables 規則: - **BBI 連向 HTTP 服務** (==綠==) - BBI 可以連向 Firewall 的 Nginx - Firewall Nginx 可以將流量 proxy 給 DMZ 的 lighttpd Web 伺服器 (即是 Firewall 可以連上 DMZ 的 Web 伺服器) - **SSH 跳板兒** (==紅==) - BBI 連向 Firewall 2222 port 的流量會被導向 DMZ 的 SSH 伺服器 - DMZ SSH 伺服器可以 SSH 到 LAN 的所有伺服器 - **DMZ 出去** - DMZ 對外只可以跟 NTP 伺服器連線對時 (==黃==) (Hint: 可以透過 /etc/services 查詢 port) - **LAN 出去** - LAN 的主機可以連上任何地方 (BBI, DMZ, Firewall) - LAN 內的主機需要做 DNS 查詢時,都會被導向 DMZ 的 s2 DMZ (==紫==) - 除上述情境,其餘流量皆不允許接受 ::: - INPUT ```shell= # 連線 nginx iptable -A INPUT -p -tcp --dport 80 -j ACCEPT # 允許 LAN 連上 firewall iptables -A INPUT -i {LAN_interface} -j ACCEPT # DMA 相關 iptables -A INPUT eth2 -m conntrack --ctstate # 其餘皆不准 iptables -A INPUT -j DROP ``` - OUTPUT ```shell= # Firewall Nginx proxy to DMZ web iptables -A OUTPUT -d {lighttpd_ip} -p tcp --dport 80 -j ACCEPT # 相關 iptables -A OUTPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # 其餘皆不准 iptables -A OUTPUT -j DROP ``` - FORWARD ```shell= # DMZ 允許該往段向外網 NTP 伺服器對時 iptable -A FORWARD -i {} -o {} -p udp --dprot 123 -j ACCEPT # 允許該網段(LAN)主機去任何地方 iptables -A FORWARD -i {LAN_interface} -j ACCEPT # 允許 DMZ ssh 到 NAT (New 額外 +2.5) iptables -A FORWARD -s {ssh_ip} -o {LAN_interface} -p tcp --dport 22 -j ACCEPT # 允許相關連線 FORWARD (# DMZ 其餘除非是相關連線,皆不可進出) (# LAN 除非相關不然不可以主動連向 LAN) iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT # 其餘皆不准 iptables -A FORWARD -j DROP ``` - POSTROUTING ```shell= # DMZ -> BBI iptables -t nat -A POSTROUTING -i {DMZ_interface} -o {BBI_interface} -j MASQUERADE # DMZ -> LAN (DMZ SSH server only) iptables -t nat -A POSTROUTING -i {DMZ_interface} -o {LAN_interface} -s {SSH_IP} --dport 22 -j MASQUERADE # LAN -> BBI iptables -t nat -A POSTROUTING -i {LAN_interface} -o {BBI_interface} -j MASQUERADE # LAN -> DMZ iptables -t nat -A POSTROUTING -i {LAN_interface} -o {DMZ_interface} -j MASQUERADE ``` - PREROUTING ```shell= # 連向 DMZ 的 SSH 伺服器的 2222 port 會被導向 22 port iptables -t nat -A PREROUTING -i {BBI_interface} -p tcp --dport 2222 -j DNAT -to-destination {ssh_ip}:22 # LAN DNS --> DMZ iptables -t nat -A PREROUTING -i -p tcp --dport 53 -j DNAT --to-destination {DNS_ip}:53 # ssh 走 udp 與 tcp 這兩個 port iptables -t nat -A PREROUTING -i {LAN_interface} -p udp --dport 53 -j DNAT -to-destination {DNS_ip}:53 iptables -t nat -A PREROUTING -i {LAN_interface} -p tcp --dport 53 -j DNAT -to-destination {DNS_ip}:53 ``` - 其他重要指令 - 要把 forward 打開 ( 預設是關閉的 ) ```shell= # Uncomment the next line to enable packet forwarding for IPv4 sudo vim /etc/sysctl.conf ``` ### [加分題] DNS 10% 1. 5% 子子最近在機器上想瀏覽 google 網頁(http://www.google.com),卻發現機器好像中毒了,總是跳出奇怪的頁面,請嘗試找出原因,不需修復。 :::info 機器IP:52.5.66.200 帳號:student ::: ```shell= ssh -i lsa_test2 student@52.5.66.200 ``` - 先去看一下連到 google 有甚麼問題 ```shell= curl www.google.com ``` - 檢查 host 有沒有問題 ```shell= cat /etc/hosts ``` - 檢查 nsswitch ```shell= cat /etc/nsswitch.conf ``` - 問題點 = 無法跑到真正的 google 網站,而是自己內部的ip 2. 5% 緯緯最近在機器上想瀏覽網頁,但發現除非是打 IP,不然都無法上網,請嘗試找出原因,不需修復。 :::info 機器IP:3.214.192.235 帳號:student ::: - 先試試看打 domain name 會怎樣 ```shell= ping www.google.com ``` - 檢查 nsswitch(先看file,再看 dns) ```shell= cat /etc/nsswitch.conf cat /etc/resolv.conf ``` - 問題點 (Ans) - 沒有任何的 dns server 設定 - 也可加入dns server 設定 ### [加分題] Crontab 15% 若我們想要自動化定時執行命令,我們會使用 `crontab` 助教歐阿最近想要建立一個定時提醒(使用 `mail` 指令發信提醒),她發現假日總是過得特別快,他希望在每個「星期日」時能夠在「23:59」提醒他,時間要過了假日要結束了! 1. 5% 當我們要編輯 `crontab` 的內容,應該如何下指令? ```shell= crontab -e ``` ```shell= vim /etc/crontab ``` 2. 5% 當要使用 `mail` 指令,寄送一篇 txt 檔 如下(`/home/lsa/sunday.txt`),並且主旨為 `LSA-pencil-test`,請依照給予的檔案路徑以及主旨要求,並將寄件目的地設為**任一助教的 `學校 email`**,請寫下完整指令 > Hint: 若要實作確認是否寄送成功,可先寄給自己,再從 **垃圾郵件** 中查找 ``` (檔案位址:/home/lsa/sunday.txt) Hello, you need to work tomorrow ``` ```shell= echo "LSA-pencil-test" | mail -s s107213004@mail1.ncnu.edu.tw ``` 3. 5% 承題意,應該如何編輯 crontab 指令,使其符合歐阿的定時要求 ```shell= 59 23 * * 7 root mail ```

    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