Centos 路由去回不同路解決方式

不知道大家有沒有在linux伺服器上有兩張網卡,且設有多段IP,但是卻如法在同網段ping通和tracert的經驗

本人我就遇過這樣的問題

如果你有兩張網卡 eth0與eth1

eth0的網段為10.10.1.0/24

eth1的網段為10.20.1.0/24

我們假設網段10.10.1.0/24的gateway是10.10.1.1

預定要讓預設的gateway裝置eth0回的話,解決的方式如下:

1.編輯iproute的規則名稱
[root@pandacentos ~]#vi /etc/iproute2/rt_tables
10     pandaroute #10為route table的值,pandaroute為route table名稱,都可自訂,但名稱請取服務名稱,方便辨識
2.重啟網路服務
[root@pandacentos ~]#service network restart
3.增加route的rule
[root@pandacentos ~]#ip route add default via 10.10.1.1 table pandaroute
[root@pandacentos ~]#ip rule add from 10.10.1.0/24 table pandaroute
以上的方式試一次性的解決方式,因為沒加到static route,所以在重開機後route就會消失,要如何避免這個問題,你可以在/etc/rc.d/rc.local上加上面這兩行制令,或用下面的static route 和rule的方式添加
[root@pandacentos ~]#vi /etc/sysconfig/network-script/route-eth0
default via 10.10.1.1 table pandaroute
[root@pandacentos ~]#vi /etc/sysconfig/netwrok-script/rule-eth0
from 10.10.1.0/24 table pandaroute
4.如果是加static route的方式,請在重起一次網路服務
[root@pandacentos ~]#service network restart
廣告

作者: pandalonso

一位喜歡拉拉熊的工程師

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com 標誌

您的留言將使用 WordPress.com 帳號。 登出 /  變更 )

Facebook照片

您的留言將使用 Facebook 帳號。 登出 /  變更 )

連結到 %s

%d 位部落客按了讚: