一.路由表一般设置:
1、重新启动机器或网卡后,使用通过route命令添加的路由使路由失效。 方法:
//要添加到主机的路由
# route addhost 192.168.1.11 deveth 0
# route addhost 192.168.1.12gw 192.168.1.1
//添加到网络的路由
# route addnet 192.168.1.11 net mask 255.255.255.0 deveth 0
# route addnet 192.168.1.11 net mask 255.255.255.0 GW 192.168.1.1 # route addnet 192.168.1.0/24 devet h1
# route add default gw 192.168.2.1
//删除根
# routedelhost 192.168.1.11 deveth 0
2、也可以使用ip命令添加或删除路由
//添加
iprouteaddefaultvia 172.16.10.2 deveth 0
IP route add 172.16.1.0/24 via 172.16.10.2 deveth 0
3、咨询
# netstat -nr
# route-n
# IP路由列表
# ip route show
二、永久设置路由表:
模糊的鸡:由/etc/sysconfig/network配置文件组成(经我测试,似乎不成功)。
efault via 192.168.3.1 deveth0# 192.168.3.1是eth0网卡的网关地址10.211.6.0/24 via 192.168.3.1 deveth 00
注:此配置表示法还支持写入/etc/sys config/network-scripts/route-interferface配置文件。
bl dbl:/etc/sys config/network-scripts/route-{interferface}配置式配置({ interferface } )是网络接口卡,如eth0
这里支持两种配置格式的写法
答:方法1所述方法
# cat/etc/sys config/network-scripts/route-eth 00.0.0.0/0 via 192.168.3.1 deveth 010.211.6.0/24 via
# cat/etc/sys config/network-scripts/route-eth 110.0.0/8 via 10.212.52.1 deveth 1
b )网络掩码法(利用投机钻空子) ) ) ) ) ) )。
# cat/etc/sys config/network-scripts/route-eth 0
address0=0.0.0.0net mask0=0.0.0.0gateway0=192.168.3.1 address1=10.211.6.0 net mask1=255.255.255.1
其中,网段的地址和掩码都为0表示所有网段,即默认路由。
# cat/etc/sys config/network-scripts/route-et h1
address0=10.0.0.0 net mask0=255.0.0.0 gateway0=10.212.52.1
网络掩码方法也请参照redhat的官方文档。
方法3(/etc/sysconfig/static-routes配置(推荐) ) ) ) ) ) ) ) ) )。)
# cat/etc/sys config/static-route
anynetanygw 192.168.3.1 any net 10.211.6.0/24gw 192.168.3.1 any net 10.0.0net mask 255.0.0.0 GW 10.212
注:默认情况下,此文件不在主机上,因此必须手动创建。 net是作用域,host可以指定单独的计算机。
这种方法也是因为/etc/init.d/network启动脚本调用此文件。 具体的调用代码原理如下。
# addnoninterface-specificstatic-routes.if [-f/etc/sys config/static-routes ]; then
grep ' ^ any '/etc/sys config/static-routes|whilereadignoreargs; do
/sbin/route add -$argsdone
fi
方法四:写在启动脚本/etc/rc.local中
根add-net10.8.0.0255.255.255.0 GW 192.168.199.2
参考: