linux添加静态路由生效,linux常识:添加静态路由

方法一:使用命令route //添加路由 # route add -host 192.168.0.221 dev eth0 # route add -host 192.168.1.221 gw 192.168.1.1 # route add -net 192.168.0.221/24 dev eth0 # route add -net 192.168.1.221/24 gw 192.168.1.1 //删除路由 # route del -ne

方法一:使用命令route

//添加路由

# route add -host 192.168.0.221 dev eth0

# route add -host 192.168.1.221 gw 192.168.1.1

# route add -net 192.168.0.221/24 dev eth0

# route add -net 192.168.1.221/24 gw 192.168.1.1

//删除路由

# route del -net 192.168.1.221/24 gw 192.168.1.1

add    增加路由

del    删除路由

-net   设置到某个网段的路由

-host 设置到某台主机的路由

gw     出口网关IP地址

dev    出口网关物理设备名

//增加默认路由(一条就够了)

# route add default gw 192.168.0.1

//查看路由表

# route -n

方法二:使用命令ip route

//添加路由

# ip route add 192.168.0.0/24 via 192.168.0.1 dev eth0

# ip route add default via 192.168.1.1 dev eth0 src 192.168.1.221 table special

//删除路由

# ip route del 192.168.0.0/24 via 192.168.0.1 dev eth0

ip route add   增加路由

ip route del   删除路由

ip route change 更改路由表

ip route show   查看路由表

ip route flush 清空路由表

via   网关出口IP地址

dev 网关出口物理设备名

src 转发数据包前设定该地址为数据包源地址

table 指定添加到该表special

//增加默认路由

# ip route add default via 192.168.0.1 dev eth0

//查看路由信息

# ip route

# ip route show cache

# ip route show table special

设置开机后生效

1、保存路由设置,使其在网络重启后任然有效

# vi /etc/sysconfig/network-script/route-eth0

192.168.1.0/24 via 192.168.1.1

2、static-routes

/etc/rc.d/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

也就是说,将静态路由加到/etc/sysconfig/static-routes 文件中就行了。

如加入:

# route add -net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1

则static-routes的格式为

any net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1

参考链接:

http://linux-ip.net/html/tools-route.html

http://linux-ip.net/html/tools-ip-route.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值