BryanHsu
    • 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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Week 10 - Book mode https://hackmd.io/@ncnu-opensource/By4H6JLNW ### nat table ![](https://i.imgur.com/PW4kY6f.png) prerouting postrouting firewall 設定網路介面卡開啟 bridge ip a 後 ip 為10.105開頭 firewall 測試對外網路 ``` ping 8.8.8.8 ``` student 因為和 firwall 在同網段下,測試兩者連線 ``` ping 192.168.xx.xx ``` --- ### 要讓 student 透過 firewall 送封包出去 (原本電腦是不提供轉送封包的功能,那是路由器的責任) ``` sudo cat /proc/sys/net/ipv4/ip_forward ``` default 是 0 代表沒有轉送功能 > 改成 1 ``` sudo vim /etc/sysctl.conf ``` 修改 `net.ipv4.ip_forward=0` 這行,拿掉該行註解並將 0 修改成 1 ``` sudo sysctl -p ``` 顯示為 `net.ipv4.ip_forward = 1` 代表完成 也開啟 student ``` route -n #-n 參數為拒絕反解,減少顯示不必要的資料 ``` gateway : 決定封包怎麼丟 要更改 gateway ,因為要將封包改送給 firewall ,並由 firewall 代為向外網送出 student上面: ``` sudo route add default gw "gatewayID" (到 firewall 上面看) ``` 上列指令設定的gatewayID為firewall IP,但firewall網卡有三張因此有三個IP,則選擇與該機器(student)同網段下的IP。 > 同網段:看IP slash `/` 後的數字,以192.168.3.1/24為例,24代表有IP 32bits前面的24 bits被覆蓋,因此只要前面24bits(IP前三數字)相同即為在相同網段下。 如果設定錯誤: ``` sudo route delete default gw "gatewayID" ``` --- ### 設好gateway,但firewall不知道怎麼把封包送出去 firewall: 把別的來源東西轉發出去 ``` sudo iptables -t nat -A POSTROUTING -o ([對外]網卡名稱) -s student上的ip -j MASQUERADE ``` > MASQUERADE 虛偽:因firewall把封包向外網傳送時,在內網內student的是虛擬ip(Private IP)無法被外網辨認,因此必須將IP轉換為firewall自身的對外IP(Public IP)。 --- tcpdump指令可擷取某個interface的封包,類似wireshark,可用來測試電腦是否有收到對方封包,這裡用來確認gateway是否有設定錯誤。 ``` sudo tcpdump -i 對內網卡名稱(ex:enp0s3) 'src 192.168.x.x(ip)' ``` 然後student去ping,就會收到封包 --- 設定讓出的去的封包,回來的時候就不會被擋: ``` sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT ``` > ESTABLISHED:UPD快、TCP穩。TCP會以三向交握建立連後才傳送資料,Firewall對外開啟連線後開啟一個特定的port與對方通訊,firewall 從外網接收到資料後傳送到student接收資料的port。ESTABLISHED只開放已經建立連線的封包經過。 > RELATED:只接受與自己主機送出的封包有關的封包 --- 到/etc/resolv.conf ``` sudo vim /etc/resolv.conf ``` 新增``nameserver 8.8.8.8``(Google的DNS) HWaddr xxxxxxxx : 卡號,獨一無二 ARP查詢 genmask : 網段大小 --- ### 解決firewall可以ping 8.8.8.8 但是沒辦法ping其他網址 ``` cat /proc/sys/net/ipv6/conf/all/disable_ipv6 ``` 看是不是0 如果是就打 ``` echo 1|sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6 ``` 把1寫進去將ipv6關掉 原因:老師說學校網路走ipv6不太穩定所以有可能ping不到 --- ### 遠端備份 (rsync) Ubuntu環境下安裝rsync ``` sudo apt install rsync -y ``` ``` rsync -avhz 檔案名稱 遠端位置(ssh格式一樣): example: rsysc -avhz filename username@ip: //or @ipaddress //filename: 欲備份檔案 //username@....: 備份目的地 ``` 冒號指的是從遠端家目錄開始算,後面可再加路徑指定資料位置 #### 參數 - a : 封裝方式備份,整個資料夾 - v : 備份過程之細節 - h : human readable - z : 壓縮備份內容, - --delete : 將多出來的檔案,維持同步 - --delete-after : - --progress:顯示進度條 - --bwlimit=300:限制網路頻寬 `cp -r a a2` 可拷貝資料夾 rsync 設定檔: /etc/rsyncd.conf 可以設定給別人備份: /etc/default/rsync [rsync vs scp](https://stackoverflow.com/questions/20244585/how-does-scp-differ-from-rsync) --- crontab 工作排程

    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