redhat雙網關靜態路由的問題解決方案(linux 路由表;linux增加路由表)

來源:互聯網
上載者:User

由於系統需要分別從內外網訪問,即外網使用者從外網訪問伺服器,內網使用者從內網訪問伺服器,結果在配置雙網關後發現內網不能訪問,使用route命令查看路由發現問題原因,重新設定路由解決了問題。

為避免伺服器重啟後再出現路由問題,在設定檔 /etc/rc.local 添加

route add -net 172.0.0.0 netmask 255.0.0.0 gw 172.31.20.254  dev eth1    #內網路由
route add -net 222.211.64.120 netmask 255.255.255.255 gw 219.221.176.253  dev eth0  #為http://www.ip138.com/指定網關
route add default gw 外網出口ip  eth0                                                                  #預設路由
route del -net default  netmask 0.0.0.0 gw 172.31.20.254  dev eth1              #刪除系統自己添加的路由

這樣系統重啟後就能自動化佈建正確的靜態路由,保證內外網都能正常訪問
原理說明:一般來說預設路由只能有一條,即使加了2條,也只能用metric小的那條,只有當metric小的那條路由不可用(如連接埠down)時,另一條才會起作用,所以對於不知道遠端地址情況(如訪問Internet)的那個連接埠需要指預設路由,而對於明確知道遠端地址分配情況的(一般為內網位址區段)連接埠指靜態路由。

linux中類似windows 的route print的命令是:
1、route -e
2、ip route list
3、netstat -rn

netstat -in 查看介面卡的資訊
netstat -rn 查看路由資訊

相關文章

聯繫我們

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