Chinaunix首页 | 论坛 | 博客
  • 博客访问: 688890
  • 博文数量: 108
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 1436
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-31 09:49
文章分类
文章存档

2019年(16)

2015年(2)

2014年(20)

2013年(70)

我的朋友

分类: LINUX

2015-05-05 11:20:58


192.168.4.0 192.168.1.254 255.255.255.0

192.168.3.0 192.168.1.254 255.255.255.0

192.168.2.0 192.168.1.254 255.255.255.0


将发送到234的数据包,先发送到,1.254

系统:suse 11 Linux
版本:SUSE Linux Enterprise Server 11 (i586)
VERSION = 11
PATCHLEVEL = 0
 
简单介绍一下配置文件方式添加静态路由的方法
 
配置文件路径:vim /etc/sysconfig/network/routes
按以下格式添加内容:
192.168.1.200 192.168.1.1 255.255.255.0 eth2          这是我的36机器,使用了3块网卡,每个网卡的路由配置如下
10.166.173.36 10.166.173.11 255.255.255.0 eth0 
10.10.53.85 10.10.53.81 255.255.255.240 eth1 
default 10.166.173.11 - -                                                      指定“缺省路由”,其实表示3个路由中是优先级最高的1个
 
字段解释
192.168.1.200--->表示本地网卡ip地址(有host or subnetwork之分)
192.168.1.1--->表示网关(下一跳IP)
255.255.255.0--->表示子网掩码(subnetwork) )
eth1--->表示给哪块网卡配路由
default 10.166.173.11 - -  默认网关(缺省路由),也就是你一共配置了3个路由,缺省路由优先级最高
 
特点:执行/etc/init.d/network restart命令让配置生效 或者 service network restart  重新加载网络配置,都要使用root用户
注意在编辑时,不要有空行,不然会出错了.
在配置文件中这样添加静态路由后,主机重启路由配置会自动加载,就不用每次手动添加路由了
 
几种查看路由的命令:
 
(1)ip route   ip与路由映射关系
10.10.53.80/28 dev eth1  proto kernel  scope link  src 10.10.53.85 
10.166.173.0/24 dev eth0  proto kernel  scope link  src 10.166.173.36 
192.168.1.0/24 dev eth2  proto kernel  scope link  src 192.168.1.200 
169.254.0.0/16 dev eth0  scope link 
127.0.0.0/8 dev lo  scope link 
default via 10.166.173.11 dev eth0
 
(2)route      内核路由表
 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.10.53.80       *               255.255.255.240    U     0      0        0 eth1
10.166.173.0     *               255.255.255.0        U     0      0        0 eth0
192.168.1.0       *               255.255.255.0        U     0      0        0 eth2
link-local            *               255.255.0.0             U     0      0        0 eth0
loopback            *               255.0.0.0                  U     0      0        0 lo
default         10.166.173.11   0.0.0.0                UG    0      0        0 eth0
 
(3)route -n   已数字方式显示路由表
 
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.10.53.80     0.0.0.0         255.255.255.240 U     0      0        0 eth1
10.166.173.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
127.0.0.0       0.0.0.0         255.0.0.0       U     0      0        0 lo
0.0.0.0         10.166.173.11   0.0.0.0         UG    0      0        0 eth0
 
(4) netstat -rn   人性化显示路由表
 
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
10.10.53.80     0.0.0.0         255.255.255.240 U         0 0          0 eth1
10.166.173.0    0.0.0.0         255.255.255.0   U         0 0          0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U         0 0          0 eth2
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 eth0
127.0.0.0       0.0.0.0         255.0.0.0       U         0 0          0 lo
0.0.0.0         10.166.173.11   0.0.0.0         UG        0 0          0 eth0
 
实例:
 
数据包转发
132.0.0.0/255.0.0.0  gw set to 10.166.173.16   从这个41采集机上把发送到132.0.0.0这个网段上的数据都指向10.166.173.16地址
 
添加/删除静态路由
命令方式
route add -net 10.10.54.0 netmask 255.255.255.240 gw 10.10.53.81  把发送到目的地10.10.54.0网段的数据包,先转发到10.10.53.81这个下一跳
route add -net 10.10.54.0 netmask 255.255.255.0 gw 10.10.53.81    添加路由
route del -net 10.10.54.0 netmask 255.255.255.240 gw 10.10.53.81  把发送到目的地10.10.54.0网段的数据包,先转发到10.10.53.81这个下一跳
route del -net 10.10.54.0 netmask 255.255.255.0 gw 10.10.53.81    删除路由
 
配置文件:vim /etc/sysconfig/network/routes   以#开始的行是注释,每一行是一个路由记录,由空格分隔的多列组成
    <网关>    <目的网络子网掩码>    <本地网络接口>
192.168.1.200 192.168.1.1 255.255.255.0 eth2
10.166.173.36 10.166.173.11 255.255.255.0 eth0
10.10.53.85 10.10.53.81 255.255.255.240 eth1
10.10.54.0 10.10.53.81 255.255.255.0 eth1
default 10.166.173.11 - -
 
2012.03.19
leonarding
tianjin

阅读(4082) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~