CentOS下TCP/IP网络管理工具:net-tools VS iproute2

Blog:http://www.simlinux.com

许多系统管理员仍然使用ifconfig、route、arp、netstat 命令组合来管理和排错网络配置,这些命令有net-tools包提供,但在Arch Linux、Centos7/RHEL7等发行版里面已经使用iproute2替代了net-toolsiproute2是另外一个网络配置工具,用来取代net-tools的功能;

net-tools访问和修改网络配置是通过procfs(/proc)和ioctl系统调用来完成的,而iproute2是通过netlink socket方式与内核通信;重要的是,iproute2发展一直很好:
https://www.kernel.org/pub/linux/utils/net/iproute2/
下面是net-tools和iproute2的使用对比:

列出所有网络接口(包括没有激活的网卡)

使用net-tools: $ifconfig-a 使用iproute2: $iplinkshow

CentOS下TCP/IP网络管理工具:net-tools VS iproute2

激活和关闭网卡

使用net-tools: $sudoifconfigeth1up $sudoifconfigeth1down 使用iproute2: $sudoiplinksetdowneth1 $sudoiplinksetupeth1

配置IPv4地址

使用net-tools: $sudoifconfigeth110.0.0.1/24 使用iproute2: $sudoipaddradd10.0.0.1/24deveth1 使用net-tools配置多IP: $sudoifconfigeth0:1192.168.10.10netmask255.255.255.0up $sudoifconfigeth0:2192.168.10.15netmask255.255.255.0up 使用iproute2配置多IP: $sudoipaddradd10.0.0.1/24broadcast10.0.0.255deveth1 $sudoipaddradd10.0.0.2/24broadcast10.0.0.255deveth1 $sudoipaddradd10.0.0.3/24broadcast10.0.0.255deveth1 查看eth0的IP地址 $sudoipaddrlistdeveth0

移除网卡上的IPv4地址

使用net-tools: $sudoifconfigeth10 使用iproute2: $sudoipaddrdel10.0.0.1/24deveth1

查看网卡上配置的IPv4地址

使用net-tools: $ifconfigeth1 使用iproute2: $ipaddrshowdeveth1 如果是网卡绑定了多IP的话,iproute2能显示所有的地址,而net-tools只能显示一个

CentOS下TCP/IP网络管理工具:net-tools VS iproute2

配置IPv6地址

使用net-tools: $sudoifconfigeth1inet6add2002:0db5:0:f102::1/64 $sudoifconfigeth1inet6add2003:0db5:0:f102::1/64 使用iproute2: $sudoip-6addradd2002:0db5:0:f102::1/64deveth1 $sudoip-6addradd2003:0db5:0:f102::1/64deveth1

查看网卡上配置的IPv6地址

使用net-tools: $ifconfigeth1 使用iproute2: $ip-6addrshowdeveth1

CentOS下TCP/IP网络管理工具:net-tools VS iproute2

移除网卡上的IPv6地址

使用net-tools: $sudoifconfigeth1inet6del2002:0db5:0:f102::1/64 使用iproute2: $sudoip-6addrdel2002:0db5:0:f102::1/64deveth1

更改网卡MAC地址

使用net-tools: $sudoifconfigeth1hwether08:00:27:75:2a:66 使用iproute2: $sudoiplinksetdeveth1address08:00:27:75:2a:67

查看路由表

使用net-tools: $route-n $netstat-rn 使用iproute2: $iprouteshow

CentOS下TCP/IP网络管理工具:net-tools VS iproute2

添加修改默认路由

使用net-tools: $sudorouteadddefaultgw192.168.1.2eth0 $sudoroutedeldefaultgw192.168.1.1eth0 使用iproute2: $sudoiprouteadddefaultvia192.168.1.2deveth0 $sudoiproutereplacedefaultvia192.168.1.2deveth0

添加和删除静态路由

使用net-tools: $sudorouteadddefaultgw192.168.1.2eth0 $sudoroutedeldefaultgw192.168.1.1eth0 使用iproute2: $sudoiprouteadddefaultvia192.168.1.2deveth0 $sudoiproutereplacedefaultvia192.168.1.2deveth0

查看socket统计

使用net-tools: $netstat $netstat-l 使用iproute2: $ss $ss-l

CentOS下TCP/IP网络管理工具:net-tools VS iproute2

查看ARP表

使用net-tools: $arp-an 使用iproute2: $ipneigh

CentOS下TCP/IP网络管理工具:net-tools VS iproute2

添加和删除静态ARP

使用net-tools: $sudoarp-s192.168.1.10000:0c:29:c0:5a:ef $sudoarp-d192.168.1.100 使用iproute2: $sudoipneighadd192.168.1.100lladdr00:0c:29:c0:5a:efdeveth0 $sudoipneighdel192.168.1.100deveth0

添加、删除和查看多播地址

使用net-tools: $sudoipmaddradd33:44:00:00:00:01deveth0 $sudoipmaddrdel33:44:00:00:00:01deveth0 $ipmaddrshowdeveth0 $netstat-g 使用iproute2: $sudoipmaddradd33:44:00:00:00:01deveth0 $sudoipmaddrdel33:44:00:00:00:01deveth0 $ipmaddrlistdeveth0

参考文档:
iproute2 HowTohttp://www.policyrouting.org/iproute2.doc.html
iproute2 man http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2/
RTnetlink http://www.man7.org/linux/man-pages/man7/rtnetlink.7.html
Netlink http://www.man7.org/linux/man-pages/man7/netlink.7.html

相关文章

linux下开机自启: 在/etc/init.d目录下新建文件elasticsear...
1、因为在centos7中/etc/rc.d/rc.local的权限被降低了,所以...
最简单的查看方法可以使用ls -ll、ls-lh命令进行查看,当使用...
ASP.NET Core应用程序发布linux在shell中运行是正常的。可一...
设置时区(CentOS 7) 先执行命令timedatectl status|grep &...
vim /etc/sysconfig/network-scripts/ifcfg-eth0 B...