• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天下

            記錄修行的印記

            每天一個linux命令(53):route命令

            每天一個linux命令(53):route命令
            http://www.cnblogs.com/peida/archive/2013/03/05/2943698.html

            Linux系統的route命令用于顯示和操作IP路由表(show / manipulate the IP routing table)。要實現兩個不同的子網之間的通信,需要一臺連接兩個網絡的路由器,或者同時位于兩個網絡的網關來實現。在Linux系統中,設置路由通常是為了解決以下問題:該Linux系統在一個局域網中,局域網中有一個網關,能夠讓機器訪問Internet,那么就需要將這臺機器的IP地址設置為Linux機器的默認路由。要注意的是,直接在命令行下執行route命令來添加路由,不會永久保存,當網卡重啟或者機器重啟之后,該路由就失效了;可以在/etc/rc.local中添加route命令來保證該路由設置永久有效。
            1.命令格式:
            route [-f] [-p] [Command [Destination] [mask Netmask] [Gateway] [metric Metric]] [if Interface]]
            2.命令功能:
            route命令是用于操作基于內核ip路由表,它的主要作用是創建一個靜態路由讓指定一個主機或者一個網絡通過一個網絡接口,如eth0。當使用"add"或者"del"參數時,路由表被修改,如果沒有參數,則顯示路由表當前的內容。
            3.命令參數:
            -c 顯示更多信息
            -n 不解析名字
            -v 顯示詳細的處理信息
            -F 顯示發送信息
            -C 顯示路由緩存
            -f 清除所有網關入口的路由表。
            -p 與 add 命令一起使用時使路由具有永久性。
             
            add:添加一條新路由。
            del:刪除一條路由。
            -net:目標地址是一個網絡。
            -host:目標地址是一個主機。
            netmask:當添加一個網絡路由時,需要使用網絡掩碼。
            gw:路由數據包通過網關。注意,你指定的網關必須能夠達到。
            metric:設置路由跳數。
            Command 指定您想運行的命令 (Add/Change/Delete/Print)。
            Destination 指定該路由的網絡目標。
            mask Netmask 指定與網絡目標相關的網絡掩碼(也被稱作子網掩碼)。
            Gateway 指定網絡目標定義的地址集和子網掩碼可以到達的前進或下一躍點 IP 地址。
            metric Metric 為路由指定一個整數成本值標(從 1 至 9999),當在路由表(與轉發的數據包目標地址最匹配)的多個路由中進行選擇時可以使用。
            if Interface 為可以訪問目標的接口指定接口索引。若要獲得一個接口列表和它們相應的接口索引,使用 route print 命令的顯示功能。可以使用十進制或十六進制值進行接口索引。
            4.使用實例:
            實例1:顯示當前路由
            命令:
            route
            route -n

            [root@localhost ~]# route
            Kernel IP routing table
            Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
            192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
            e192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
            10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
            default         192.168.120.240 0.0.0.0         UG    0      0        0 eth0
            [root@localhost ~]# route -n
            Kernel IP routing table
            Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
            192.168.120.0   0.0.0.0         255.255.255.0   U     0      0        0 eth0
            192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
            10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
            0.0.0.0         192.168.120.240 0.0.0.0         UG    0      0        0 eth0

            說明:
            第一行表示主機所在網絡的地址為192.168.120.0,若數據傳送目標是在本局域網內通信,則可直接通過eth0轉發數據包;
            第四行表示數據傳送目的是訪問Internet,則由接口eth0,將數據包發送到網關192.168.120.240
            其中Flags為路由標志,標記當前網絡節點的狀態。
            Flags標志說明:
            U Up表示此路由當前為啟動狀態
            H Host,表示此網關為一主機
            G Gateway,表示此網關為一路由器
            R Reinstate route,使用動態路由重新初始化的路由
            D Dynamically,此路由是動態性地寫入
            M Modified,此路由是由路由守護程序或導向器動態修改
            ! 表示此路由當前為關閉狀態
            備注:
            route -n (-n 表示不解析名字,列出速度會比route 快)

            實例2:添加網關/設置網關
            命令:
            route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
            輸出:
            [root@localhost ~]# route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
            [root@localhost ~]# route
            Kernel IP routing table
            Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
            192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
            192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
            10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
            224.0.0.0       *               240.0.0.0       U     0      0        0 eth0
            default         192.168.120.240 0.0.0.0         UG    0      0        0 eth0
            [root@localhost ~]# 
            說明:
            增加一條 到達244.0.0.0的路由

            實例3:屏蔽一條路由
            命令:
            route add -net 224.0.0.0 netmask 240.0.0.0 reject
            輸出:
            [root@localhost ~]# route add -net 224.0.0.0 netmask 240.0.0.0 reject
            [root@localhost ~]# route
            Kernel IP routing table
            Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
            192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
            192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
            10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
            224.0.0.0       -               240.0.0.0       !     0      -        0 -
            224.0.0.0       *               240.0.0.0       U     0      0        0 eth0
            default         192.168.120.240 0.0.0.0         UG    0      0        0 eth0

            說明:
            增加一條屏蔽的路由,目的地址為 224.x.x.x 將被拒絕

            實例4:刪除路由記錄
            命令:
            route del -net 224.0.0.0 netmask 240.0.0.0
            route del -net 224.0.0.0 netmask 240.0.0.0 reject
            輸出:
            [root@localhost ~]# route
            Kernel IP routing table
            Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
            192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
            192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
            10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
            224.0.0.0       -               240.0.0.0       !     0      -        0 -
            224.0.0.0       *               240.0.0.0       U     0      0        0 eth0
            default         192.168.120.240 0.0.0.0         UG    0      0        0 eth0
            [root@localhost ~]# route del -net 224.0.0.0 netmask 240.0.0.0
            [root@localhost ~]# route
            Kernel IP routing table
            Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
            192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
            192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
            10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
            224.0.0.0       -               240.0.0.0       !     0      -        0 -
            default         192.168.120.240 0.0.0.0         UG    0      0        0 eth0
            [root@localhost ~]# route del -net 224.0.0.0 netmask 240.0.0.0 reject
            [root@localhost ~]# route
            Kernel IP routing table
            Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
            192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
            192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
            10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
            default         192.168.120.240 0.0.0.0         UG    0      0        0 eth0
            [root@localhost ~]#

            說明:


            實例5:刪除和添加設置默認網關
            命令:
            route del default gw 192.168.120.240
            route add default gw 192.168.120.240
            輸出:
            [root@localhost ~]# route del default gw 192.168.120.240
            [root@localhost ~]# route
            Kernel IP routing table
            Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
            192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
            192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
            10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
            [root@localhost ~]# route add default gw 192.168.120.240
            [root@localhost ~]# route
            Kernel IP routing table
            Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
            192.168.120.0   *               255.255.255.0   U     0      0        0 eth0
            192.168.0.0     192.168.120.1   255.255.0.0     UG    0      0        0 eth0
            10.0.0.0        192.168.120.1   255.0.0.0       UG    0      0        0 eth0
            default         192.168.120.240 0.0.0.0         UG    0      0        0 eth0
            [root@localhost ~]#

            posted on 2013-03-07 14:25 天下 閱讀(509) 評論(0)  編輯 收藏 引用 所屬分類: Linux使用

            <2014年9月>
            31123456
            78910111213
            14151617181920
            21222324252627
            2829301234
            567891011

            導航

            統計

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            日产精品久久久久久久| 国产精品日韩深夜福利久久 | 77777亚洲午夜久久多喷| 亚洲乱码精品久久久久..| 亚洲色大成网站www久久九| 国内精品久久人妻互换| 久久精品国产99久久香蕉| 久久精品中文无码资源站| 久久99国产精一区二区三区| 中文字幕久久亚洲一区| 久久精品天天中文字幕人妻| 久久精品成人欧美大片| 九九精品99久久久香蕉| 久久久久久久久久久| 久久久久国产一级毛片高清版| 久久亚洲国产最新网站| 很黄很污的网站久久mimi色| 久久棈精品久久久久久噜噜| 国产香蕉久久精品综合网| 国产精品美女久久久久AV福利| 久久精品国产亚洲AV高清热| 少妇无套内谢久久久久| 国产精品丝袜久久久久久不卡| 久久精品国产亚洲AV麻豆网站 | 色综合久久久久综合体桃花网| 一级做a爰片久久毛片16| 性做久久久久久久| 久久99热这里只有精品国产| 久久久黄色大片| 久久久久99精品成人片三人毛片 | 久久国产精品国语对白| 久久精品免费观看| 69久久夜色精品国产69| 久久亚洲AV成人无码电影| 久久国语露脸国产精品电影| 久久夜色精品国产亚洲| 久久久久久久久波多野高潮| 久久精品国产精品亚洲精品 | 亚洲国产成人精品91久久久| 精品乱码久久久久久夜夜嗨| 人妻丰满?V无码久久不卡|