js-apis-net-ethernet.md 20.7 KB
Newer Older
S
shawn_he 已提交
1
# # @ohos.net.ethernet (Ethernet Connection Management)
G
Gloria 已提交
2

S
shawn_he 已提交
3
The **ethernet** module provides wired network capabilities, which allow users to set the IP address, subnet mask, gateway, and Domain Name System (DNS) server, and HTTP proxy of a wired network.
G
Gloria 已提交
4

S
shawn_he 已提交
5
> **NOTE**
G
Gloria 已提交
6 7 8 9 10 11 12 13
> The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.

## Modules to Import

```js
import ethernet from '@ohos.net.ethernet'
```

S
shawn_he 已提交
14
## ethernet.setIfaceConfig<sup>9+</sup>
G
Gloria 已提交
15

S
shawn_he 已提交
16
setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback\<void>): void
G
Gloria 已提交
17 18 19

Sets the network interface configuration. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
20 21
**System API**: This is a system API.

G
Gloria 已提交
22 23
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL

S
shawn_he 已提交
24
**System capability**: SystemCapability.Communication.NetManager.Ethernet
G
Gloria 已提交
25 26 27 28 29

**Parameters**

| Name  | Type                                             | Mandatory| Description                                      |
| -------- | ------------------------------------------------- | ---- | ------------------------------------------ |
S
shawn_he 已提交
30
| iface    | string                                            | Yes  | Interface name.                                    |
G
Gloria 已提交
31 32 33
| ic       | [InterfaceConfiguration](#interfaceconfiguration) | Yes  | Network interface configuration to set.                  |
| callback | AsyncCallback\<void>                     | Yes  | Callback used to return the result. If the operation is successful, the return result is empty. If the operation fails, an error code is returned.|

S
shawn_he 已提交
34 35 36 37 38
**Error codes**

| ID| Error Message                                |
| ------- | ----------------------------------------|
| 201     | Permission denied.                      |
S
shawn_he 已提交
39
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
40 41 42 43
| 401     | Parameter error.                        |
| 2200001 | Invalid parameter value.                |
| 2200002 | Operation failed. Cannot connect to service.|
| 2200003 | System internal error.                  |
S
shawn_he 已提交
44 45 46 47
| 2201004 | Invalid Ethernet profile.  |
| 2201005 | Device information does not exist.  |
| 2201006 | Ethernet device not connected.                    |
| 2201007 | Ethernet failed to write user configuration information.    |
S
shawn_he 已提交
48

G
Gloria 已提交
49 50 51
**Example**

```js
S
shawn_he 已提交
52
ethernet.setIfaceConfig("eth0", {
S
shawn_he 已提交
53 54 55 56 57
  mode: 0,
  ipAddr: "192.168.xx.xxx",
  route: "192.168.xx.xxx",
  gateway: "192.168.xx.xxx",
  netMask: "255.255.255.0",
S
shawn_he 已提交
58 59 60 61 62 63
  dnsServers: "1.1.1.1",
  httpProxy: {
    host: "180.89.xx.xx",
    port: 8080,
    exclusionList: {"example.com","192.168.0.1"}
  }
S
shawn_he 已提交
64
}, (error) => {
S
shawn_he 已提交
65 66 67 68 69
  if (error) {
    console.log("setIfaceConfig callback error = " + JSON.stringify(error));
  } else {
    console.log("setIfaceConfig callback ok ");
  }
S
shawn_he 已提交
70
});
G
Gloria 已提交
71 72
```

S
shawn_he 已提交
73
## ethernet.setIfaceConfig<sup>9+</sup>
G
Gloria 已提交
74

S
shawn_he 已提交
75
setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\<void>
G
Gloria 已提交
76 77 78

Sets the network interface configuration. This API uses a promise to return the result.

S
shawn_he 已提交
79 80
**System API**: This is a system API.

G
Gloria 已提交
81 82
**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL

S
shawn_he 已提交
83
**System capability**: SystemCapability.Communication.NetManager.Ethernet
G
Gloria 已提交
84 85 86 87 88

**Parameters**

| Name| Type                                             | Mandatory| Description                    |
| ------ | ------------------------------------------------- | ---- | ------------------------ |
S
shawn_he 已提交
89
| iface  | string                                            | Yes  | Interface name.                  |
G
Gloria 已提交
90 91 92 93 94 95
| ic     | [InterfaceConfiguration](#interfaceconfiguration) | Yes  | Network interface configuration to set.|

**Return value**

| Type               | Description                                                       |
| ------------------- | ----------------------------------------------------------- |
S
shawn_he 已提交
96 97 98 99 100 101 102
| Promise\<void>       | Promise used to return the result. If the operation is successful, the return result is empty. If the operation fails, an error code is returned.|

**Error codes**

| ID| Error Message                                |
| ------- | ----------------------------------------|
| 201     | Permission denied.                      |
S
shawn_he 已提交
103
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
104 105 106 107
| 401     | Parameter error.                        |
| 2200001 | Invalid parameter value.                |
| 2200002 | Operation failed. Cannot connect to service.|
| 2200003 | System internal error.                  |
S
shawn_he 已提交
108 109 110 111
| 2201004 | Invalid Ethernet profile.  |
| 2201005 | Device information does not exist.  |
| 2201006 | Ethernet device not connected.                    |
| 2201007 | Ethernet failed to write user configuration information.    |
G
Gloria 已提交
112 113 114 115

**Example**

```js
S
shawn_he 已提交
116
ethernet.setIfaceConfig("eth0", {
S
shawn_he 已提交
117 118 119 120 121
  mode: 0,
  ipAddr: "192.168.xx.xxx",
  route: "192.168.xx.xxx",
  gateway: "192.168.xx.xxx",
  netMask: "255.255.255.0",
S
shawn_he 已提交
122 123 124 125 126 127
  dnsServers: "1.1.1.1",
  httpProxy: {
    host: "180.89.xx.xx",
    port: 8080,
    exclusionList: {"example.com","192.168.0.1"}
  }
S
shawn_he 已提交
128
}).then(() => {
S
shawn_he 已提交
129
  console.log("setIfaceConfig promise ok ");
S
shawn_he 已提交
130
}).catch(error => {
S
shawn_he 已提交
131
  console.log("setIfaceConfig promise error = " + JSON.stringify(error));
G
Gloria 已提交
132 133 134
});
```

S
shawn_he 已提交
135
## ethernet.getIfaceConfig<sup>9+</sup>
G
Gloria 已提交
136

S
shawn_he 已提交
137
getIfaceConfig(iface: string, callback: AsyncCallback\<InterfaceConfiguration>): void
G
Gloria 已提交
138 139 140

Obtains the configuration of a network interface. This API uses an asynchronous callback to return the result. 

S
shawn_he 已提交
141 142
**System API**: This is a system API.

G
Gloria 已提交
143 144
**Required permission**: ohos.permission.GET_NETWORK_INFO

S
shawn_he 已提交
145
**System capability**: SystemCapability.Communication.NetManager.Ethernet
G
Gloria 已提交
146 147 148 149 150

**Parameters**

| Name  | Type                                           | Mandatory | Description        |
| -------- | ----------------------------------------------- | ----- | ------------ |
S
shawn_he 已提交
151 152 153 154 155 156 157 158
| iface    | string                                          | Yes   | Interface name.|
| callback | AsyncCallback\<[InterfaceConfiguration](#interfaceconfiguration)> | Yes   | Callback used to return the result.  |

**Error codes**

| ID| Error Message                                |
| ------- | ----------------------------------------|
| 201     | Permission denied.                      |
S
shawn_he 已提交
159
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
160 161 162 163
| 401     | Parameter error.                        |
| 2200001 | Invalid parameter value.                |
| 2200002 | Operation failed. Cannot connect to service.|
| 2200003 | System internal error.                  |
S
shawn_he 已提交
164
| 2201005 | Device information does not exist.  |
G
Gloria 已提交
165 166 167 168 169

**Example**

```js
ethernet.getIfaceConfig("eth0", (error, value) => {
S
shawn_he 已提交
170 171 172 173 174 175 176 177 178 179
  if (error) {
    console.log("getIfaceConfig  callback error = " + JSON.stringify(error));
  } else {
    console.log("getIfaceConfig callback mode = " + JSON.stringify(value.mode));
    console.log("getIfaceConfig callback ipAddr = " + JSON.stringify(value.ipAddr));
    console.log("getIfaceConfig callback route = " + JSON.stringify(value.route));
    console.log("getIfaceConfig callback gateway = " + JSON.stringify(value.gateway));
    console.log("getIfaceConfig callback netMask = " + JSON.stringify(value.netMask));
    console.log("getIfaceConfig callback dnsServers = " + JSON.stringify(value.dnsServers));
  }
G
Gloria 已提交
180 181 182
});
```

S
shawn_he 已提交
183
## ethernet.getIfaceConfig<sup>9+</sup>
G
Gloria 已提交
184

S
shawn_he 已提交
185
getIfaceConfig(iface: string): Promise\<InterfaceConfiguration>
G
Gloria 已提交
186 187 188

Obtains the configuration of a network interface. This API uses a promise to return the result. 

S
shawn_he 已提交
189 190
**System API**: This is a system API.

G
Gloria 已提交
191 192
**Required permission**: ohos.permission.GET_NETWORK_INFO

S
shawn_he 已提交
193
**System capability**: SystemCapability.Communication.NetManager.Ethernet
G
Gloria 已提交
194 195 196 197 198

**Parameters**

| Name  | Type                                   | Mandatory| Description        |
| -------- | --------------------------------------- | ---- | ------------ |
S
shawn_he 已提交
199
| iface    | string                                  | Yes  | Interface name.|
G
Gloria 已提交
200 201 202 203 204

**Return value**

| Type                             | Description                              |
| --------------------------------- | ---------------------------------- |
S
shawn_he 已提交
205 206 207 208 209 210 211
| Promise\<[InterfaceConfiguration](#interfaceconfiguration)>   | Promise used to return the result.       |

**Error codes**

| ID| Error Message                                |
| ------- | ----------------------------------------|
| 201     | Permission denied.                      |
S
shawn_he 已提交
212
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
213 214 215 216
| 401     | Parameter error.                        |
| 2200001 | Invalid parameter value.                |
| 2200002 | Operation failed. Cannot connect to service.|
| 2200003 | System internal error.                  |
S
shawn_he 已提交
217
| 2201005 | Device information does not exist.  |
G
Gloria 已提交
218 219 220 221 222

**Example**

```js
ethernet.getIfaceConfig("eth0").then((data) => {
S
shawn_he 已提交
223 224 225 226 227 228
  console.log("getIfaceConfig promise mode = " + JSON.stringify(data.mode));
  console.log("getIfaceConfig promise ipAddr = " + JSON.stringify(data.ipAddr));
  console.log("getIfaceConfig promise route = " + JSON.stringify(data.route));
  console.log("getIfaceConfig promise gateway = " + JSON.stringify(data.gateway));
  console.log("getIfaceConfig promise netMask = " + JSON.stringify(data.netMask));
  console.log("getIfaceConfig promise dnsServers = " + JSON.stringify(data.dnsServers));
S
shawn_he 已提交
229
}).catch(error => {
S
shawn_he 已提交
230
  console.log("getIfaceConfig promise error = " + JSON.stringify(error));
G
Gloria 已提交
231 232 233
});
```

S
shawn_he 已提交
234
## ethernet.isIfaceActive<sup>9+</sup>
G
Gloria 已提交
235

S
shawn_he 已提交
236
isIfaceActive(iface: string, callback: AsyncCallback\<number>): void
G
Gloria 已提交
237 238 239

Checks whether a network interface is active. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
240 241
**System API**: This is a system API.

G
Gloria 已提交
242 243
**Required permission**: ohos.permission.GET_NETWORK_INFO

S
shawn_he 已提交
244
**System capability**: SystemCapability.Communication.NetManager.Ethernet
G
Gloria 已提交
245 246 247 248 249

**Parameters**

| Name  | Type                       | Mandatory| Description                                              |
| -------- | --------------------------- | ---- | -------------------------------------------------- |
S
shawn_he 已提交
250
| iface    | string                      | Yes  | Interface name. If this parameter is left empty, the API checks for any active network interface.            |
G
Gloria 已提交
251 252
| callback | AsyncCallback\<number>       | Yes  | Callback used to return the result. The value **1** means that the network interface is active, **0** means that the network interface is inactive, and any other value means that an error has occurred.|

S
shawn_he 已提交
253 254 255 256 257
**Error codes**

| ID| Error Message                                |
| ------- | ----------------------------------------|
| 201     | Permission denied.                      |
S
shawn_he 已提交
258
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
259 260 261 262
| 401     | Parameter error.                        |
| 2200001 | Invalid parameter value.                |
| 2200002 | Operation failed. Cannot connect to service.|
| 2200003 | System internal error.                  |
S
shawn_he 已提交
263
| 2201005 | Device information does not exist.  |
S
shawn_he 已提交
264

G
Gloria 已提交
265 266 267 268
**Example**

```js
ethernet.isIfaceActive("eth0", (error, value) => {
S
shawn_he 已提交
269 270 271 272 273
  if (error) {
    console.log("whether2Activate callback error = " + JSON.stringify(error));
  } else {
    console.log("whether2Activate callback = " + JSON.stringify(value));
  }
G
Gloria 已提交
274 275 276
});
```

S
shawn_he 已提交
277
## ethernet.isIfaceActive<sup>9+</sup>
G
Gloria 已提交
278

S
shawn_he 已提交
279
isIfaceActive(iface: string): Promise\<number>
G
Gloria 已提交
280 281 282

Checks whether a network interface is active. This API uses a promise to return the result.

S
shawn_he 已提交
283 284
**System API**: This is a system API.

G
Gloria 已提交
285 286
**Required permission**: ohos.permission.GET_NETWORK_INFO

S
shawn_he 已提交
287
**System capability**: SystemCapability.Communication.NetManager.Ethernet
G
Gloria 已提交
288 289 290 291 292

**Parameters**

| Name| Type  | Mandatory| Description                                  |
| ------ | ------ | ---- | -------------------------------------- |
S
shawn_he 已提交
293
| iface  | string | Yes  | Interface name. If this parameter is left empty, the API checks for any active network interface.|
G
Gloria 已提交
294 295 296 297 298 299 300

**Return value**

| Type           | Description                                                              |
| ----------------| ------------------------------------------------------------------ |
| Promise\<number> | Promise used to return the result. The value **1** means that the network interface is active, **0** means that the network interface is inactive, and any other value means that an error has occurred.|

S
shawn_he 已提交
301 302 303 304 305
**Error codes**

| ID| Error Message                                |
| ------- | ----------------------------------------|
| 201     | Permission denied.                      |
S
shawn_he 已提交
306
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
307 308 309 310
| 401     | Parameter error.                        |
| 2200001 | Invalid parameter value.                |
| 2200002 | Operation failed. Cannot connect to service.|
| 2200003 | System internal error.                  |
S
shawn_he 已提交
311
| 2201005 | Device information does not exist.  |
S
shawn_he 已提交
312

G
Gloria 已提交
313 314 315 316
**Example**

```js
ethernet.isIfaceActive("eth0").then((data) => {
S
shawn_he 已提交
317
  console.log("isIfaceActive promise = " + JSON.stringify(data));
S
shawn_he 已提交
318
}).catch(error => {
S
shawn_he 已提交
319
  console.log("isIfaceActive promise error = " + JSON.stringify(error));
G
Gloria 已提交
320 321 322
});
```

S
shawn_he 已提交
323
## ethernet.getAllActiveIfaces<sup>9+</sup>
G
Gloria 已提交
324

S
shawn_he 已提交
325
getAllActiveIfaces(callback: AsyncCallback\<Array\<string>>): void
G
Gloria 已提交
326

S
shawn_he 已提交
327 328 329
Obtains the list of all active network interfaces. This API uses an asynchronous callback to return the result.

**System API**: This is a system API.
G
Gloria 已提交
330 331 332

**Required permission**: ohos.permission.GET_NETWORK_INFO

S
shawn_he 已提交
333
**System capability**: SystemCapability.Communication.NetManager.Ethernet
G
Gloria 已提交
334 335 336 337 338

**Parameters**

| Name  | Type                                | Mandatory| Description                          |
| -------- | ------------------------------------ | ---- | ------------------------------ |
S
shawn_he 已提交
339 340 341 342 343 344 345
| callback | AsyncCallback\<Array\<string>>         | Yes  | Callback used to return the result.|

**Error codes**

| ID| Error Message                                |
| ------- | ----------------------------------------|
| 201     | Permission denied.                      |
S
shawn_he 已提交
346
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
347 348
| 2200002 | Operation failed. Cannot connect to service.|
| 2200003 | System internal error.                  |
G
Gloria 已提交
349 350 351 352 353

**Example**

```js
ethernet.getAllActiveIfaces((error, value) => {
S
shawn_he 已提交
354 355 356 357 358 359
  if (error) {
    console.log("getAllActiveIfaces callback error = " + JSON.stringify(error));
  } else {
    console.log("getAllActiveIfaces callback value.length = " + JSON.stringify(value.length));
    for (let i = 0; i < value.length; i++) {
      console.log("getAllActiveIfaces callback = " + JSON.stringify(value[i]));
G
Gloria 已提交
360
    }
S
shawn_he 已提交
361
  }
G
Gloria 已提交
362 363 364
});
```

S
shawn_he 已提交
365
## ethernet.getAllActiveIfaces<sup>9+</sup>
G
Gloria 已提交
366

S
shawn_he 已提交
367
getAllActiveIfaces(): Promise\<Array\<string>>
G
Gloria 已提交
368

S
shawn_he 已提交
369
Obtains the list of all active network interfaces. This API uses a promise to return the result.
G
Gloria 已提交
370

S
shawn_he 已提交
371
**System API**: This is a system API.
G
Gloria 已提交
372

S
shawn_he 已提交
373
**Required permission**: ohos.permission.GET_NETWORK_INFO
G
Gloria 已提交
374

S
shawn_he 已提交
375
**System capability**: SystemCapability.Communication.NetManager.Ethernet
G
Gloria 已提交
376 377 378 379 380

**Return value**

| Type                          | Description                                           |
| ------------------------------ | ----------------------------------------------- |
S
shawn_he 已提交
381 382 383 384 385 386 387
| Promise\<Array\<string>>         | Promise used to return the result.  |

**Error codes**

| ID| Error Message                                |
| ------- | ----------------------------------------|
| 201     | Permission denied.                      |
S
shawn_he 已提交
388
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
389 390
| 2200002 | Operation failed. Cannot connect to service.|
| 2200003 | System internal error.                  |
G
Gloria 已提交
391 392 393 394 395

**Example**

```js
ethernet.getAllActiveIfaces().then((data) => {
S
shawn_he 已提交
396 397 398 399
  console.log("getAllActiveIfaces promise data.length = " + JSON.stringify(data.length));
  for (let i = 0; i < data.length; i++) {
    console.log("getAllActiveIfaces promise  = " + JSON.stringify(data[i]));
  }
S
shawn_he 已提交
400
}).catch(error => {
S
shawn_he 已提交
401
  console.log("getAllActiveIfaces promise error = " + JSON.stringify(error));
G
Gloria 已提交
402 403 404
});
```

S
shawn_he 已提交
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
## ethernet.on('interfaceStateChange')<sup>10+</sup>

on(type: 'interfaceStateChange', callback: Callback\<{ iface: string, active: boolean }\>): void

Registers an observer for NIC hot swap events. This API uses an asynchronous callback to return the result.

**System API**: This is a system API.

**Required permission**: ohos.permission.GET_NETWORK_INFO

**System capability**: SystemCapability.Communication.NetManager.Ethernet

**Parameters**

| Name  | Type                                   | Mandatory| Description      |
| -------- | --------------------------------------- | ---- | ---------- |
| type     | string                  | Yes  | Event type. The value is **interfaceStateChange**.|
S
shawn_he 已提交
422
| callback | AsyncCallback\<{ iface: string, active: boolean }\> | Yes  | Callback used to return the result.<br>**iface**: NIC name.<br>**active**: whether the NIC is active. The value **true** indicates that the NIC is active, and the value **false** indicates the opposite.|
S
shawn_he 已提交
423 424 425 426 427

**Error codes**

| ID| Error Message                                     |
| ------- | -------------------------------------------- |
S
shawn_he 已提交
428
| 201     | Permission denied.                      |
S
shawn_he 已提交
429
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
430
| 401     | Parameter error.                     |
S
shawn_he 已提交
431 432 433 434

**Example**

```js
S
shawn_he 已提交
435 436
 ethernet.on('interfaceStateChange', (data) => {
  console.log('on interfaceSharingStateChange: ' + JSON.stringify(data));
S
shawn_he 已提交
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
});
```

## ethernet.off('interfaceStateChange')<sup>10+</sup>

off(type: 'interfaceStateChange', callback?: Callback\<{ iface: string, active: boolean }\>): void

Unregisters the observer for NIC hot swap events. This API uses an asynchronous callback to return the result.

**System API**: This is a system API.

**Required permission**: ohos.permission.GET_NETWORK_INFO

**System capability**: SystemCapability.Communication.NetManager.Ethernet

**Parameters**

| Name  | Type                                   | Mandatory| Description      |
| -------- | --------------------------------------- | ---- | ---------- |
| type     | string                  | Yes  | Event type. The value is **interfaceStateChange**.|
S
shawn_he 已提交
457
| callback | AsyncCallback\<{ iface: string, active: boolean }> | No  | Callback used to return the result.<br>**iface**: NIC name.<br>**active**: whether the NIC is active. The value **true** indicates that the NIC is active, and the value **false** indicates the opposite.|
S
shawn_he 已提交
458 459 460 461 462

**Error codes**

| ID| Error Message                                     |
| ------- | -------------------------------------------- |
S
shawn_he 已提交
463
| 201     | Permission denied.                      |
S
shawn_he 已提交
464
| 202     | Non-system applications use system APIs.                      |
S
shawn_he 已提交
465
| 401     | Parameter error.                     |
S
shawn_he 已提交
466 467 468 469 470 471 472

**Example**

```js
ethernet.off('interfaceStateChange');
```

S
shawn_he 已提交
473
## InterfaceConfiguration<sup>9+</sup>
G
Gloria 已提交
474 475 476

Defines the network configuration for the Ethernet connection.

S
shawn_he 已提交
477
**System API**: This is a system API.
G
Gloria 已提交
478

S
shawn_he 已提交
479 480 481 482 483 484 485 486 487 488
**System capability**: SystemCapability.Communication.NetManager.Ethernet

| Name         | Type                   | Mandatory| Description                                                        |
| ------------ | ----------------------- | ---|------------------------------------------------------------ |
| mode         | [IPSetMode](#ipsetmode) | Yes| Configuration mode of the Ethernet connection.|
| ipAddr       | string                  | Yes| Static IP address of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in Dynamic Host Configuration Protocol (DHCP) mode.|
| route        | string                  | Yes| Route of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.|
| gateway      | string                  | Yes| Gateway of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.|
| netMask      | string                  | Yes| Subnet mask of the Ethernet connection. The value must be an IPv4 address, which is a 32-bit number displayed in dotted decimal notation and each 8-bit field ranges from 0 to 255. This parameter does not need to be configured in DHCP mode.|
| dnsServers   | string                  | Yes| DNS server addresses of the Ethernet connection. The value must be an IPv4 address. This parameter does not need to be configured in DHCP mode. Multiple addresses are separated by commas (,).|
S
shawn_he 已提交
489
| httpProxy<sup>10+</sup> | [HttpProxy](js-apis-net-connection.md#httpproxy) | No| HTTP proxy of the Ethernet connection. By default, no proxy is configured.|
G
Gloria 已提交
490

S
shawn_he 已提交
491
## IPSetMode<sup>9+</sup>
G
Gloria 已提交
492 493 494

Defines the configuration mode of the Ethernet connection.

S
shawn_he 已提交
495 496 497
**System API**: This is a system API.

**System capability**: SystemCapability.Communication.NetManager.Ethernet
G
Gloria 已提交
498 499 500 501 502

| Name                 | Value  | Description                  |
| ------------------------ | ---- | ---------------------- |
| STATIC | 0 | Static configuration.|
| DHCP   | 1 | Dynamic configuration.|