参考文章:
- Linux下使用Quagga搭建软路由-OSPFv2学习
- 鳥哥的 Linux 私房菜
一 路由设置
1. 参数说明
root@anzye:# route -n
内核 IP 路由表
目标 网关 子网掩码 标志 跃点 引用 使用 接口
0.0.0.0 192.168.2.254 0.0.0.0 UG 600 0 0 wlan0
10.42.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 wlan0
192.168.1.0 10.42.0.232 255.255.255.0 UG 20 0 0 eth1
192.168.2.0 0.0.0.0 255.255.255.0 U 600 0 0 wlan0
192.168.213.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet1
|
|
输出项 |
说明 |
Destination |
目标网段或者主机 |
Gateway |
网关地址,”*” 表示目标是本主机所属的网络,不需要路由 |
Genmask |
网络掩码 |
Flags |
标记 |
Metric |
路由距离,到达指定网络所需的中转数(linux 内核中没有使用) |
Ref |
路由项引用次数(linux 内核中没有使用) |
Use |
此路由项被路由软件查找的次数 |
Iface |
该路由表项对应的输出接口 |
一些可能的标记如下:
- U : Up表示此路由当前为启动状态
- H :表示此网关为一主机
- G :Gateway,表示此网关为一路由器
- R : Reinstate Route,使用动态路由重新初始化的路由
- D : Dynamically,此路由是动态性地写入
- M : Modified,此路由是由路由守护程序或导向器动态修改
- ! :表示此路由当前为关闭状态
2 查询设置
root@anzye:# route -h
用法: route [-nNvee] [-FC] [<AF>] 显示核心路由表
route [-v] [-FC] {add|del|flush} ... 为AF修改路由表。
route {-h|--help} [<AF>] Detailed usage syntax for specified AF.
route {-V|--version} 显示版本和作者信息并退出。
-v, --verbose 显示详细信息
-n, --numeric 不解析名称
-e, --extend 显示更多信息
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-
route -n :不解析名称的查询核心路由表
-
route [add|del] [-net|-host] target/default [netmask Nm] [gw Gw] [[dev] If]
- add : 添加一条路由规则
- del : 删除一条路由规则
- -net : 路由目的地址是一个网络
- -host : 路由目的地址是一个主机
- default: 当主机不能在路由表中查找到目标主机的IP地址或网络路由时,数据包就被发送到其指定的默认路由(默认网关)上,flags标记为G
- target : 目的网络或主机(可直接 使用 target/24 省去后面的netmask)
- netmask : 目的地址的网络掩码
- gw : 路由数据包通过的网关
- dev : 为路由指定的网络接口
二 动态路由的设置
编译安装见上Quagga 移植
具体配置可看参考文章1,以下记几点注意事项
- telnet 127.0.0.1 port (port 2601为zebra配置,2604为ospf配置),若有vtysh可直接使用免区分法不同协议的端口
- 一个路由器一个router-id号,不同router必须不同用以区分。
- 两个路由器直连通的网口必须设成同一网段的,保证可互ping,且在设置ospf的network时,两路由直连的口的network必须相同,包括area值,否则无法获取对方信息,更不用说它下一结点的路由信息了。
- 一个物理网卡下挂多个不同段的虚拟口,与其相连的多张网卡要跑ospf动态路由交换,则必须保证没有相同mac值的网卡。
- 默认分发的路由表是
O>*
标示的条目,自行添加的静态核心路由条目不会分发到其它路由器去,可配置 redistribute kernel项就行如下: anzye@anzye # cat /ospfd.config
router ospf
ospf router-id 192.168.1.52
redistribute kernel
network 192.168.1.0/24 area 0.0.0.1
www.centos.vbird> show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
I - ISIS, B - BGP, > - selected route, * - FIB route
K>* 0.0.0.0/0 via 192.168.1.254, eth0 <==核心直接設定的
C>* 127.0.0.0/8 is directly connected, lo <==介面產生的路由
K>* 169.254.0.0/16 is directly connected, eth1 <==核心直接設定的
C>* 192.168.1.0/24 is directly connected, eth0 <==介面產生的路由
C>* 192.168.100.0/24 is directly connected, eth1 <==介面產生的路由
K :代表以類似 route 指令加入核心的路由規則,包括 route-ethN 所產生的規則;
C :代表由你的網路介面所設定的 IP 而產生的相關的路由規則
S :以 zebra 功能所設定的靜態路由資訊;
R :就是透過 RIP 協定所增加的路由規則囉!
- 在设置时有不懂的命令直接在命令后按?如
anzye# show ip route
<cr>
A.B.C.D Network in the IP routing table to display
A.B.C.D/M IP prefix <network>/<length>, e.g., 35.0.0.0/8
babel Babel routing protocol (Babel)
bgp Border Gateway Protocol (BGP)
connected Connected routes (directly attached subnet or host)
isis Intermediate System to Intermediate System (IS-IS)
kernel Kernel routes (not installed via the zebra RIB)
nhrp Next Hop Resolution Protocol (NHRP)
ospf Open Shortest Path First (OSPFv2)
pim Protocol Independent Multicast (PIM)
rip Routing Information Protocol (RIP)
static Statically configured routes
summary Summary of all routes
supernets-only Show supernet entries only
tag Show only routes with tag
vrf Specify the VRF
- 有问题看log文件吧
实验
在一台机器上使用route增加一条路由信息如route add -net 192.168.3.0/24 eth0
在另一台机器上route -n/ip router show即可看到自动增加到本地路由表了,更详细的描述使用quagga的相关命令查询