在linux下永久保存路由表的写法(Suse和Redhat)

来源:互联网 发布:数据分析师条件 编辑:程序博客网 时间:2024/04/30 00:28

在linux下永久保存路由表的写法



本文转自:http://blog.csdn.net/chenfei_5201213/article/details/7864337

一、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

1 0