Skip to content

建立 2026-09-14 更新 2026-09-14

ifconfig

ifconfig(interface configuration)是 Unix/Linux/macOS 傳統上用來查看網卡的指令:介面名稱、MAC、IPv4/IPv6、是否 UP。Windows 對應的是 ipconfig

現代 Linux 已把 ifconfig 標成舊工具(來自 net-tools),預設可能沒裝。新安裝請優先用 iproute2 的 ip。macOS 仍常用 ifconfig。本頁兩種都寫,避免你在書上看到舊指令就卡住。

ifconfig

ifconfig
ifconfig -a
ifconfig en0

不加參數通常只列「有起來」的介面;-a 連關閉的也列。常見名稱:eth0enp*(有線)、wlan0wlp*(無線)、lo(迴圈)、en0(macOS 有線或 Wi-Fi,視機型)。

輸出重點:

  • inet:IPv4;inet6:IPv6
  • netmaskprefixlen:遮罩
  • ether:MAC
  • UPRUNNING:介面有沒有啟用

閘道不在 ifconfig 裡,要另外看:

netstat -rn
route -n

macOS 看實際在用的 DNS:

scutil --dns

Debian/Ubuntu 若提示找不到命令:sudo apt install net-tools。新腳本請改用下面的 ip

改用 ip(Linux 現況)

ip addr
ip -br addr
ip route
ip neigh
舊指令 現況
ifconfig ip addrip link
route ip route
arp ip neigh

ip routedefault via ... 就是預設閘道,對應 Windows ipconfig 的 Default Gateway。確認後用 ping 測閘道與公網。

臨時加位址(示範;永久設定請用 Netplan、NetworkManager 等發行版機制):

sudo ip addr add 192.0.2.10/24 dev eth0
sudo ip link set eth0 up

不要在生產環境用 ifconfig eth0 192.0.2.10 這種舊寫法當長期設定,重開機就沒了,也容易和 NetworkManager 打架。

教學影片

what is an IP Address?(NetworkChuck)同時示範 Windows ipconfig 與 Linux ifconfig,並用「街道/門牌」比喻講 IP、遮罩、預設閘道。看完就知道為什麼 ifconfig 沒印閘道時,還要再跑 ip route

Windows Command Line Tools(PowerCert Animated Videos)主講 Windows,但「先看本機 IP 再 ping」的流程與 Linux 相同;對照本頁的 ip addrip route 即可。

相關資料

  • man ip(iproute2)
  • Windows 對應:ipconfig 鄰居快取:arp