我想知道是否可以在 cli 命令的輸出中重新排序介面的順序:
ip address
接口的列出順序是在哪裡定義的?
我有 13 個接口,包括橋接接口和 VLAN 接口。
他們的順序是任意的,我想改變這一點。
我使用“網路管理器”和“進階網路配置”工具進行設定。
答案1
它來自/proc/net/dev
。例如:
alan@earth:~$ ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether d0:bf:9c:45:77:40 brd ff:ff:ff:ff:ff:ff
altname enp3s0f0
inet 192.168.0.104/24 metric 100 brd 192.168.0.255 scope global dynamic eno1
valid_lft 5991sec preferred_lft 5991sec
inet6 fe80::d2bf:9cff:fe45:7740/64 scope link
valid_lft forever preferred_lft forever
3: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether d0:bf:9c:45:77:41 brd ff:ff:ff:ff:ff:ff
altname enp3s0f1
alan@earth:~$ cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 1070507017 9072512 0 0 0 0 0 0 1070507017 9072512 0 0 0 0 0 0
eno1: 1669873916763 1133028998 0 2042363 0 0 0 8542737 57824815006 320245927 0 0 0 0 0 0
eno2: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 核心本身以net/core/net-procfs.c
.查看來源這裡。這是片段。
static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
{
struct rtnl_link_stats64 temp;
const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
"%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
dev->name, stats->rx_bytes, stats->rx_packets,
stats->rx_errors,
stats->rx_dropped + stats->rx_missed_errors,
stats->rx_fifo_errors,
stats->rx_length_errors + stats->rx_over_errors +
stats->rx_crc_errors + stats->rx_frame_errors,
stats->rx_compressed, stats->multicast,
stats->tx_bytes, stats->tx_packets,
stats->tx_errors, stats->tx_dropped,
stats->tx_fifo_errors, stats->collisions,
stats->tx_carrier_errors +
stats->tx_aborted_errors +
stats->tx_window_errors +
stats->tx_heartbeat_errors,
stats->tx_compressed);
}