Static Routing静态路由(Windows/Linux/Solaris)
2013-06-14现场网络环境的不同,需要在系统里增加路由时,为了防止机器重启或者网卡重启后路由失效,还需要根据系统使用不同的参数或配置文件:
1、windows系统
命令:route add 172.16.136.0 mask 255.255.252.0 172.17.78.1 -p
注:-p参数会将路由写入注册表
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Tcpip\Parameters\PersistentRoutes]
"0.0.0.0,0.0.0.0,10.228.12.254,-1"=""
检查命令:route print或者netstat -rn
2、linux系统
命令:route add default gw 192.9.100.10
//添加到主机的路由
# route add –host 192.168.1.11 dev eth0
# route add –host 192.168.1.12 gw 192.168.1.1
//添加到网络的路由
# route add –net 192.168.1.11 netmask 255.255.255.0 eth0
# route add –net 192.168.1.11 netmask 255.255.255.0 gw 192.168.1.1
# route add –net 192.168.1.0/24 eth1
//添加默认网关
# route add default gw 192.168.2.1
//删除路由
# route del –host 192.168.1.11 dev eth0
注:为了重起系统路由仍然有效,需要将路由保存下来
方法1:在/etc/rc.local里添加 route add -net 192.168.3.0/24 dev eth0
方法2:在/etc/sysconfig/network里添加到末尾
GATEWAY=gw-ip 或者 GATEWAY=gw-dev
方法3:在/etc/sysconfig/static-routes里添加
static-routes的写法是any net 192.168.0.0/16 gw 网关ip
any net 192.168.3.0/24 gw 192.168.3.254
any net 10.250.228.128 netmask 255.255.255.192 gw 10.250.228.129
参考:/etc/init.d/network
# Add non interface-specific static-routes.
if [ -f /etc/sysconfig/static-routes ]; then
grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
/sbin/route add -$args
done
fi
方法4:在route-eth0里添加
在/etc/sysconfig/network-scripts/route-eth0
添加10.203.166.0/25 via 10.203.166.1 dev eth0
在/etc/sysconfig/network-scripts/route-eth1
添加10.62.206.0/29 via 10.62.206.1 dev eth1
3、Solaris系统(There are many ways to configure static routing under Solaris UNIX.)
命令:route -p add 192.168.2.0/24 192.168.3.254
route delate -net default 192.168.3.254
方法1:vi /etc/defaultrouter这个文件,内容就是你的默认网关
方法2:vi /etc/gateways
Append following entries:
net 192.168.1.0 gateway 192.168.1.254 metric 1 passive
net 10.0.0.0 gateway 10.20.110.1 metric 1 active
方法3:在/etc/rc2.d下面vi S99route
内容: route add -net destination next-hop metric
方法4:route -p add 192.168.2.0/24 192.168.3.254
此命令会将路由写入 /etc/inet/static_routes
分类:操作系统、网络 | 标签: network |