Linux ifconfig命令用于顯示或設置網絡設備。
ifconfig可設置網絡設備的狀態(tài),或是顯示目前的設置。
ifconfig [網絡設備][down up -allmulti -arp -promisc][add<地址>][del<地址>][<hw<網絡設備類型><硬件地址>][io_addr<I/O地址>][irq<IRQ地址>][media<網絡媒介類型>][mem_start<內存地址>][metric<數目>][mtu<字節(jié)>][netmask<子網掩碼>][tunnel<地址>][-broadcast<地址>][-pointopoint<地址>][IP地址]
參數說明:
顯示網絡設備信息
# ifconfig eth0 Link encap:Ethernet HWaddr 00:50:56:0A:0B:0C inet addr:192.168.0.3 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::250:56ff:fe0a:b0c/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:172220 errors:0 dropped:0 overruns:0 frame:0 TX packets:132379 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:87101880 (83.0 MiB) TX bytes:41576123 (39.6 MiB) Interrupt:185 Base address:0x2024 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:2022 errors:0 dropped:0 overruns:0 frame:0 TX packets:2022 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:2459063 (2.3 MiB) TX bytes:2459063 (2.3 MiB)
啟動關閉指定網卡
# ifconfig eth0 down # ifconfig eth0 up
為網卡配置和刪除IPv6地址
# ifconfig eth0 add 33ffe:3240:800:1005::2/ 64 //為網卡設置IPv6地址 # ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 //為網卡刪除IPv6地址
用ifconfig修改MAC地址
# ifconfig eth0 down //關閉網卡 # ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址 # ifconfig eth0 up //啟動網卡 # ifconfig eth1 hw ether 00:1D:1C:1D:1E //關閉網卡并修改MAC地址 # ifconfig eth1 up //啟動網卡
配置IP地址
# ifconfig eth0 192.168.1.56 //給eth0網卡配置IP地址 # ifconfig eth0 192.168.1.56 netmask 255.255.255.0 // 給eth0網卡配置IP地址,并加上子掩碼 # ifconfig eth0 192.168.1.56 netmask 255.255.255.0 broadcast 192.168.1.255 // 給eth0網卡配置IP地址,加上子掩碼,加上個廣播地址
啟用和關閉ARP協議
# ifconfig eth0 arp //開啟 # ifconfig eth0 -arp //關閉
設置最大傳輸單元
# ifconfig eth0 mtu 1500 //設置能通過的最大數據包大小為 1500 bytes