Linux ifconfig Command
The Linux ifconfig command is used to display or configure network devices.
ifconfig can set the status of network devices, or display the current settings.
Syntax
ifconfig [网络设备][down up -allmulti -arp -promisc][add<地址>][del<地址>][<hw<网络设备类型><硬件地址>][io_addr<I/O地址>][irq<IRQ地址>][media<网络媒介类型>][mem_start<内存地址>][metric<数目>][mtu<字节>][netmask<子网掩码>][tunnel<地址>][-broadcast<地址>][-pointopoint<地址>][IP地址]
Parameter Description:
- add<address> Set the IPv6 IP address of the network device.
- del<address> Delete the IPv6 IP address of the network device.
- down Shut down the specified network device.
- <hw<network device type><hardware address> Set the type and hardware address of the network device.
- io_addr<I/O address> Set the I/O address of the network device.
- irq<IRQ address> Set the IRQ of the network device.
- media<network media type> Set the media type of the network device.
- mem_start<memory address> Set the starting address occupied by the network device in main memory.
- metric<number> Specify the number to be added when calculating the forwarding count of data packets.
- mtu<bytes> Set the MTU of the network device.
- netmask<subnet mask> Set the subnet mask of the network device.
- tunnel<address> Establish a tunnel communication address between IPv4 and IPv6.
- up Start the specified network device.
- -broadcast<address> Treat data packets destined for the specified address as broadcast packets.
- -pointopoint<address> Establish a direct connection with the network device at the specified address; this mode has confidentiality features.
- -promisc Disable or enable the promiscuous mode of the specified network device.
- [IP address] Specify the IP address of the network device.
- [network device] Specify the name of the network device.
Examples
Display network device information
# 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)
Start or shut down the specified network card
# ifconfig eth0 down # ifconfig eth0 up
Configure and delete IPv6 addresses for the network card
# ifconfig eth0 add 33ffe:3240:800:1005::2/ 64 //为网卡设置IPv6地址 # ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 //为网卡删除IPv6地址
Use ifconfig to modify the MAC address
# 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 //启动网卡
Configure IP address
# 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地址,加上子掩码,加上个广播地址
Enable and disable the ARP protocol
# ifconfig eth0 arp //开启 # ifconfig eth0 -arp //关闭
Set the maximum transmission unit
# ifconfig eth0 mtu 1500 //设置能通过的最大数据包大小为 1500 bytesOther extensions
Linux Command Encyclopedia