ifconfig(interface configuration)是 Unix/Linux 傳統網路介面設定工具,雖新版系統建議改用 ip 指令,但 ifconfig 仍廣泛使用於腳本與舊版系統。
ifconfig -a
顯示所有介面(含未啟用),包含介面名稱(如 eth0、enp3s0、lo)、IPv4/IPv6 位址、MAC 位址、MTU、封包統計等。
ifconfig eth0
# 設定 IPv4 位址與子網路遮罩 ifconfig eth0 192.168.1.100 netmask 255.255.255.0 # 啟用/停用介面 ifconfig eth0 up ifconfig eth0 down # 設定 MTU ifconfig eth0 mtu 9000 # 設定別名(虛擬 IP) ifconfig eth0:0 192.168.1.101 netmask 255.255.255.0
ifconfig eth0 promisc # 啟用(抓包需用) ifconfig eth0 -promisc # 停用
# 新增 IPv6 位址 ifconfig eth0 inet6 add 2001:db8::1/64 # 移除 IPv6 位址 ifconfig eth0 inet6 del 2001:db8::1/64
| 欄位 | 意義 |
|---|---|
inet | IPv4 位址 |
inet6 | IPv6 位址 |
netmask | 子網路遮罩 |
broadcast | 廣播位址 |
ether | MAC 位址 |
RX packets | 接收封包數 |
TX packets | 傳送封包數 |
RX bytes | 接收位元組數 |
TX bytes | 傳送位元組數 |
collisions | 衝突數(乙太網) |


新版 Linux(CentOS 7+、Ubuntu 18.04+、Debian 9+)建議使用 ip 指令:
ip addr show # 相當於 ifconfig -a ip link set eth0 up # 相當於 ifconfig eth0 up ip addr add 192.168.1.100/24 dev eth0
但 ifconfig 仍可透過安裝 net-tools 套件取得。