ip指令工作在OSI 網絡棧的兩個層上:第二層(資料鍊路層)和第三層(網絡 或 IP)層。它做了之前net-tools包的所有工作。
安裝 ip
ip指令包含在iproute2util包中,一般都會有,自己想辦法安裝。
ifconfig 和 ip 使用對比:
檢視網口和 IP 位址
如果你想檢視主機的 IP 位址或網絡接口資訊,ifconfig(不帶任何參數)指令提供了一個很好的總結:
$ ifconfig
$ ip address show,或者簡寫為ip a:
$ ip a
添加 IP 位址
使用 ifconfig指令添加 IP 位址指令為:
$ ifconfig eth0 add 192.9.203.21
ip類似:
$ ip address add 192.9.203.21 dev eth0
ip中的子指令可以縮短,是以下面這個指令同樣有效:
$ ip addr add 192.9.203.21 dev eth0
你甚至可以更短些:
$ ip a add 192.9.203.21 dev eth0
移除一個 IP 位址
添加 IP 位址與删除 IP 位址正好相反。
使用 ifconfig,指令是:
$ ifconfig eth0 del 192.9.203.21
ip指令的文法是:
$ ip a del 192.9.203.21 dev eth0
啟用或禁用多點傳播
使用 ifconfig接口來啟用或禁用多點傳播multicast:
# ifconfig eth0 multicast
對于 ip,使用set子指令與裝置(dev)以及一個布爾值和multicast選項:
# ip link set dev eth0 multicast on
啟用或禁用網絡
每個系統管理者都熟悉“先關閉,然後打開”這個技巧來解決問題。對于網絡接口來說,即打開或關閉網絡。
ifconfig指令使用up或down關鍵字來實作:
# ifconfig eth0 up
或者你可以使用一個專用指令:
# ifup eth0
ip指令使用set子指令将網絡設定為up或down狀态:
# ip link set eth0 up
開啟或關閉位址解析功能(ARP)
使用 ifconfig,你可以通過聲明它來啟用:
# ifconfig eth0 arp
使用 ip,你可以将arp屬性設定為on或off:
# ip link set dev eth0 arp on
ip 和 ipconfig 的優缺點
ip指令比ifconfig更通用,技術上也更有效,因為它使用的是Netlink套接字,而不是ioctl系統調用。