博文背景

想知道ip a命令的输出都是什么意思,过于简单的如mtu、mac地址和广播地址我就不解释了

具体操作

重要文档
https://baturin.org/docs/iproute2/
http://web.archive.org/web/20220807073512/http://www.policyrouting.org/iproute2.doc.html
https://lartc.org/howto/

详解开始

ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:34:c3:3b brd ff:ff:ff:ff:ff:ff
    altname enp2s1
    inet 192.168.8.128/24 metric 100 brd 192.168.8.255 scope global dynamic ens33
       valid_lft 1025sec preferred_lft 1025sec
    inet6 fe80::20c:29ff:fe34:c33b/64 scope link
       valid_lft forever preferred_lft forever

尖括号里面有up并且后面的state也有up那么为什么会有两个up呢?

请看https://superuser.com/questions/1463162/unknown-state-of-network-interface

这里提到网卡分为管理状态和运行状态

为了方便理解,我们断开虚拟机的网卡连接

vmware adapter

查看网卡状态

state down

会发现左边是up但是右边是down的状态

NO_CARRIER(大写)是一条从调制解调器发送到它所连接的设备(通常是计算机)的短信,表明调制解调器没有(或不再)连接到远程系统。

参考 https://en.wikipedia.org/wiki/NO_CARRIER

尖括号里面的东西叫网络设备的状态标识(net_device_flags)

参考 https://man7.org/linux/man-pages/man7/netdevice.7.html

BROADCAST:表示网卡有广播地址
MULTICAST:表示网卡可以发送多播包
UP:表示网卡处于启动的状态
LOWER_UP:网卡连接正常,就是网卡已经上电

参考 https://www.cnblogs.com/qgdtq/p/15350333.html

group指的是Link groups are similar to port ranges found in managed switches. You can add network interfaces to a numbered group and perform operations on all the interfaces from that group at once.Links not assigned to any group belong to group 0 (“default”).

参考 https://baturin.org/docs/iproute2/#ip-link-group

qdisc和qlen指的是Linux 操作系统中的流量控制器 TC (Traffic Control) 用于Linux内核的流量控制,它规定建立处理数据包的队列,并定义队列中的数据包被发送的方式,从而实现对流量的控制。qdisc(队列规则,queueing discipline)是 Linux 流量控制系统的核心。实际就是一个队列上面附加的排队规则,下文有时也直接称为队列。
qdisc其实就是一个调度器,每个网络接口都会有一个调度器,qdisc会根据调度器的规则重新排列数据包进入队列的顺序。qlen我暂且简单理解成队列的长度,可能有误,读者自行斟酌。
请看 https://blog.csdn.net/qq_44577070/article/details/123967699
参考 https://tldp.org/en/Traffic-Control-HOWTO/ar01s04.html

inet指的是Internet protocol family
参考 https://unix.stackexchange.com/questions/545462/what-does-inet-stand-for-in-the-ip-utility

link/loopback和link/ether指的应该就是网卡类型,具体没有找到权威解释

scope指的是

Scope | Description
global | valid everywhere
site | valid only within this site (IPv6)
link | valid only on this device
host | valid only inside this host (machine)

Scope is normally determined by the ip utility without explicit use on the command line. (…)

The scope of a route in Linux is an indicator of the distance to the destination network. The scope of an IP address is an indicator of how far from the local host the address is known, which, to some extent also tells you how far the owner of that address is from the local host (…).

Host: An address has a host scope when it is used only to communicate within the host itself. Outside the host this address is not known and can not be used. An Example is the loopback address, 127.0.0.1

Link: An address has a link scope when it is meaningful and can be used only within a LAN. An example is a subnet’s broadcast address.

Global: An address has global scope when it can be used anywhere. This is the default scope for most addresses. (…)

The main reason to use scopes seems to be that a host with multiple interfaces and addresses has to decide when to use which address. For communication with itself a loopback address (scope host) can be used. With communication elswhere, a different address has to be selected.

参考 https://serverfault.com/questions/63014/ip-address-scope-parameter

vaild_lft和preferred_lft指的是
Autoconfigured IPv6 global unicast addresses acquire their valid and preferred lifetime assignments from RAs. A valid lifetime is the time period during which an address is allowed to remain available and usable on an interface. A preferred lifetime is the length of time an address is intended for full use on an interface, and must be less than or equal to the address’s valid lifetime.
参考 https://techhub.hpe.com/eginfolib/networking/docs/switches/WB/16-01/5200-0135_wb_2920_ipv6/content/ch01s15.html

虽然针对ipv6的,但是有时候ipv4也会出现这玩意,有关ipv4我没找到详细资料但道理应该差不多。
根据 https://phoenixnap.com/blog/ipv4-vs-ipv6 显示对于ipv4这个概念并不适用。

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐