FreeBSD 系統下查看 IP 位址、MAC 位址、MTU、IPv6 等網路介面完整資訊的標準指令與輸出解讀。
ifconfig -a$ ifconfig -a
em0: flags=8843 metric 0 mtu 1500
options=9b
ether 00:0c:29:e2:ce:a2
inet 192.168.1.195 netmask 0xffffff00 broadcast 192.168.1.255
inet6 fe80::20c:29ff:fee2:cea2%em0 prefixlen 64 scopeid 0x2
nd6 options=29
media: Ethernet autoselect (1000baseT )
status: active
plip0: flags=8810 metric 0 mtu 1500
nd6 options=29
lo0: flags=8049 metric 0 mtu 16384
options=600003
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x5
inet 127.0.0.1 netmask 0xff000000
nd6 options=21
| 欄位 | 說明 | 範例值 |
|---|---|---|
em0 | 實體網卡介面名稱 (Intel PRO/1000) | em0, igb0, re0, vtnet0 |
flags | 介面狀態旗標 | UP=啟用, RUNNING=連線中, BROADCAST=支援廣播 |
mtu | 最大傳輸單元 | 1500 (乙太網標準) |
ether | MAC 位址 (硬體位址) | 00:0c:29:e2:ce:a2 |
inet | IPv4 位址 | 192.168.1.195 |
netmask | 子網掩碼 (十六進位) | 0xffffff00 = 255.255.255.0 |
broadcast | 廣播位址 | 192.168.1.255 |
inet6 | IPv6 位址 (Link-local / Global) | fe80::20c:29ff:fee2:cea2%em0 |
media | 實體介質狀態 | 1000baseT full-duplex |
status | 介面連線狀態 | active / no carrier |
lo0 | 回環介面 | 127.0.0.1 / ::1 |
ifconfig em0:僅顯示指定介面。ifconfig -l:列出所有介面名稱 (一行)。ifconfig em0 inet:僅顯示 IPv4 相關資訊。ifconfig em0 inet6:僅顯示 IPv6 相關資訊。# /etc/rc.conf
ifconfig_em0="inet 192.168.1.195 netmask 255.255.255.0"
defaultrouter="192.168.1.1"
# IPv6
ifconfig_em0_ipv6="inet6 2001:db8::1 prefixlen 64"
ipv6_defaultrouter="2001:db8::fffe"
修改後 service netif restart && service routing restart 生效。
掌握 ifconfig -a 輸出解讀,可快速完成 FreeBSD 網路故障排查、IP 規劃與防火牆規則編寫。