linux和windows如何添加路由

來源:互聯網
上載者:User
1、添加一條路由表
Route add 60.232.142.40 mask 255.255.255.248 192.168.100.250 metric
3 if
2
添加一條路由記錄,所有到60.232.142.40/29網段的資料包,都通過2號介面卡(網卡)走192.168.100.250的網關,優先順序為3。(結果會怎樣?)
Route
add –p 60.232.142.40 mask 255.255.255.248 192.168.100.250 metric 3 if
2
作用同上,只是這是一條長久路由,不會因為重啟機器而丟失。

2、刪除一條路由表
Route delete
60.232.142.40
請留心:如果有兩條路由記錄有著相同的“目的網路號”,則會將兩條記錄同時刪除。如果只想刪除其中某一條的話,請在刪除後用route
add命令再添加上其中一條。
From:http://whatislinux.net/how-to-add-a-static-ip-route-in-windows

3、修改一條路由記錄
Route
change 157.0.0.0 mask 255.0.0.0 157.55.80.5 metric 2 if
2
Change參數只能修改“網關”和“跳數”linux添加路由路由, linux

linux路由的添加對於我們來說很重要,有的時候網路不通,也許就是你路由沒加,發出來,希望對大家有所協助!

伺服器ip(eth0)
[root@localhost
net]# ifconfig
eth0    Link encap:Ethernet   HWaddr
00:0C:29:E3:9A:15  
      inet addr:172.18.3.205   Bcast:172.18.3.255  
Mask:255.255.255.0
      inet6 addr: fe80::20c:29ff:fee3:9a15/64
Scope:Link
      UP BROADCAST RUNNING MULTICAST   MTU:1500   Metric:1
  
   RX packets:4776 errors:0 dropped:0 overruns:0 frame:0
      TX
packets:3348 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0
txqueuelen:1000
      RX bytes:439384 (429.0 KiB)   TX bytes:390425 (381.2
KiB)
      Interrupt:11 Base address:0x1400
lo        Link encap:Local
Loopback  
      inet addr:127.0.0.1   Mask:255.0.0.0
      inet6 addr:
::1/128 Scope:Host
      UP LOOPBACK RUNNING   MTU:16436   Metric:1
     
RX packets:254 errors:0 dropped:0 overruns:0 frame:0
      TX packets:254
errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0

      RX bytes:22128 (21.6 KiB)   TX bytes:22128 (21.6 KiB)

  
  
查看原始路由資訊
[root@localhost net]# route -n
Kernel IP routing
table
Destination     Gateway       Genmask       Flags Metric Ref Use
Iface
172.18.3.0    0.0.0.0       255.255.255.0 U     0    0        0
eth0
169.254.0.0     0.0.0.0       255.255.0.0     U     0    0        0 eth0

==========================================================

  
  
  
添加預設閘道
[root@localhost net]# route add default gw
172.18.3.50
[root@localhost net]# route
Kernel IP routing
table
Destination     Gateway       Genmask       Flags Metric Ref Use
Iface
172.18.3.0    *             255.255.255.0 U     0    0        0
eth0
169.254.0.0     *             255.255.0.0     U     0    0        0
eth0
default       172.18.3.50     0.0.0.0       UG 0    0        0 eth0

=======================================================

  
  
添加一個ip(eth0:1)
[root@localhost net]# ifconfig eth0:1
192.168.168.119 netmask 255.255.255.0 up
[root@localhost net]#
ifconfig
eth0    Link encap:Ethernet   HWaddr 00:0C:29:E3:9A:15  
     
inet addr:172.18.3.205   Bcast:172.18.3.255   Mask:255.255.255.0
      inet6
addr: fe80::20c:29ff:fee3:9a15/64 Scope:Link
      UP BROADCAST RUNNING
MULTICAST   MTU:1500   Metric:1
      RX packets:5071 errors:0 dropped:0
overruns:0 frame:0
      TX packets:3569 errors:0 dropped:0 overruns:0
carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:466532 (455.5
KiB)   TX bytes:416538 (406.7 KiB)
      Interrupt:11 Base address:0x1400

eth0:1 Link encap:Ethernet   HWaddr 00:0C:29:E3:9A:15  
      inet
addr:192.168.168.119   Bcast:192.168.168.255   Mask:255.255.255.0
      UP
BROADCAST RUNNING MULTICAST   MTU:1500   Metric:1
      Interrupt:11 Base
address:0x1400
lo        Link encap:Local Loopback  
      inet
addr:127.0.0.1   Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
     
UP LOOPBACK RUNNING   MTU:16436   Metric:1
      RX packets:258 errors:0
dropped:0 overruns:0 frame:0
      TX packets:258 errors:0 dropped:0
overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:22480
(21.9 KiB)   TX bytes:22480 (21.9 KiB)
  
在查看路由資訊
[root@localhost
net]# route -n
Kernel IP routing table
Destination     Gateway      
Genmask       Flags Metric Ref Use Iface
172.18.3.0    0.0.0.0      
255.255.255.0 U     0    0        0 eth0
192.168.168.0 0.0.0.0      
255.255.255.0 U     0    0        0 eth0
169.254.0.0     0.0.0.0      
255.255.0.0     U     0    0        0 eth0
0.0.0.0       172.18.3.50    
0.0.0.0       UG 0    0        0 eth0

===============================================================

  
  
添加一條到主機192.168.168.110的路由(通過eth0:1)
[root@localhost net]#
route add -host   192.168.168.110 dev eth0:1
[root@localhost net]#
route
Kernel IP routing table
Destination     Gateway       Genmask      
Flags Metric Ref Use Iface
192.168.168.110 *             255.255.255.255 UH 0
   0        0 eth0
172.18.3.0    *             255.255.255.0 U     0    0   
    0 eth0
192.168.168.0 *             255.255.255.0 U     0    0        0
eth0
169.254.0.0     *             255.255.0.0     U     0    0        0
eth0
default       172.18.3.50     0.0.0.0       UG 0    0        0 eth0

===============================================================

  
  
添加一條到主機192.168.168.120的路由(通過ip192.168.168.119)

[root@localhost net]# route add -host 192.168.168.120 gw
192.168.168.119
[root@localhost net]# route
Kernel IP routing
table
Destination     Gateway       Genmask       Flags Metric Ref Use
Iface
192.168.168.120 192.168.168.119 255.255.255.255 UGH 0    0        0
eth0
192.168.168.110 *     &nb

sp;       255.255.255.255 UH 0    0
       0 eth0
172.18.3.0    *             255.255.255.0 U     0    0        0
eth0
192.168.168.0 *             255.255.255.0 U     0    0        0
eth0
169.254.0.0     *             255.255.0.0     U     0    0        0
eth0
default       172.18.3.50     0.0.0.0       UG 0    0        0 eth0

===========================================================

添加到網路的路由(通過eth0)
[root@localhost net]# route add -net 192.168.3.0
netmask 255.255.255.0 dev eth0
[root@localhost net]# route
Kernel IP
routing table
Destination     Gateway       Genmask       Flags Metric Ref
Use Iface
192.168.168.120 192.168.168.119 255.255.255.255 UGH 0    0        0
eth0
192.168.168.110 *             255.255.255.255 UH 0    0        0
eth0
192.168.3.0     *             255.255.255.0 U     0    0        0
eth0
172.18.3.0    *             255.255.255.0 U     0    0        0
eth0
192.168.168.0 *             255.255.255.0 U     0    0        0
eth0
169.254.0.0     *             255.255.0.0     U     0    0        0
eth0
default       172.18.3.50     0.0.0.0       UG 0    0        0 eth0

  
添加到網路的路由(通過ip172.18.3.50)
[root@localhost net]# route add -net
192.168.4.0 netmask 255.255.255.0 gw 172.18.3.50
[root@localhost net]#
route
Kernel IP routing table
Destination     Gateway       Genmask      
Flags Metric Ref Use Iface
192.168.168.120 192.168.168.119 255.255.255.255
UGH 0    0        0 eth0
192.168.168.110 *             255.255.255.255 UH 0
   0        0 eth0
192.168.4.0     172.18.3.50     255.255.255.0 UG 0    0   
    0 eth0
192.168.3.0     *             255.255.255.0 U     0    0        0
eth0
172.18.3.0    *             255.255.255.0 U     0    0        0
eth0
192.168.168.0 *             255.255.255.0 U     0    0        0
eth0
169.254.0.0     *             255.255.0.0     U     0    0        0
eth0
default       172.18.3.50     0.0.0.0       UG 0    0        0 eth0

=======================================================================

參數區別-host跟主機ip,-net跟網路號

=======================================================================

  
輸出結果中各個欄位的含義是:
  
Destination表示路由的目標IP地址

Gateway表示網關使用的主機名稱或者是IP地址。上面輸出的"*"表示沒有網關
Genmask表示路由的網路遮罩

Flags是表示路由的標誌。可用的標誌及其意義是:U表示路由在啟動,H表示target是一台主機,G表示使用網關,R表示對動態路由進行複位設定;D表示動態安裝路由,M表示修改路由,!表示拒絕路由。

Metric表示路由的單位開銷量
Ref表示依賴本路由現狀的其它路由數目
Use表示路由表條目被使用的數目

Iface表示路由所發送的包的目的網路轉自:http://lzhxiaoyu.blog.51cto.com/10707/291323

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.