1# ifconfig
2
3
4## Command Function
5
6This command can be used to:
7
8- Query and set parameters of a network interface card (NIC), such as the IP address, network mask, gateway, and MAC address.
9
10- Enable or disable a NIC.
11
12
13## Syntax
14
15ifconfig [option]
16
17option:
18
19- [_-a_]
20
21- <*interface*> <*address*> [_netmask <mask>_] [_gateway <address>_]
22
23- [_hw ether <address>_] [_mtu <size>_]
24
25- [_inet6 add <address>_]
26
27- [_inet6 del <address>_]
28
29- [_up|down_]
30
31
32## Parameters
33
34**Table 1** Parameter description
35
36| Parameter| Description| Value Range|
37| -------- | -------- | -------- |
38|  No parameter| Displays all NIC information, which includes the IP address, network mask, gateway, MAC address, maximum transmission unit (MTUs), and running status of each NIC.| N/A |
39| -a | Displays data sent and received by the protocol stack.| N/A |
40| interface | Specifies the NIC name, for example, **eth0**.| N/A |
41| address | Specifies the IP address, for example, **192.168.1.10**. The NIC name must be specified.| N/A |
42| netmask | Specifies the subnet mask, for example, **255.255.255.0**.| N/A |
43| gateway | Specifies the gateway, for example, **192.168.1.1**.| N/A |
44| hw ether | Specifies the MAC address, for example, **00:11:22:33:44:55**. Currently, only the **ether** hardware type is supported.| N/A |
45| mtu | Specifies the MTU size, for example, **1000**.| - IPv4: [68, 1500]<br>- IPv6:[1280, 1500] |
46| 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 |
47| del | Deletes an IPv6 address. You need to specify the NIC name and add the **inet6** option. For details, see the example.| N/A |
48| up | Enables the data processing function of the NIC. The NIC name must be specified.| N/A |
49| down | Disables the data processing function of the NIC. The NIC name must be specified.| N/A |
50
51
52## Usage Guidelines
53
54- This command can be used only after the TCP/IP stack is enabled.
55
56- Detecting an IP address conflict takes time. Each time you run the **ifconfig** command to set an IP address, there is a delay of about 2 seconds.
57
58
59## Example
60
61- ifconfig eth0 192.168.100.31 netmask 255.255.255.0 gateway 192.168.100.1 hw ether 00:49:cb:6c:a1:31
62
63- ifconfig -a
64
65- ifconfig eth0 inet6 add 2001:a:b:c:d:e:f:d
66
67- ifconfig eth0 inet6 del 2001:a:b:c:d:e:f:d
68
69
70## Output
71
72- Example 1: Set network parameters.
73
74  ```
75  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
76  OHOS:/$ ifconfig
77  lo      ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1
78          ip6: ::1/64
79          HWaddr 00 MTU:0 Running Link UP
80  eth0    ip:192.168.100.31 netmask:255.255.255.0 gateway:192.168.100.1
81          HWaddr 00:49:cb:6c:a1:31 MTU:1500 Running Default Link UP
82  ```
83
84
85
86  **Table 2** Parameter description
87
88  | Parameter| Description|
89  | -------- | -------- |
90  | ip | IP address of the board.|
91  | netmask | Subnet mask.|
92  | gateway | Gateway.|
93  | HWaddr | MAC address of the board.|
94  | MTU | Maximum transmission unit.|
95  | Running/Stop | Whether the NIC is running.|
96  | Default | Indicates that the NIC is connected to the default gateway.|
97  | Link&nbsp;UP/Down | Connection status of the NIC.|
98
99- Example 2: Obtain protocol stack statistics.
100
101  ```
102  OHOS # ifconfig -a
103  RX packets:6922  errors:0        ip dropped:4312         link dropped:67         overrun:0       bytes:0 (0.0 B)
104  RX packets(ip6):3     errors:0        dropped:0       overrun:0       bytes:0 (0.0 B)
105  TX packets:1394  errors:0        link dropped:67         overrun:0       bytes:0(0.0 B)
106  TX packets(ip6):3     errors:0        overrun:0       bytes:0(0.0 B)
107  ```
108
109
110
111  **Table 3** ifconfig -a parameter description
112
113  | Parameter| Description|
114  | -------- | -------- |
115  | RX&nbsp;packets | Number of normal packets received at the IP layer.|
116  | RX&nbsp;error | Number of error packets received at the IP layer. The errors include the length error, verification error, IP option error, and IP header protocol error.|
117  | RX&nbsp;dropped | Number of packets discarded at the IP layer. Packets are discarded due to packet errors, packet forwarding failures, and disabled local NICs.|
118  | RX&nbsp;overrun | Number of packets that the MAC layer fails to deliver to the upper-layer protocol stack. The failure is caused by resource insufficiency at the protocol stack.|
119  | RX&nbsp;bytes | Total length of normal packets received at the IP layer, excluding the length of the fragments that are not reassembled.|
120  | TX&nbsp;packets | Number of packets that have been normally sent or forwarded at the IP layer.|
121  | TX&nbsp;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.|
122  | TX&nbsp;dropped | Number of packets that the MAC layer discards due to delivery failures, for example, the NIC driver fails to process the packets.|
123  | TX&nbsp;overrun | Not used currently.|
124  | TX&nbsp;bytes | Total length of the packets successfully sent or forwarded at the IP layer.|
125
126- Example 3: Set an IPv6 address.
127
128  ```
129  OHOS:/$ ifconfig eth0 inet6 add 2001:a:b:c:d:e:f:d
130  NetifStatusCallback(eth0): nsc event: 0x8
131  NetifStatusCallback(eth0): nsc status changed: 0
132  NetifStatusCallback(eth0): nsc event: 0x200
133  NetifStatusCallback(eth0): nsc event: 0x8
134  NetifStatusCallback(eth0): nsc status changed: 1
135  NetifStatusCallback(eth0): nsc event: 0x200
136  NetifStatusCallback(eth0): nsc event: 0x200
137  OHOS:/$ ifconfig
138  lo      ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1
139          ip6: ::1/64
140          HWaddr 00 MTU:0 Running Link UP
141  eth0    ip:192.168.1.10 netmask:255.255.255.0 gateway:192.168.1.1
142          ip6: 2001:A:B:C:D:E:F:D/64
143          HWaddr 66:2f:e5:bd:24:e6 MTU:1500 Running Default Link UP
144  ```
145
146- Example 4: Delete an IPv6 address.
147
148  ```
149  OHOS:/$ ifconfig eth0 inet6 del 2001:a:b:c:d:e:f:d
150  NetifStatusCallback(eth0): nsc event: 0x200
151  OHOS:/$ ifconfig
152  lo      ip:127.0.0.1 netmask:255.0.0.0 gateway:127.0.0.1
153          ip6: ::1/64
154          HWaddr 00 MTU:0 Running Link UP
155  eth0    ip:192.168.1.10 netmask:255.255.255.0 gateway:192.168.1.1
156          HWaddr 66:2f:e5:bd:24:e6 MTU:1500 Running Default Link UP
157  ```
158