智传网优云课堂,专注分享IT技术
与IT技术爱好者一起共同学习进步

Linux net-tools与iproute2对比与区别

前言

本文主要介绍net-tools套件与iproute2套件的区别。

net-tools套件与iproute2套件的区别

ifconfig、route、arp和netstat等命令行工具都是net-toos套件的工具集,用于解决网络故障。net-tools起源于BSD的TCP/IP工具箱,后来成为老版本Linux内核中配置网络功能的工具。但自2001年起,Linux社区已经对其停止维护。同时,一些Linux发行版比如Arch Linux和CentOS/RHEL 7则已经完全抛弃了net-tools,只支持iproute2。

iproute2的出现旨在从功能上取代net-tools。net-tools通过procfs(/proc)和ioctl系统调用去访问和改变内核网络配置,而iproute2则通过netlink套接字接口与内核通讯。抛开性能而言,iproute2的用户接口比net-tools显得更加直观。比如,各种网络资源(如link、IP地址、路由和隧道等)均使用合适的对象抽象去定义,使得用户可使用一致的语法去管理不同的对象。到目前为止,iproute2仍处在持续开发中。

笔者强烈建议用户应该使用iproute2取代传统的net-tools套件,因为iproute2可以做很多net-tools无法做到的事情。

两者常见命令对比

net-tools iproute2 命令作用
arp -na ip neigh 查看MAC地址表
ifconfig ip link 查看网卡基本信息
ifconfig -a ip addr show 查看网站详细信息
ifconfig –help ip help 查看帮助信息
ifconfig -s ip -s link 查看网卡流量传输信息
ifconfig eth0 up ip link set eth0 up 启用网卡
ipmaddr ip maddr 查看网卡相关的MAC地址表
iptunnel ip tunnel 查看隧道信息
netstat ss 查看端口使用情况
netstat -i ip -s link 查看每张网卡的信息及传输信息
netstat -g ip maddr 查看张网卡的二层及三层邻居信息
netstat -l ss -l 查看本机的监听端口
netstat -r ip route 查看本机路由表
route add ip route add 添加静态路由
route del ip route del 删除静态路由
route -n ip route show 查看本机路由表
vconfig ip link 查看本地连接情况

Linux查看MAC地址表

oucanrong@zcwyou:~$ arp -na

? (172.16.87.174) 位于 00:0c:29:2a:8e:23 [ether] 在 vmnet8
? (172.16.87.170) 位于 在 vmnet8
? (172.16.87.179) 位于 00:0c:29:2a:8e:23 [ether] 在 vmnet8
? (192.168.42.129) 位于 da:1a:b5:a1:93:bc [ether] 在 enp0s20u1

查看网卡基本信息

oucanrong@zcwyou:~$ ip link

查看网卡基本信息

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp0s25: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
link/ether 3c:97:0e:43:e8:bd brd ff:ff:ff:ff:ff:ff
3: wlp3s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN mode DORMANT group default qlen 1000
link/ether 60:67:20:c7:be:00 brd ff:ff:ff:ff:ff:ff
4: vmnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 1000
link/ether 00:50:56:c0:00:01 brd ff:ff:ff:ff:ff:ff
5: vmnet8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 1000
link/ether 00:50:56:c0:00:08 brd ff:ff:ff:ff:ff:ff
12: enp0s20u1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 1000
link/ether c6:34:99:3e:12:f9 brd ff:ff:ff:ff:ff:ff

Linux 查看ip 命令帮助信息

oucanrong@zcwyou:~$ ip help

Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
where OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |
vrf | sr }
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec |
-f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
-4 | -6 | -I | -D | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } | -br[ief] |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch][filename] |
-rc[vbuf][size] | -n[etns] name | -a[ll] | -c[olor]}

Linux查看网卡流量传输信息

Linux查看网卡流量传输信息

[root@zcwyou ~]# ip -s link

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
300977974 305919 0 0 0 0
TX: bytes packets errors dropped carrier collsns
300977974 305919 0 0 0 0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1400 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether fa:16:3e:48:b5:08 brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
107994934 965313 0 0 0 0
TX: bytes packets errors dropped carrier collsns
714725526 808580 0 0 0 0

赞(0)
未经允许不得转载:Linux入门学习到精通 » Linux net-tools与iproute2对比与区别
分享到: 更多 (0)

学习QQ群:557371664

关注微信公众号自助视频学习

评论 抢沙发

评论前必须登录!