Linux ifconfig命令:顯示或設置網絡設備參數信息
ifconfig命令來自于英文詞組”network interfaces configuring“的縮寫,其功能是用于顯示或設置網絡設備參數信息。在Windows系統中與之類似的命令叫做ipconfig,同樣的功能可以使用ifconfig去完成。
通常不建議使用ifconfig命令配置網絡設備的參數信息,因為一旦服務器重啟,配置過的參數會自動失效,還是編寫到配置文件中更穩妥。
語法格式:ifconfig [參數] [網卡設備]
常用參數:
add<地址> 設置網絡設備IPv6的IP地址
del<地址> 刪除網絡設備IPv6的IP地址
down 關閉指定的網絡設備
up 啟動指定的網絡設備
IP地址 指定網絡設備的IP地址
參考實例
顯示系統的網絡設備信息:
[root@linuxcool ~]# ifconfig
ens160: flags=4163<up,broadcast,running,multicast> mtu 1500
inet 192.168.10.30 netmask 255.255.255.0 broadcast 192.168.10.255
inet6 fe80::4d16:980c:e0fe:51c2 prefixlen 64 scopeid 0x20
ether 00:0c:29:60:cd:ee txqueuelen 1000 (Ethernet)
RX packets 407 bytes 34581 (33.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 59 bytes 6324 (6.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
………………省略部分輸出信息………………</up,broadcast,running,multicast>
對指定的網卡設備依次進行關閉和啟動操作:
[root@linuxcool ~]# ifconfig ens160 down
[root@linuxcool ~]# ifconfig ens160 up
對指定的網卡設備執行修改IP地址操作:
[root@linuxcool ~]# ifconfig ens160 192.168.10.20 netmask 255.255.255.0
對指定的網卡設備執行修改MAC地址操作:
注意Linux系統中的MAC地址間隔符為冒號(:),而在Windows系統中間隔符為減號(-)。
[root@linuxcool ~]# ifconfig ens160 hw ether 00:aa:bb:cc:dd:ee
對指定的網卡設備依次進行ARP協議關閉和開啟操作:
[root@linuxcool ~]# ifconfig ens160 -arp
[root@linuxcool ~]# ifconfig ens160 arp