ip route 和 route 命令

ip route 属于 iproute2 工具包;route 属于 net-tools 工具包;目前 ip route 使用较为广泛; 

两个工具包的介绍请见 “iproute2 和 net-tools 介绍” 文章。

ip route命令介绍

        ip route命令用于管理静态路由表。

        linux 系统中,可以自定义从 1-252个路由表。

        路由表和表明的对应关系记录在/etc/iproute2/rt_tables中,所谓操作路由表,路由表必须存在,即操作的此文件下存在的路由表。

1)看某个路由表

#ip route show table table_number / table name
ip route show table 1
192.169.11.0/24 dev br0  scope link  src 192.168.9.234 
192.168.0.0/20 dev wan1.1  scope link 
default via 192.168.10.1 dev wan1.1 
# 
ip route show table rt-wan1.1
192.169.11.0/24 dev br0  scope link  src 192.168.9.234 
192.168.0.0/20 dev wan1.1  scope link 
default via 192.168.10.1 dev wan1.1 
# 

 2)添加路由

# ip route add
ip route show table 11
192.168.0.0/20 dev wan1.1  scope link 
# 
# 192.168.96.0/20:目的网络地址
# dev 接口名称:通过哪个接口进行路由
# table 11: 对路由表11进行的添加路由操作
ip route add 192.168.96.0/20 dev wan2.1 table 11
# 
ip route show table 11
192.168.96.0/20 dev wan2.1  scope link 
192.168.0.0/20 dev wan1.1  scope link 
# 

3)根据条件删除路由表中符合条件的路由项

# ip route del
ip route show table 11
192.168.96.0/20 dev wan2.1  scope link 
192.168.0.0/20 dev wan1.1  scope link 
# 
# 
ip route del 192.168.96.0/20 dev wan2.1 table 11
# 
# 
ip route show table 11
192.168.0.0/20 dev wan1.1  scope link 
# 

4)清空某个路由表

# ip route flush
ip route show table 11
192.168.96.0/20 dev wan2.1  scope link 
192.168.0.0/20 dev wan1.1  scope link 
# 
ip route flush table 11
# 
# 
ip route show table 11
# 

route命令介绍

 1)添加网络路由

# 例1:添加网络路由时,只需指定网络 ID,通过 netmask 设置掩码长度:
[root@VM_139_74_centos ~]# route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0
[root@VM_139_74_centos ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
224.0.0.0       0.0.0.0         240.0.0.0       U     0      0        0 eth0
... 

 2)删除路由

# 例2:删除可用路由
route del -net 224.0.0.0 netmask 240.0.0.0
例3:添加或删除默认网关时,Linux 会自动检查网关的可用性:
[root@VM_139_74_centos ~]# route add default gw 192.168.1.1
SIOCADDRT: Network is unreachable
[root@VM_139_74_centos ~]# route del default gw 192.168.1.1
SIOCDELRT: No such process
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值