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

            說明:
            第一行表示主機(jī)所在網(wǎng)絡(luò)的地址為192.168.120.0,若數(shù)據(jù)傳送目標(biāo)是在本局域網(wǎng)內(nèi)通信,則可直接通過eth0轉(zhuǎn)發(fā)數(shù)據(jù)包;
            第四行表示數(shù)據(jù)傳送目的是訪問Internet,則由接口eth0,將數(shù)據(jù)包發(fā)送到網(wǎng)關(guān)192.168.120.240
            其中Flags為路由標(biāo)志,標(biāo)記當(dāng)前網(wǎng)絡(luò)節(jié)點(diǎn)的狀態(tài)。
            Flags標(biāo)志說明:
            U Up表示此路由當(dāng)前為啟動狀態(tài)
            H Host,表示此網(wǎng)關(guān)為一主機(jī)
            G Gateway,表示此網(wǎng)關(guān)為一路由器
            R Reinstate route,使用動態(tài)路由重新初始化的路由
            D Dynamically,此路由是動態(tài)性地寫入
            M Modified,此路由是由路由守護(hù)程序或?qū)蚱鲃討B(tài)修改
            ! 表示此路由當(dāng)前為關(guān)閉狀態(tài)
            備注:
            route -n (-n 表示不解析名字,列出速度會比route 快)

            實(shí)例2:添加網(wǎng)關(guān)/設(shè)置網(wǎng)關(guān)
            命令:
            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 ~]# 
            說明:
            增加一條 到達(dá)244.0.0.0的路由

            實(shí)例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 將被拒絕

            實(shí)例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 ~]#

            說明:


            實(shí)例5:刪除和添加設(shè)置默認(rèn)網(wǎng)關(guān)
            命令:
            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 天下 閱讀(504) 評論(0)  編輯 收藏 引用 所屬分類: Linux使用

            <2013年3月>
            242526272812
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(4)

            隨筆分類(378)

            隨筆檔案(329)

            鏈接

            最新隨筆

            搜索

            最新評論

            国产成人精品综合久久久久| 伊人久久久AV老熟妇色| 久久免费线看线看| 91超碰碰碰碰久久久久久综合| 99久久99久久久精品齐齐| 精品久久久久久无码人妻蜜桃| 精品久久久久中文字| 精品伊人久久久| 99久久国产综合精品麻豆| 精品免费久久久久国产一区 | 久久久久97国产精华液好用吗| 亚洲日本久久久午夜精品| 国内精品九九久久久精品| 亚洲国产成人精品久久久国产成人一区二区三区综| 亚洲国产成人久久精品99 | 亚洲AV无码久久精品成人| 亚洲国产天堂久久综合网站| 亚洲精品乱码久久久久久久久久久久 | 久久青青草原精品国产不卡| 久久精品蜜芽亚洲国产AV| 人妻精品久久久久中文字幕| 久久福利青草精品资源站免费| 狠狠色丁香久久婷婷综合图片 | 精品国产婷婷久久久| 色综合久久久久综合体桃花网 | 伊人久久大香线蕉av不卡| 国产2021久久精品| 国产精品久久久久无码av| 影音先锋女人AV鲁色资源网久久| 欧美色综合久久久久久| 国产99久久九九精品无码| 1000部精品久久久久久久久| 亚洲AV无码久久| 日韩AV无码久久一区二区| 国内精品久久久久影院薰衣草 | 久久久精品国产Sm最大网站| 国产农村妇女毛片精品久久| 久久99精品国产麻豆婷婷| 99精品久久久久久久婷婷| 99久久精品免费看国产一区二区三区| 国产精品久久亚洲不卡动漫|