(两百八十三)Ip命令学习

1.基础知识补充

ip段/数字-如192.168.0.1/24是什么意思?
后面这个数字标示了我们的网络号的位数,也就是子网掩码中前多少号为1

129.168.1.1 /24 这个24就是告诉我们网络号是24位

也就相当于告诉我们了

子网掩码是:11111111 11111111 11111111 00000000

ip后面的/+数字表示的是ip的网络号位数

       Route tables: Linux-2.x can pack routes into several routing tables identified by a number in the range from 1 to 2^31 or by name from the file /etc/iproute2/rt_tables By default all normal
       routes are inserted into the main table (ID 254) and the kernel only uses this table when calculating routes.  Values (0, 253, 254, and 255) are reserved for built-in use.

       Actually, one other table always exists, which is invisible but even more important. It is the local table (ID 255). This table consists of routes for local and broadcast addresses. The ker‐
       nel maintains this table automatically and the administrator usually need not modify it or even look at it.

       The multiple routing tables enter the game when policy routing is used.

路由表:比如下面是wlan0这张路由表的内容,路由规则由等级从高到低的很多路由表组成

1|raphael:/ # ip route list table wlan0                                                                                                                                                                    
default via 192.168.0.1 dev wlan0 proto static 
192.168.0.0/24 dev wlan0 proto static scope link 
 

raphael:/ # ip rule
0:    from all lookup local 
10000:    from all fwmark 0xc0000/0xd0000 lookup legacy_system 
10500:    from all iif lo oif dummy0 uidrange 0-0 lookup dummy0 
10500:    from all iif lo oif rmnet_data0 uidrange 0-0 lookup rmnet_data0 
10500:    from all iif lo oif wlan0 uidrange 0-0 lookup wlan0 
13000:    from all fwmark 0x10063/0x1ffff iif lo lookup local_network 
13000:    from all fwmark 0xd0001/0xdffff iif lo lookup rmnet_data0 
13000:    from all fwmark 0x1007b/0x1ffff iif lo lookup wlan0 
14000:    from all iif lo oif dummy0 lookup dummy0 
14000:    from all fwmark 0xc0000/0xc0000 iif lo oif rmnet_data0 lookup rmnet_data0 
14000:    from all iif lo oif wlan0 lookup wlan0 
15000:    from all fwmark 0x0/0x10000 lookup legacy_system 
16000:    from all fwmark 0x0/0x10000 lookup legacy_network 
17000:    from all fwmark 0x0/0x10000 lookup local_network 
19000:    from all fwmark 0x7b/0x1ffff iif lo lookup wlan0 
22000:    from all fwmark 0x0/0xffff iif lo lookup wlan0 
32000:    from all unreachable
 

 

2. ip rule

       ip rule manipulates rules in the routing policy database control the route selection algorithm.

ip rule 操控控制路由选择算法的路由策略数据库,简单来说就是控制路由选择。

       Classic routing algorithms used in the Internet make routing decisions based only on the destination address of packets (and in theory, but not in practice, on the TOS field).

经典的路由选择算法是根据包的目的地

       In some circumstances we want to route packets differently depending not only on destination addresses, but also on other packet fields: source address, IP protocol, transport protocol ports
       or even packet payload.  This task is called 'policy routing'.

在一些情况下我们想根据其他一些包的参数,发送地址、ip协议、端口或者包的承载状况来路由包。

       To solve this task, the conventional destination based routing table, ordered according to the longest match rule, is replaced with a 'routing policy database' (or RPDB), which selects routes
       by executing some set of rules.

传统的规则由路由策略数据库代替。

       Each policy routing rule consists of a selector and an action predicate.  The RPDB is scanned in order of decreasing priority. The selector of each rule is applied to {source address, desti‐
       nation address, incoming interface, tos, fwmark} and, if the selector matches the packet, the action is performed. The action predicate may return with success.  In this case, it will either
       give a route or failure indication and the RPDB lookup is terminated. Otherwise, the RPDB program continues with the next rule.

每条规则包含一个选择器和一个动作谓语。数据库以优先级降序查询来匹配所有参数规则。

       Semantically, the natural action is to select the nexthop and the output device.

       At startup time the kernel configures the default RPDB consisting of three rules:

       1.     Priority: 0, Selector: match anything, Action: lookup routing table local (ID 255).  The local table is a special routing table containing high priority control routes for local and
              broadcast addresses.

              Rule 0 is special. It cannot be deleted or overridden.

       2.     Priority: 32766, Selector: match anything, Action: lookup routing table main (ID 254).  The main table is the normal routing table containing all non-policy routes. This rule may be
              deleted and/or overridden with other ones by the administrator.

       3.     Priority: 32767, Selector: match anything, Action: lookup routing table default (ID 253).  The default table is empty. It is reserved for some post-processing if no previous default
              rules selected the packet.  This rule may also be deleted.

       Each RPDB entry has additional attributes. F.e. each rule has a pointer to some routing table. NAT and masquerading rules have an attribute to select new IP address to translate/masquerade.
       Besides that, rules have some optional attributes, which routes have, namely realms.  These values do not override those contained in the routing tables. They are only used if the route did
       not select any attributes.
 

那理解下下面的路由规则,前面序号代表优先级,from all 不知道是啥,iif/ofi/fwmark/uidrange应该都是匹配条件,loockup + xxx应该是指查询某张表

raphael:/ # ip rule
0:	from all lookup local 
10000:	from all fwmark 0xc0000/0xd0000 lookup legacy_system 
10500:	from all iif lo oif dummy0 uidrange 0-0 lookup dummy0 
10500:	from all iif lo oif rmnet_data0 uidrange 0-0 lookup rmnet_data0 
10500:	from all iif lo oif wlan0 uidrange 0-0 lookup wlan0 
13000:	from all fwmark 0x10063/0x1ffff iif lo lookup local_network 
13000:	from all fwmark 0xd0001/0xdffff iif lo lookup rmnet_data0 
13000:	from all fwmark 0x1007b/0x1ffff iif lo lookup wlan0 
14000:	from all iif lo oif dummy0 lookup dummy0 
14000:	from all fwmark 0xc0000/0xc0000 iif lo oif rmnet_data0 lookup rmnet_data0 
14000:	from all iif lo oif wlan0 lookup wlan0 
15000:	from all fwmark 0x0/0x10000 lookup legacy_system 
16000:	from all fwmark 0x0/0x10000 lookup legacy_network 
17000:	from all fwmark 0x0/0x10000 lookup local_network 
19000:	from all fwmark 0x7b/0x1ffff iif lo lookup wlan0 
22000:	from all fwmark 0x0/0xffff iif lo lookup wlan0 
32000:	from all unreachable

iif/ofi/fwmark/uidrange

              iif NAME
                     select the incoming device to match. If the interface is loopback, the rule only matches packets originating from this host. This means that you may create separate routing
                     tables for forwarded and local packets and, hence, completely segregate them.

              oif NAME
                     select the outgoing device to match. The outgoing interface is only available for packets originating from local sockets that are bound to a device.

              tos TOS

              dsfield TOS
                     select the TOS value to match.

              fwmark MARK
                     select the fwmark value to match.
 

待续:fwmark是怎么实现的

 

3.路由表

1|raphael:/ # ip route list table wlan0                                                                                                                                                                    
default via 192.168.0.1 dev wlan0 proto static 
192.168.0.0/24 dev wlan0 proto static scope link 

192.168.0.1是网关

下面是子网ip范围么,意思是啥呢,猜测是WiFi waln0的包都从网关走么

待续:含义查下资料

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值