Linux作業系統靜態路由設定技巧介紹

來源:互聯網
上載者:User

現在有五個裝置,PC1接ROUT1,ROUT1再接ROUT2,ROUT2再接ROUT3,ROUT3再接PC2,拓撲圖見下:

□————○————○————○————□

PC1 ROUT1 ROUT2 ROUT3 PC2

五個裝置的靜態IP地址分別為:

PC1 192.168.1.88/24

ROUT1 192.168.1.128/24 192.168.2.128/24

ROUT2 192.168.2.66/24 192.168.3.66/24

ROUT3 192.168.3.100/24 192.168.4.33/24

PC2 192.168.4.66/24

PC1配置如下:

#ifconfig eth0 192.168.1.88 netmask 255.255.255.0

#route add default gw 192.168.1.128

ROUT1配置如下:

#ifconfig eth0 192.168.1.128 netmask 255.255.255.0

#ifconfig eth0: 1 192.168.2.128 netmask 255.255.255.0

#route add -net 192.168.4.0/24 gw 192.168.2.66

ROUT2配置如下:

#ifconfig eth0 192.168.2.66 netmask 255.255.255.0

#ifconfig eth0: 1 192.168.3.66 netmask 255.255.255.0

#route add -net 192.168.1.0/24 gw 192.168.2.128

#route add -net 192.168.4.0/24 gw 192.168.3.100

ROUT3配置如下:

#ifconfig eth0 192.168.3.100 netmask 255.255.255.0

#ifconfig eth0: 1 192.168.4.33 netmask 255.255.255.0

#route add -net 192.168.1.0/24 gw 192.168.3.66

PC2配置如下:

#ifconfig eth0 192.168.4.66 netmask 255.255.255.0

#route add default gw 192.168.4.33

這樣PC1就能ping通PC2了。

註:

上面三個路由器這裡用三台PC代替。用電腦代替路由器,必須要啟用電腦的IP轉寄功能,改/proc/sys/net/ipv4/ip_forward裡的內容為1(預設為0),用下面的命令完成

#e cho 1 > /proc/sys/net/ipv4/ip_forward

網路重啟後,上面的檔案自動改為0

補充幾個命令:

1、刪除預設路由

#route del default

2、查看路由

#route -n

3、設定指定網段路由

#route add -net 192.168.3.0 netmask 255.255.255.0 gw 192.168.6.66

或者

#route add -net 192.168.3.0/24 gw 192.168.6.66

4、刪除指定網段路由

#route del -net 192.168.3.0 netmask 255.255.255.0

或者

#route del -net 192.168.3.0/24

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.