在linux下永久保存路由表的寫法
一、SuSe Linux
在/etc/sysconfig/network/routes裏添加。
/etc/sysconfig/network/routes格式如下:
# Destination Dummy/Gateway Netmask Device
#
180.200.0.0 10.200.6.201 255.255.0.0 eth0
180.200.3.170 10.200.6.201 255.255.255.255 eth0
default 124.29.118.1 0.0.0.0 eth1
第一列爲路由目標,可以是網絡或主機的IP地址;
第二列包含默認網關或通過其可訪問主機或網絡的網關;
第三列包含網關後的網絡或主機的子網掩碼;
第四列表示該條路由從哪個設備出去。
添加後運行以下命令生效(以root用戶執行):
/etc/init.d/network restart
二、RedHat Linux
在/etc/rc.d/rc.local文件中添加。
/etc/rc.d/rc.local格式如下:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
touch /var/lock/subsys/local
在/etc/rc.d/rc.local文件最後按下面格式添加路由:
#
route add –host 180.200.3.170 gw 10.200.6.201 dev eth0
route add –net 180.200.0.0 netmask 255.255.0.0 gw 10.200.6.201 dev eth0
#
說明:route add:命令關鍵字,表示增加路由,若要刪除路由,則爲route del;
-host/-net:表示路由目標是主機還是網段;
netmask:表示路由目標爲網段時纔會使用到,表示路由目標網段的子網掩碼;
gw:命令關鍵字,後面跟下一跳網關;
dev:命令關鍵字,後面跟具體設備名,表示路由是從該設備出去。
一般需要重啓系統生效,可使用以下命令重啓系統(以root用戶執行):
shutdown –r now
三、可使用以下命令檢查路由
netstat –rn