如何重新排序“ip 地址”的输出?

如何重新排序“ip 地址”的输出?

我想知道是否可以重新排序 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);
}

相关内容