1、linux中的静态路由
方法一:
添加路由
route add -net 192.168.0.0/24 gw 192.168.0.1
route add -host 192.168.1.1 dev 192.168.0.1
删除路由
route del -net 192.168.0.0/24 gw 192.168.0.1
add
增加路由
del
删除路由
-net
设置到某个网段的路由
-host
设置到某台主机的路由
gw
出口网关
IP
地址
dev
出口网关
物理设备名
增
加默认路由
route add default gw 192.168.0.1
默认路由一条就够了
route -n
查看路由表
方法二:
添加路由
ip route add 192.168.0.0/24 via 192.168.0.1
ip route add 192.168.1.1 dev 192.168.0.1
删除路由
ip route del 192.168.0.0/24 via 192.168.0.1
add
增加路由
del
删除路由
via
网关出口
IP
地址
dev
网关出口
物理设备名
增加默认路由
ip route add default via 192.168.0.1 dev eth0
via 192.168.0.1
是我的默认路由器
查看路由信息
ip route
如加入:
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
2、zebra路由工具简介
可使用zebra工具配置静态和动态路由,rpm装完后,可用vtysh登陆,进行模拟路由器
在linux上常见的路由服务是由zebra提供的
Zebra支持 ripv1,ripv2,ospf,bgp等路由协议
Zebra下载链接
http://rpmfind.net/linux/rpm2html/search.php?query=zebra
3、使用zebra配置动态路由
常规方法:rpm -ivh zebra*.rpm
基于ospf的配置
#cd /etc/zebra
#touch ospfd.conf
#/etc/rc.d/init.d/zebra start 启动zebra这个服务
#/etc/rc.d/init.d/ospfd start 启动ospfd
好了,目前能登陆路由
#vtysh
如果按”?”键列出的内容,能查看相关命令。
键入"enable" 进入终极模式,此时提示符的 ">" 会变成 "#"
#configure terminal 目前进入设置模式
提示会变成类似 localhost(config)# ,就表示进入了设置模式了。
输入命令:interface eth0
提示会变成类似 localhost(config-if)#
目前就能设置第一张网卡了,
localhost(config-if)# ip address 192.168.1.166/24
(默认此网卡是死的,需要手动激活才能使用)
localhost(config-if)# no shutdown #这就是激活了。
localhost(config-if)# exit #推出eth0的设置
设置第二张网卡
localhost(config)# interface eth1
localhost(config-if)# ipadress 192.168.4.4/24
localhost(config-if)# no shutdown
localhost(config-if)# exit
接着就是设置协议
localhost(config)# router ospf
显示“localhost(config-router)# ” 接着输入命令
localhost(config-router)# network 192.168.1.0/24 area 1
localhost(config-router)# network 192.168.4.0/24 area 1
以上是指定区域为 “1”区
localhost(config-router)# end
结束设置
然后复制一个文件
localhost# copy running-config startup-config
查看路由的信息能使用:show running-config
显示路由器学习路由知识情况用:show ip route
好了,这样就完成1和4 网段之间的动态路由了,如有更多网段,则在设置网卡的步骤中多
添加几个相似的设置就能了。
下面是基于rip的设置:
几乎所有步骤都相同
#cd /etc/zebra
#touch ripd.conf
#/etc/rc.d/init.d/zebra start 启动zebra这个服务
#/etc/rc.d/init.d/ripd start 启动ospfd
好了,目前能登陆路由
#vtysh,其他的和路由器一样
输入命令:interface eth0
目前设置第一张网卡
localhost(config-if)# ip address 192.168.1.166/24
localhost(config-if)# no shutdown
localhost(config-if)# exit
设置第二张网卡
localhost(config)# interface eth1
localhost(config-if)# ipadress 192.168.4.4/24
localhost(config-if)# no shutdown
localhost(config-if)# exit
设置协议
localhost(config)# router rip
localhost(config-router)# network 192.168.1.0/24
localhost(config-router)# network 192.168.4.0/24
localhost(config-router)# version 2
localhost(config-router)# end
结束设置
然后复制一个文件
localhost# copy running-config startup-config
查看路由的信息能使用:show running-config
显示路由器学习路由知识情况用:show ip route
4、Zebe的文件
/etc/logrotate.d/zebra
/etc/pam.d/zebra
/etc/rc.d/init.d/bgpd
/etc/rc.d/init.d/mplsd
/etc/rc.d/init.d/ospf6d
/etc/rc.d/init.d/ospfd
/etc/rc.d/init.d/ripd
/etc/rc.d/init.d/ripngd
/etc/rc.d/init.d/zebra
/etc/zebra
/etc/zebra/bgpd.conf
/etc/zebra/mplsd.conf
/etc/zebra/ospf6d.conf
/etc/zebra/ospfd.conf
/etc/zebra/ripd.conf
/etc/zebra/ripngd.conf
/etc/zebra/vtysh.conf
/etc/zebra/zebra.conf
/usr/bin/vtysh
/usr/sbin/bgpd
/usr/sbin/mplsd
/usr/sbin/ospf6d
/usr/sbin/ospfd
/usr/sbin/ripd
/usr/sbin/ripngd
/usr/sbin/zebra
/usr/share/doc/zebra-0.94
/usr/share/doc/zebra-0.94/AUTHORS
/usr/share/doc/zebra-0.94/COPYING
/usr/share/doc/zebra-0.94/ChangeLog
/usr/share/doc/zebra-0.94/INSTALL
/usr/share/doc/zebra-0.94/NEWS
/usr/share/doc/zebra-0.94/README
/usr/share/doc/zebra-0.94/REPORTING-BUGS
/usr/share/doc/zebra-0.94/SERVICES
/usr/share/doc/zebra-0.94/TODO
/usr/share/doc/zebra-0.94/bgpd.conf.sample
/usr/share/doc/zebra-0.94/bgpd.conf.sample2
/usr/share/doc/zebra-0.94/mplsd.conf.sample
/usr/share/doc/zebra-0.94/ospf6d.conf.sample
/usr/share/doc/zebra-0.94/ospfd.conf.sample
/usr/share/doc/zebra-0.94/ripd.conf.sample
/usr/share/doc/zebra-0.94/ripngd.conf.sample