ifconfig [介面名] # 查看指定介面 ifconfig [介面名] [協定族] 選項 位址... # 設定參數
[root@machine1 ~]# ifconfig eth0: flags=4163mtu 1500 inet 210.34.6.89 netmask 255.255.255.128 broadcast 210.34.6.127 ether 52:54:ab:dd:6f:61 txqueuelen 1000 (Ethernet) RX packets 46299 bytes 12345678 TX packets 3057 bytes 87654321 lo: flags=73 mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 loop txqueuelen 1000 (Local Loopback)
eth0:乙太網卡介面名稱HWaddr/ether:MAC 位址 (廠商燒錄,全球唯一)inet addr:IPv4 位址Bcast:廣播位址Mask:子網路遮罩MTU:最大傳輸單元 (預設 1500)RX/TX packets/errors/dropped/overruns:收發統計與錯誤計數lo:回環介面,本機內部通訊專用# 臨時修改 (重啟失效) ifconfig eth0 down ifconfig eth0 hw ether 00:11:22:33:44:55 ifconfig eth0 up # 永久生效:寫入啟動腳本 echo "ifconfig eth0 hw ether 00:11:22:33:44:55" >> /etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local
# 臨時新增 ifconfig eth0:0 192.168.1.10 netmask 255.255.255.0 ifconfig eth0:1 192.168.1.11 netmask 255.255.255.0 # 永久配置 (CentOS/RHEL) cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:0 # 編輯 ifcfg-eth0:0 修改 DEVICE=eth0:0, IPADDR=192.168.1.10 systemctl restart network
| 操作 | 指令 |
|---|---|
| 啟用介面 | ifconfig eth0 up |
| 停用介面 | ifconfig eth0 down |
| 設定 IP/掩碼 | ifconfig eth0 192.168.1.10 netmask 255.255.255.0 |
| 設定 MTU | ifconfig eth0 mtu 9000 |
| 啟用混雜模式 | ifconfig eth0 promisc |
| 查看所有介面 (含關閉) | ifconfig -a |
ifconfig 屬於 net-tools 套件,已停止維護。現代 Linux 推薦使用 iproute2 套件的 ip 指令:
ip link show # 等同 ifconfig -a ip addr show # 等同 ifconfig ip addr add 192.168.1.10/24 dev eth0 ip link set eth0 up/down ip link set dev eth0 address 00:11:22:33:44:55