# ifconfig - [Command Function](#section174940284379) - [Syntax](#section136073203715) - [Parameters](#section6493235203710) - [Usage](#section05763403371) - [Example](#section168802042123717) - [Output](#section124638211109) ## Command Function This command can be used to: - Query and set network interface card \(NIC\) parameters, such as the IP address, network mask, gateway, and MAC address. - Disable or enable a NIC. ## Syntax ifconfig \[_-a_\] <_interface_\> <_address_\> \[_netmask _\] \[_gateway _\] \[_hw ether _\] \[_mtu _\] \[_inet6 add _\] \[_inet6 del _\] \[_up|down_\] ## Parameters **Table 1** Parameter description

Parameter

Description

Value Range

No parameter

Displays the IP addresses, network masks, gateway, MAC addresses, MTU, and running status of all NICs.

N/A

-a

Displays data sent and received by the protocol stack.

N/A

interface

Specifies the NIC name, for example, eth0.

N/A

address

Specifies the IP address, for example, 192.168.1.10. The NIC name must be specified.

N/A

netmask

Specifies the subnet mask, for example, 255.255.255.0.

N/A

gateway

Specifies the gateway, for example, 192.168.1.1.

N/A

hw ether

Specifies the MAC address, for example, 00:11:22:33:44:55. Currently, only the ether hardware type is supported.

N/A

mtu

Specifies the maximum transmission unit (MTU) size, for example, 1000.

  • For IPv4:

    [68,1500]

  • For IPv6:

    [1280, 1500]

add

Specifies the IPv6 address, for example, 2001:a:b:c:d:e:f:d. The NIC name and inet6 must be specified.

N/A

del

Deletes an IPv6 address. The NIC name and inet6 must be specified.

N/A

up

Enables the data processing function of the NIC. The NIC name must be specified.

N/A

down

Disables the data processing function of the NIC. The NIC name must be specified.

N/A

## Usage - This command can be used only after the TCP/IP protocol stack is enabled. - Detecting the IP address conflict takes a period of time. Each time you run the **ifconfig** command to set an IP address, there is a delay of about 2 seconds. ## Example 1. ifconfig eth0 192.168.100.31 netmask 255.255.255.0 gateway 192.168.100.1 hw ether 00:49:cb:6c:a1:31 2. ifconfig -a 3. ifconfig eth0 inet6 add 2001:a:b:c:d:e:f:d 4. ifconfig eth0 inet6 del 2001:a:b:c:d:e:f:d ## Output 1. Set network parameters. ``` OHOS # ifconfig eth0 192.168.100.31 netmask 255.255.255.0 gateway 192.168.100.1 hw ether 00:49:cb:6c:a1:31 OHOS # ifconfig eth0 ip:192.168.100.31 netmask:255.255.255.0 gateway:192.168.100.1 HWaddr 00:49:cb:6c:a1:31 MTU:1500 Running Default Link UP lo ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1 ip6: ::1/64 HWaddr 00 MTU:0 Running Link UP ``` The following table describes the output parameters. **Table 2** Output description

Parameter

Description

ip

IP address of the board

netmask

Subnet mask

gateway

Gateway

HWaddr

MAC address of the board

MTU

Maximum transmission unit

Running/Stop

Indicates whether the NIC is running.

Default

The NIC is connected to the default gateway.

Link UP/Down

Connection status of the NIC

2. Obtain protocol stack statistics. ``` OHOS # ifconfig -a RX packets:6922 errors:0 ip dropped:4312 link dropped:67 overrun:0 bytes:0 (0.0 B) RX packets(ip6):3 errors:0 dropped:0 overrun:0 bytes:0 (0.0 B) TX packets:1394 errors:0 link dropped:67 overrun:0 bytes:0(0.0 B) TX packets(ip6):3 errors:0 overrun:0 bytes:0(0.0 B) ``` The following table describes the output parameters. **Table 3** ifconfig -a output description

Parameter

Description

RX packets

Number of normal packets received at the IP layer.

RX error

Number of error packets received at the IP layer. The errors include the length, verification, IP option, and IP header protocol errors.

RX dropped

Number of packets discarded at the IP layer. Packets are discarded due to packet errors, packet forwarding failures, and disabled local NICs.

RX overrun

Number of packets that the MAC layer fails to deliver to the upper-layer protocol stack. The failure is mainly caused by resource insufficiency at the protocol stack.

RX bytes

Total length of normal packets received at the IP layer, excluding the length of the fragments that are not reassembled.

TX packets

Number of packets that have been normally sent or forwarded at the IP layer.

TX error

Number of packets that the IP layer fails to send. Packets may fail to be sent because the packets cannot be routed or the packets fail to be processed in the protocol stack.

TX dropped

Number of packets that the MAC layer discards due to sending failures, for example, the NIC driver fails to process the packets.

TX overrun

Reserved.

TX bytes

Total length of the packets successfully sent or forwarded at the IP layer.

3. Set the IPv6 address information. ``` OHOS # ifconfig eth0 inet6 add 2001:a:b:c:d:e:f:d OHOS # ifconfig eth1 ip:192.168.3.60 netmask:255.255.255.0 gateway:0.0.0.0 HWaddr 00:0e:c6:a8:5a:c2 MTU:1500 Running Link UP eth0 ip:192.168.2.60 netmask:255.255.255.0 gateway:0.0.0.0 ip6: 2001:A:B:C:D:E:F:D/64 HWaddr 46:44:02:02:03:03 MTU:1500 Running Link UP lo ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1 ip6: ::1/64 HWaddr 00 MTU:16436 Running Link UP ``` 4. Delete the IPv6 address information. ``` OHOS # ifconfig eth0 inet6 del 2001:a:b:c:d:e:f:d OHOS # ifconfig eth1 ip:192.168.3.60 netmask:255.255.255.0 gateway:0.0.0.0 HWaddr 00:0e:c6:a8:5a:c2 MTU:1500 Running Link UP eth0 ip:192.168.2.60 netmask:255.255.255.0 gateway:0.0.0.0 HWaddr 46:44:02:02:03:03 MTU:1500 Running Link UP lo ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1 ip6: ::1/64 HWaddr 00 MTU:16436 Running Link UP ```