目录

网络工具

net-tools 与 iproute2

net-tools 起源于BSD,自2001年起,Linux社区已经对其停止维护,net-tools通过procfs(/proc)和ioctl系统调用去访问和改变内核网络配置。

而iproute2旨在取代net-tools,并提供了一些新功能。一些Linux发行版已经停止支持net-tools,只支持iproute2。而iproute2则通过netlink套接字接口与内核通讯。

net-tools中工具的名字比较杂乱,而iproute2则相对整齐和直观,基本是ip命令加后面的子命令。

虽然取代意图很明显,但是这么多年过去了,net-tool依然还在被广泛使用,最好还是两套命令都掌握吧。

Ip地址

$ ip addr          
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: enp4s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 04:d4:c4:ec:c0:80 brd ff:ff:ff:ff:ff:ff
    inet 192.168.31.124/24 brd 192.168.31.255 scope global dynamic noprefixroute enp4s0
       valid_lft 34381sec preferred_lft 34381sec
    inet6 fe80::e06f:1aaa:46c9:9e83/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
$ ifconfig 
enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.124  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::e06f:1aaa:46c9:9e83  prefixlen 64  scopeid 0x20<link>
        ether 04:d4:c4:ec:c0:80  txqueuelen 1000  (以太网)
        RX packets 9406930  bytes 10365285165 (10.3 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 6361476  bytes 3426976663 (3.4 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (本地环回)
        RX packets 5121031  bytes 6933226725 (6.9 GB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 5121031  bytes 6933226725 (6.9 GB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0