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
    # 防火牆 [TOC] ## 防火牆與網路安全 (Firewall & Network Security) ### Netfilter 與 iptables - **Netfilter**:Linux 核心層封包過濾框架(1998 年 Rusty Russell 主導;自 Linux 2.4 起取代 ipchains)。功能:封包篩選、NAT、封包變更、連線追蹤。 - **iptables**:使用者端 CLI,用來操作 Netfilter。需 `sudo` 權限。 - > **補充:** `nftables` 幾乎已全面取代 `iptables`,程式碼重複度更低、易於擴充新協議。 #### Netfilter Hook 點與封包流程 | Hook | 觸發時機 | |------|----------| | `NF_IP_PRE_ROUTING` | 封包剛進入主機 | | `NF_IP_LOCAL_IN` | 路由判斷目的為本機 | | `NF_IP_FORWARD` | 封包需轉發到其他主機 | | `NF_IP_LOCAL_OUT` | 本機產生之封包送出前 | | `NF_IP_POST_ROUTING` | 封包離開主機前(含轉發) | #### iptables 的 Tables 與 Chains - **Tables**:依功能分類規則;內建常用表:`filter`、`nat`、`mangle`、`raw`、`security`。 - **Chains**:對應 Netfilter Hook,決定規則檢查時機:`PREROUTING`、`INPUT`、`FORWARD`、`OUTPUT`、`POSTROUTING`。 ##### 常用 Tables 說明 | Table | 主要用途 | 典型 Chains | |-------|---------|-------------| | `filter` | 封包允許 / 拒絕 | `INPUT` / `OUTPUT` / `FORWARD` | | `nat` | 網路位址轉譯 (DNAT/SNAT) | `PREROUTING` / `POSTROUTING` / (`INPUT` / `OUTPUT` 特殊情境) | | `mangle` | 修改 TTL、TOS… | `PREROUTING` / `POSTROUTING` / `INPUT` / `OUTPUT` / `FORWARD` | | `raw` | 跳過 conntrack 標記 | `PREROUTING` / `OUTPUT` | | `security` | SELinux 相關標記 | 依需求 | #### 政策 (Policy) 與目標 (Target) - **Policy**:每條 *chain* 的預設行為:`ACCEPT`、`DROP`、`REJECT`。 - **Target**:符合規則後的動作,除上述三者尚可 `LOG` 等。 #### iptables 指令範例 ```bash # 列出目前 filter 規則(不解析 DNS,顯示行號) sudo iptables -t filter -L -nv --line-numbers # 新增規則:允許 22/TCP 進入本機 sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT # 刪除 INPUT 連鎖中的第 3 條規則 sudo iptables -D INPUT 3 # 儲存 / 還原規則 sudo iptables-save > /etc/iptables.rules sudo iptables-restore < /etc/iptables.rules ``` #### NAT (Network Address Translation) - **SNAT (Source NAT)**:`POSTROUTING` 修改來源 IP,常用於 LAN 出口「偽裝」成公網 IP。 - **DNAT (Destination NAT)**:`PREROUTING` 修改目的 IP,常用於將外部連線導向內部伺服器 (DMZ)。 --- ### TCP Wrappers - **配置檔**:`/etc/hosts.allow`(允許)與 `/etc/hosts.deny`(拒絕)。 - **判定順序**:先 `hosts.allow`,再 `hosts.deny`,皆不符合則放行。 - **優缺點**:設定簡易但僅作用於應用層,僅支援透過 `libwrap.so` 之服務。 --- ### Great Firewall (GFW) - 中國大陸用以審查境內網際網路之系統。技術手段:DNS 汙染、IP 封鎖、封包竄改等。 - VPN 翻牆:常見協議有 **PPTP**、**OpenVPN**、**IPsec**;GFW 可透過特徵阻斷加密流量。 --- ## 入侵偵測與防禦系統 (IDS & IPS) ### IDS (Intrusion Detection System) | 類型 | 部署位置 | 監控範圍 | 優 / 缺點 | |------|----------|----------|-----------| | **HIDS** | 被保護主機內 | 系統 Log、Process、文件完整性 | 誤判低,但佔系統資源 | | **NIDS** | 網段中 (port mirror) | 流經之所有封包 | 不影響網路拓撲,但高速流量易遺漏封包 | - **偵測方式** - *Signature‑based / Misuse*:比對已知攻擊特徵,誤判低、未知攻擊偵測率低。 - *Anomaly‑based*:建立正常基線偵測異常,能抓未知攻擊、誤判高。 - **常見 IDS**:`Snort`、`Suricata`、`Zeek`、`OSSEC`、`Fail2Ban`。 ### IPS (Intrusion Prevention System) - **NIPS**:Inline 於網路中,於封包抵達主機前即擋下。 - **HIPS**:安裝於主機,直接丟棄惡意封包。 > **Firewall vs. IDS vs. IPS** > `Firewall` 管控流量進出 → `IDS` 被動偵測通知 → `IPS` 主動阻擋(Inline,失效可能癱瘓網路)。 ### 典型防禦工具 1. **Fail2Ban** – 解析 Log,自動封鎖暴力破解或 DNS DDoS 攻擊來源。 2. **SYN Cookie** – 於半連線佇列滿時計算 Cookie,防禦 SYN Flood。 3. **PortSentry** – 監聽指定埠並結合 TCP Wrapper 阻擋惡意 Port Scan。 --- ## 災難復原與業務永續 (Disaster Recovery & Business Continuity) ### 災難復原 (Disaster Recovery, DR) - **備份** / **時間點快照** / **虛擬 DR** / **實體 DR 站點**。 ### BCDR 架構 | 概念 | 說明 | |------|------| | **BCP** (Business Continuity Plan) | 主動層面,確保災難前中後仍可運作 | | **DRP** (Disaster Recovery Plan) | 被動層面,災後恢復 IT 系統 | - **關鍵指標** - **RTO** (Recovery Time Objective) – 容許停機時間上限。 - **RPO** (Recovery Point Objective) – 容許資料損失時間範圍。 #### 建立 BCP 流程 1. 業務衝擊分析 (BIA) 2. 風險分析 3. 資產盤點與分級 4. 角色 / 職責定義 5. 持續測試與 PDCA 改進 ### 服務可用性 (SLA / SLO / SLI) - **SLI**:延遲、錯誤率、吞吐量等可量化指標。 - **SLO**:基於 SLI 訂定的目標值。 - **SLA**:服務提供者與客戶間的正式協議,含補償條款。

    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