Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux ifconfig Command

Linux ifconfig Command

Linux Command Reference Linux Command Reference

The Linux ifconfig command is used to display or configure network devices.

ifconfig can configure the state of a network device or display its current settings.

Syntax

ifconfig [网络设备][down up -allmulti -arp -promisc][add<地址>][del<地址>][<硬件地址>][io_addr][irq][media<网络媒介类型>][mem_start<内存地址>][metric<数目>][mtu<字节>][netmask<子网掩码>][tunnel<地址>][-broadcast<地址>][-pointopoint<地址>][IP地址]

Parameter Description:

  • add
    Set the IPv6 IP address of a network device.
  • del
    Delete the IPv6 IP address of a network device.
  • down Disable the specified network device.
  • Set the type and hardware address of a network device.
  • io_addr Set the I/O address of a network device.
  • irq Set the IRQ of a network device.
  • media Set the media type of a network device.
  • mem_start Set the starting address a network device occupies in main memory.
  • metric Specify the amount to add when counting the number of packet transmissions.
  • mtu Set the MTU of a network device.
  • netmask Set the subnet mask of a network device.
  • tunnel
    Establish a tunnel communication address between IPv4 and IPv6.
  • up Enable the specified network device.
  • -broadcast
    Treat packets destined for the specified address as broadcast packets.
  • -pointopoint
    Establish a direct connection with the network device at the specified address; this mode provides confidentiality.
  • -promisc Disable or enable promiscuous mode on the specified network device.
  • [IP address] Specify the IP address of the network device.
  • [network device] Specify the name of the network device.

Example

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)

Enable or disable a specified network card

# ifconfig eth0 down

# ifconfig eth0 up

Configure and delete IPv6 addresses for a network card

# ifconfig eth0 add 33ffe:3240:800:1005::2/ 64 //为网卡设置IPv6地址



# ifconfig eth0 del 33ffe:3240:800:1005::2/ 64 //Delete IPv6 address from network card

Modify a MAC address with ifconfig

# ifconfig eth0 down //关闭网卡

# ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //Change MAC address

# ifconfig eth0 up //Start network card

# ifconfig eth1 hw ether 00:1D:1C:1D:1E //disable network card and change MAC address

# ifconfig eth1 up //Start network card

Configure an IP address

# ifconfig eth0 192.168.1.56 

//Configure IP address for eth0 network card

# ifconfig eth0 192.168.1.56 netmask 255.255.255.0 

// Configure IP address for eth0 network card, and add subnet mask

# 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  //disable

Set the maximum transmission unit

# ifconfig eth0 mtu 1500 

//Set the maximum allowed packet size to 1500 bytes

Linux Command Reference Linux Command Reference