歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> iproute2 對決 net-tools

iproute2 對決 net-tools

日期:2017/2/28 14:25:27   编辑:Linux教程

如今很多系統管理員依然通過組合使用諸如ifconfig、route、arp和netstat等命令行工具(統稱為net-tools)來配置網絡功能,解決網絡故障。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仍處在持續開發中。

如果你仍在使用net-tools,而且尤其需要跟上新版Linux內核中的最新最重要的網絡特性的話,那麼是時候轉到iproute2的陣營了。原因就在於使用iproute2可以做很多net-tools無法做到的事情。

對於那些想要轉到使用iproute2的用戶,有必要了解下面有關net-tools和iproute2的眾多對比。

使用iproute2配置force-onlink路由 http://www.linuxidc.com/Linux/2012-06/63519.htm

使用netstat檢測及監測網絡連接 http://www.linuxidc.com/Linux/2014-09/106497.htm

netstat 的10個基本用法 http://www.linuxidc.com/Linux/2014-01/94644.htm

Linux netstat命令詳解 http://www.linuxidc.com/Linux/2012-12/75667.htm

試試Linux下的ip命令,ifconfig已經過時了 http://www.linuxidc.com/Linux/2014-06/102670.htm

顯示所有已連接的網絡接口

下面的命令顯示出所有可用網絡接口的列表(無論接口是否激活)。

使用net-tools

  1. $ ifconfig -a

使用iproute2

  1. $ ip link show

為什麼在 RedHat Linux 5 下不能使用 ifconfig 命令 http://www.linuxidc.com/Linux/2014-03/98962.htm

激活或停用網絡接口

使用這些命令來激活或停用某個指定的網絡接口。

使用net-tools

  1. $ sudo ifconfig eth1 up
  2. $ sudo ifconfig eth1 down

使用iproute2

  1. $ sudo ip link set down eth1
  2. $ sudo ip link set up eth1

為網絡接口分配IPv4地址

使用這些命令配置網絡接口的IPv4地址。

使用net-tools

  1. $ sudo ifconfig eth1 10.0.0.1/24

使用iproute2

  1. $ sudo ip addr add 10.0.0.1/24 dev eth1

值得注意的是,可以使用iproute2給同一個接口分配多個IP地址,ifconfig則無法這麼做。使用ifconfig的變通方案是使用IP別名。

  1. $ sudo ip addr add 10.0.0.1/24 broadcast 10.0.0.255 dev eth1
  2. $ sudo ip addr add 10.0.0.2/24 broadcast 10.0.0.255 dev eth1
  3. $ sudo ip addr add 10.0.0.3/24 broadcast 10.0.0.255 dev eth1

移除網絡接口的IPv4地址

就IP地址的移除而言,除了給接口分配全0地址外,net-tools沒有提供任何合適的方法來移除網絡接口的IPv4地址。相反,iproute2則能很好地完全。

使用net-tools

  1. $ sudo ifconfig eth1 0

使用iproute2

  1. $ sudo ip addr del10.0.0.1/24 dev eth1

顯示網絡接口的IPv4地址

按照如下操作可查看某個指定網絡接口的IPv4地址。

使用net-tools

  1. $ ifconfig eth1

使用iproute2

  1. $ ip addr show dev eth1

同樣,如果接口分配了多個IP地址,iproute2會顯示出所有地址,而net-tools只能顯示一個IP地址。

為網絡接口分配IPv6地址

使用這些命令為網絡接口添加IPv6地址。net-tools和iproute2都允許用戶為一個接口添加多個IPv6地址。

使用net-tools

  1. $ sudo ifconfig eth1 inet6 add 2002:0db5:0:f102::1/64
  2. $ sudo ifconfig eth1 inet6 add 2003:0db5:0:f102::1/64

使用iproute2

  1. $ sudo ip -6 addr add 2002:0db5:0:f102::1/64 dev eth1
  2. $ sudo ip -6 addr add 2003:0db5:0:f102::1/64 dev eth1

顯示網絡接口的IPv6地址

按照如下操作可顯示某個指定網絡接口的IPv6地址。net-tools和iproute2都可以顯示出所有已分配的IPv6地址。

使用net-tools

  1. $ ifconfig eth1

使用iproute2

  1. $ ip -6 addr show dev eth1

更多詳情見請繼續閱讀下一頁的精彩內容: http://www.linuxidc.com/Linux/2014-11/109953p2.htm

Copyright © Linux教程網 All Rights Reserved