Linux中配置路由使用route命令
查看路由表
[root@centos7 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.0.2 0.0.0.0 UG 100 0 0 eth0
10.0.0.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
UG:Up Gateway,网关并且UP
GH:Up Host,主机路由并且UP
route的使用
格式:route [add|del] [-host|-net|default] [address/mask] [gw] [dev]
add | del:增加或者删除路由条目
-host:主机路由
-net:网络路由
default:默认路由
gw:下一跳地址,前提是可达
dev:出接口
主机路由:具体到某台主机如何走
去往1.1.1.1的主机从eth0发出去
[root@centos7 ~]# route add -host 1.1.1.1/32 dev eth0
去往1.1.1.1的主机交个下一跳10.0.0.2发出
[root@centos7 ~]# route add -host 1.1.1.1/32 gw 10.0.0.2
网络路由:指明到该网络是如何走
去往1.1.1.0/24的网络从eth0发出去
[root@centos7 ~]# route add -host 1.1.1.0/24 dev eth0
去往