Linux路由表网关全为0意义&路由基本操作 您所在的位置:网站首页 静态路由配置网关怎么设置 Linux路由表网关全为0意义&路由基本操作

Linux路由表网关全为0意义&路由基本操作

2024-06-30 05:31| 来源: 网络整理| 查看: 265

网关0.0.0.0代表该网段属于直连网段,不需要走三层,直接走二层

 如下所示路由表中很多网关为全为0的路由条目

[zyq@zyq ~]$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.0.1 0.0.0.0 UG 600 0 0 wlp3s0 172.16.8.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet1 172.16.176.0 0.0.0.0 255.255.255.0 U 0 0 0 vmnet8 192.168.0.0 0.0.0.0 255.255.255.0 U 600 0 0 wlp3s0 192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr1 192.168.4.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr2 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0 以 192.168.2.0/24 网段为例

路由条目192.168.2.0    0.0.0.0        255.255.255.0  U    0     0       0 virbr1 表示,本机属于192.168.2.0/24 网段,本机通过本机virbr1接口上的地址与192.168.2.0/24 网段的主机通信,路由开销为0(于本机与192.168.2.0/24 网段直连,通过ARP解析通信)。

查看virbr1接口 [zyq@zyq ~]$ ip a ... 4: virbr1: mtu 1500 qdisc noqueue state UP qlen 1000 link/ether 52:54:00:69:7e:a4 brd ff:ff:ff:ff:ff:ff inet 192.168.2.254/24 brd 192.168.2.255 scope global virbr1 valid_lft forever preferred_lft forever ... 查看与之相连主机上的路由条目和接口地址 [root@ct7_node01 ~]# ip a ... 2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 74:52:01:01:01:01 brd ff:ff:ff:ff:ff:ff inet 192.168.2.11/24 brd 192.168.2.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::54fc:ae6:27ee:f265/64 scope link noprefixroute valid_lft forever preferred_lft forever ... [root@ct7_node01 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.122.1 0.0.0.0 UG 101 0 0 eth1 192.168.2.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 ... Linux静态路由基本操作 添加路由 [root@ct7_node01 ~]# route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0 [root@ct7_node01 ~]# route -n Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.122.1 0.0.0.0 UG 101 0 0 eth1 192.56.76.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 192.168.2.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 192.168.122.0 0.0.0.0 255.255.255.0 U 101 0 0 eth1 删除路由 [root@ct7_node01 ~]# route del -net 192.56.76.0 netmask 255.255.255.0 dev eth0 [root@ct7_node01 ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.122.1 0.0.0.0 UG 101 0 0 eth1 192.168.2.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0 192.168.122.0 0.0.0.0 255.255.255.0 U 101 0 0 eth1 路由更多的操作 route add -net 127.0.0.0 netmask 255.0.0.0 dev lo adds the normal loopback entry, using netmask 255.0.0.0 and associated with the "lo" device (assuming this device was previously set up correctly with ifconfig(8)). route add -net 192.56.76.0 netmask 255.255.255.0 dev eth0 adds a route to the local network 192.56.76.x via "eth0". The word "dev" can be omitted here. route del default deletes the current default route, which is labeled "default" or 0.0.0.0 in the destination field of the current routing table. route add default gw mango-gw adds a default route (which will be used if no other route matches). All packets using this route will be gatewayed through "mango-gw". The device which will actually be used for that route depends on how we can reach "mango-gw" - the static route to "mango-gw" will have to be set up before. route add ipx4 sl0 Adds the route to the "ipx4" host via the SLIP interface (assuming that "ipx4" is the SLIP host). route add -net 192.57.66.0 netmask 255.255.255.0 gw ipx4 This command adds the net "192.57.66.x" to be gatewayed through the former route to the SLIP interface. route add -net 224.0.0.0 netmask 240.0.0.0 dev eth0 This is an obscure one documented so people know how to do it. This sets all of the class D (multicast) IP routes to go via "eth0". This is the correct normal configuration line with a multicasting kernel. route add -net 10.0.0.0 netmask 255.0.0.0 reject This installs a rejecting route for the private network "10.x.x.x."

相关路由参数

Flags  

        U(开启路由)

        G(使用网关)

Metric 到目标网段的距离(通常代表有多少跳),最新的kernel已弃用这个参数,但是路由守护进程可能会用到。

Ref 对该路由的引用数(在 Linux 内核中未使用)

Use 系统查找本条路由的次数进行计数。 根据 -F 和 -C 的使用,这将是路由缓存未命中 (-F) 或命中 (-C)。

相关路由参数原文

Flags  Possible flags include        U (route is up)        H (target is a host)        G (use gateway)        R (reinstate route for dynamic routing)        D (dynamically installed by daemon or redirect)        M (modified from routing daemon or redirect)        A (installed by addrconf)        C (cache entry)        !  (reject route)

Metric The 'distance' to the target (usually counted in hops). It is not used by recent kernels, but may be needed by routing daemons.

Ref    Number of references to this route. (Not used in the Linux kernel.)Use   Count of lookups for the route.  Depending on the use of -F and -C this will be either route cache misses (-F) or hits (-C).



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有