ifconfig:配置或顯示網絡接口資訊
【功能說明】
ifconfig指令用于配置網卡IP位址等網絡參數或顯示目前網絡的接口狀态,其類似于Windows下的ipconfig指令,這兩個指令很容易混淆,此外,ifconfig指令在配置網卡資訊時必須以root使用者的身份來執行。如果系統中沒有ifconfig指令,那就需要安裝一下,安裝指令為yum-y install net-tools。
【格式文法】
ifconfig [interface] [option]
ifconfig [網絡接口] [選項]
【說明】
1)在ifconfig指令及後面的網絡接口和選項裡,每個元素之間都至少要有一個空格。
2)interface為網絡接口名,Linux下的網絡接口名類似于eth0、eth1和lo等,分别表示第1塊網卡、第2塊網卡和回環接口。這是個可選項,如果不添加此選項,則顯示系統中所有的網卡資訊;如果添加此選項,則顯示指定的網卡資訊。
3)使用ifconfig指令配置網卡資訊僅會臨時生效,重新開機網絡或伺服器配置就會失效。
【選項說明】
參數選擇 | 解釋說明 |
-a | 顯示所有的網絡接口資訊,包括活動的和非活動的 |
up | 激活指定的網絡斷開 |
down | 關閉指定的網絡接口 |
hw | 設定網絡接口的實體位址 |
[root@10 ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.85.128.6 netmask 255.255.0.0 broadcast 10.85.255.255
inet6 fe80::549c:5266:8f34:5568 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:9d:2d:34 txqueuelen 1000 (Ethernet)
RX packets 98 bytes 8817 (8.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 74 bytes 7777 (7.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:fb:b0:e9 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
對于上面的指令結果,eth0表示第1塊網卡,第2塊網卡為eth1,依此類推;lo表示回環接口。
下面以eth0的結果作進一步說明。
第1行:顯示連接配接類型為Ethernet(以太網),HWaddr表示硬體的MAC位址。
第2行:依次顯示網卡的IP位址(inet addr)、廣播位址(Bcast)和子網路遮罩(Mask)。
第3行:IPv6位址的配置資訊,由于沒有使用IPv6位址,是以這裡沒有IP位址顯示。
第4行:“UP”代表網卡的開啟狀态,“RUNNING”代表網卡上的網線處于連接配接狀态,“MULTICAST”代表支援多點傳播,“MTU:1500”表示最大傳輸單元為1500位元組。
第5、6行:顯示了網卡接收、發送資料包的統計資訊。