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 12(2021/12/09) [TOC] # DMZ ![](https://i.imgur.com/5On5HEo.png) - 所有網路都要經過firewall才能出去 - DMZ裡面不能連出去,但外網可以連進來 - DMZ 不能直接連到 student - 先 ping 看看能不能連線 - 外網連到firewall的port,透過firewall轉送連線到DMZ內的http service - 學校有外網、內網和防火牆,另外切一個區域叫DMZ > 實體DMZ : 南北韓中間的非戰區 - 到 DMZ 後即使攻擊成功,也不會危害到內網的東西 # 實作 :::info 需求 * firewall * 對外網卡 *1 (橋接介面卡, bridge): * wan * 對內網卡 *2 (僅限主機介面卡, Host-Only) * lan * dmz * http-service * 對內網卡 *1 (僅限主機介面卡, Host-Only) : lan * student * 對內網卡 *1 (僅限主機介面卡, Host-Only) : lan ::: ![](https://i.imgur.com/eN4PJM3.png) ## DMZ<=>firewall<=>外網 - DMZ can out (為了安裝軟體) - **在firewall上:** 允許連線進到Dmz網卡的都可以轉至Wan網卡出去 ```terminal= sudo iptables -I FORWARD -i {dmz} -o {wan} -j ACCEPT ``` - **在http-service上:** 設置gateway ```terminal= sudo route add default gw {firewall IP} ``` ![](https://i.imgur.com/bhWUNbI.png =60%x) - 封包轉送至指定 ip:port </br>![](https://i.imgur.com/IxOMnsW.png =60%x) - 在 firewall ```terminal= sudo iptables -t nat -A PREROUTING \ -p tcp --dport 8080 \ # 到我的8080port -i {wan} \ -j DNAT --to {http ip}:80 # 轉送去目的ip(DMZ)的80port ``` ![](https://i.imgur.com/1qJaPuO.png) - 從 `{wan}` (網卡卡號) 傳送過來的封包 - `prerouting`: 在封包實際進入電腦之前就先處理封包目的地 - `DNAT`:轉送到 `{http IP}`的 80 port > 白話: 連到 `{wan}` 的 8080 ,都轉送到 `{http IP}:80` - 看剛剛設定的資料 (ps. 參數說明前面有提到) ```Bash= sudo iptables -nvL -t nat --line-number ``` - FORWARD ACCEPT(同意轉送) 去該台 80 port 的封包 ![](https://i.imgur.com/6nFspti.png) - 同意轉送至`{http IP}:80`(destination) 且使用 tcp 的封包 ```terminal= sudo iptables -I FORWARD -d {http ip} -p tcp --dport 80 -j ACCEPT ``` ## DMZ<=>firewall<=>內網 - 同意從 {lan}(firewall 的內網網卡)到 {dmz}(DMZ 的網卡)來的封包 ```terminal= # 內網的 IP 要連到 DMZ sudo iptables -I FORWARD -i {lan} -o {dmz} -j ACCEPT # 任何人傳到 DMZ 前先將 IP 轉換成 內部 IP 到 DMZ 的 網卡? sudo iptables -t nat -A POSTROUTING -o {dmz} -j MASQUERADE ``` >`{lan}` 連內網的網卡 ></br> `{dmz}` 連到dmz的網卡 > MASQUERADE : 將內網IP轉成外網IP (IP 轉換) ![](https://i.imgur.com/7BnCrU8.png) - 封包轉送至指定 ip:port ```terminal= # 目的port 我(firewall)的8080,從 {lan}(內網網卡,在 firewall 上) , 轉送到 http 的 80 port sudo iptables -t nat -A PREROUTING \ -p tcp --dport 8080 \ -i {lan} \ -j DNAT --to {http ip}:80 ``` ```terminal= # 目的port 我(firewall)的8080,從 dmz(在firewall 上的) , 轉送到http 的 80 port sudo iptables -t nat -A PREROUTING \ -p tcp --dport 8080 \ -i {dmz} \ -j DNAT --to {http ip}:80 ``` :::info **花式連線** - ping (ICMP) - 透過 Internet 層發出 ICMP,並讓對方回傳 - 若是 Internet / Transport 層的問題就用 ping - wget & curl - 都當成 http 的 client,都是去做 http 的連線,跟chrome沒有太大的差別 - 測試跨全層(全面測試)有沒有錯誤時用curl - traceroute - 把路徑上的每個節點通通列出來 - `sudo apt install traceroute` - 指令 `traceroute <網址>` - 補充:如果查到最後斷掉,有可能是ICMP的問題,被對方擋了。 - mtr - 觀察每個節點 ::: - 檢查有沒有封包進出 : `tcpdump port <port 號>` - 怎麼讓公網的人能夠連進 DMZ 裡面的 SSH - 接受來自外界到我的 22 port - 別人是用 destination: FIREWALL:22 連過來,所以不能直接 forward 給 DMZ - 要怎麼把 destination: FIREWALL 改成 dest: DMZ網段 (不要用 MASQUEADE) :::info > 我會建議外面連進來的都不要下 MASQUERADE [name=BT] - 因為沒有 MASQUERADE 才可以知道連進來的 IP (被攻擊時就可以知道source IP) - 記得如果沒有 MASQUERADE 要設 gateway,不然回傳不回去(因為不會轉換IP,不同網段之間就無法傳遞) - 不設 MASQUERADE 的話,routing table 需要有相關設定(gateway),否則找不到傳送路線 9- 網路上的封包,是不知道中間到底01多少路途,直接交給預設最信任的人,交給他傳送 ::: :::info > 要做 MASQUEADE [name=BT] - 從**內網到外網**的時候要做 MASQUEADE(把內網 IP 變成自己的 public IP),否則對方server 可能會亂傳給別人的內網 - 封包就算收得到也會迷失在外網的網海中(別人家也有叫做192.168.....的host) ::: - 轉送功能 - 若要跨網段傳資料,就(firewall?)就需要有轉送功能 1. kernel TCP forward link要有開 2. routing table(如果沒有firewall也無法送到student) 3. TCP/IP有forward的相關設定 IP 10. ~ . ~ . ~ 私人網域 172. 192.168 244 :::danger - 希望大家 17:00 到 - 照理來說是考到 20:00 > 但可能到 00:00 ... :::

    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