1、添加静态路由命令
添加一条到主机192.168.168.110的路由(通过eth0)
[root@localhost ~]# route add -host 192.168.1.110 dev eth0
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.110 * 255.255.255.255 UH 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
添加一条到主机192.168.168.110的路由(通过ip192.168.1.143)
[root@localhost ~]# route add -host 192.168.168.110 gw 192.168.1.143
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.110 * 255.255.255.255 UH 0 0 0 eth0
192.168.168.110 192.168.1.143 255.255.255.255 UGH 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 1 0 0 eth0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
添加到网络的路由(通过eth0)
[root@localhost ~]# route add -net 192.168.1.0 netmask 255.255.255.0 dev eth0
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.110 * 255.255.255.255 UH 0 0 0 eth0
192.168.168.110 192.168.1.143 255.255.255.255 UGH 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
添加到网络的路由(通过ip192.168.1.1)
[root@localhost ~]# route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.1.1
[root@localhost ~]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.110 * 255.255.255.255 UH 0 0 0 eth0
192.168.168.110 192.168.1.143 255.255.255.255 UGH 0 0 0 eth0
192.168.100.0 192.168.1.1 255.255.255.0 UG 0 0 0 eth0
192.168.1.0 * 255.255.255.0 U 0 0 0 eth0
192.168.122.0 * 255.255.255.0 U 0 0 0 virbr0
default 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
Destination表示路由的目标IP地址
Gateway表示网关使用的主机名或者是IP地址。上面输出的"*"表示没有网关
Genmask表示路由的网络掩码
Flags是表示路由的标志。可用的标志及其意义是:U表示路由在启动,H表示target是一台主机,G表示使用网关,R表示对动态路由进行复位设置;D表示动态安装路由,M表示修改路由,!表示拒绝路由。
Metric表示路由的单位开销量
Ref表示依赖本路由现状的其它路由数目
Use表示路由表条目被使用的数目
Iface表示路由所发送的包的目的网络
以上形式添加路由系统重启后会失效,要永久生效的话,编辑/etc/sysconfig/network-scripts/route-eth0文件。
[root@localhost ~]# vim /etc/sysconfig/network-scripts/route-eth0
192.168.1.0 via 192.168.1.143