路邊停
    • Create new note
    • Create a note from template
      • 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
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me 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
    • Save as template
    • 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 Create Help
Create Create new note Create a note from template
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
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me 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
    # 使用SDN 實踐零信任微分段 ## 核心架構如下: ![image](https://hackmd.io/_uploads/H10Yj-WPJl.png) ## 規格: * SDNController Ryu 用途 : 作為SDN PDP OS:Ubuntu 22.04(LTS) Ryu : SDN Controller framework based on python 3.9 Library: Python==3.9(3.10以上不支援)、Miniconda ## 建置環境 ### Mininet 在 SDN-Test VM 上安裝 Mininet: ``` apt install mininet ``` 直接輸入 mn 就可以建立一個簡單的拓樸了 ``` mn ``` 如果後面後面加上-c,作用是清理和重置 Mininet 的環境 這會模擬出兩個主機(h1、h2)及一台switch(s1)、一個默認控制器c0 h1、h2會連接到s1 ``` *** Creating network *** Adding controller *** Adding hosts: h1 h2 *** Adding switches: s1 *** Adding links: (h1, s1) (h2, s1) *** Configuring hosts h1 h2 *** Starting controller c0 *** Starting 1 switches s1 ... *** Starting CLI: mininet> ``` 可以使用指令net,來看目前的網路結構 ![image](https://hackmd.io/_uploads/BkUvoIfwyx.png) 或是輸入pingall來看互相的連接關係 ![image](https://hackmd.io/_uploads/SJYij8GP1l.png) 也可以直接用ping的(h1 ping h2) ![image](https://hackmd.io/_uploads/By4qRLzwkl.png) 使用 xterm 則可以開啟指定節點的終端 ### Controller 連結 使用 linear,3 拓撲(線性拓撲,3個節點),並設置遠程控制器。 ```  sudo mn --topo linear,3 --controller remote ``` 明確指定控制器的 IP 和 Port,這裡控制器運行在本地 IP 127.0.0.1,端口為 6633(默認 OpenFlow 控制器端口)。 ``` sudo mn --controller remote,ip=127.0.0.1,port=6633 ``` 然後確保控制器是啟動的狀態 檢查OpenFlow 規則 用於檢查安裝在交換機(例如 s1)上的 OpenFlow 規則。 這是用來驗證控制器是否正確管理了交換機中的流量規則。 ``` sudo ovs-ofctl dump-flows s1 ``` 如果要連接外地的SDN Controller,使用下面這個指令 ``` mn –-x –-topo linear,3 –-controller remote,ip=192.168.173.15,port=6633 –-switch ovs,protocols=OpenFlow13 ``` ## Ryu 先安裝Miniconda,以免python版本跑掉 ``` wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh ``` 啟動Miniconda 建立python=3.9的環境 ``` source ~/.bashrc conda create -n test_env python=3.9 conda activate test_env ``` 降級setuptool,安裝Ryu ``` pip install setuptools==59.6.0 pip install ryu pip install eventlet==0.30.2 ryu-manager --version ``` 啟用Ryu控制器,使用預設的simple_switch_13 ``` ryu-manager ryu.app.simple_switch_13 ``` 此時,Ryu 控制器會在默認端口(6633)上等待來自 OpenFlow 交換機的連接。 確保 Ryu 控制器運行後再進行下一步操作。 Mininet 進行連接 ``` sudo mn --topo linear,3 --controller remote,ip=127.0.0.1,port=6633 --switch ovs,protocols=OpenFlow13 ``` ## 讓內部host 連網 先安裝工具 ``` sudo apt update sudo apt install isc-dhcp-client ``` ![image](https://hackmd.io/_uploads/rJ2CLNPF1l.png) 原理是透過bridge 新增一個OVS bridge ``` $ ovs-vsctl add-br ovsbr0 #Create OVS bridge $ ovs-vsctl show #Show bridge information 1054844d-7b25-4ec1-be12-2069fac0c03b Bridge "ovsbr0" Port "ovsbr0" Interface "ovsbr0" type: internal ovs_version: "2.5.2" ``` 將實體網卡加入到ovs bridge 中(這裡會短暫被中斷網路) (假設enp0s8為實體網卡) 再加入到ovsbr0,使用dhclient 指令讓ovsbr0自動獲得IP 此時的網路就會恢復了 ``` ifconfig enp0s8 0 ovs-vsctl add-port ovsbr0 enp0s8 dhclient ovsbr0 ifconfig ovsbr0 route -n ``` ![image](https://hackmd.io/_uploads/H1u354Dt1e.png) 先把原本的host網卡所對應的switch s1-eth2 從bridge s1 中移除 ``` ovs-vsctl del-port s1 s1-eth2 ovs-vsctl add-port ovsbr0 s1-eth2 ``` 設定host 網卡,給定靜態網路 ``` mininet> h2 ifconfig h2-eth0 192.168.173.20/24 up ``` 設置後,內部host網路就可以外傳了 set controller ``` ovs-vsctl set-controller ovsbr0 tcp:192.168.1.100:6633 ``` ## 參考連結 https://bingdoal.github.io/network/2022/02/sdn-openflow-controller-opendaylight-mininet/ https://hackmd.io/@cu/SyLOH_-Cu https://medium.com/@john.lin/%E9%80%8F%E9%81%8E-ovs-bridge-%E5%8F%8A-docker-%E8%A6%AA%E6%89%8B%E6%89%93%E9%80%A0-sdn-%E5%AF%A6%E9%A9%97%E7%B6%B2%E8%B7%AF-%E5%9B%9B-%E8%A8%AD%E5%AE%9A%E5%A4%96%E9%83%A8%E9%80%A3%E7%B6%B2-b0e96d9d2ee1

    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