加入收藏
举报
02-14 20:03
#0
文件名称:
ifconfig.md
所在目录:
Openharmony v1.0 / docs / docs-en / kernel
文件大小:
22.08 KB
下载地址:
fenwii/OpenHarmony
   
免责声明:本网站仅提供指向 GitHub 上的文件的链接,所有文件的版权归原作者所有,本网站不对文件内容的合法性、准确性或安全性承担任何责任。
文本预览:
# ifconfig
## Command Function
This command is used to query and set parameters of a NIC, such as the IP address, subnet mask, gateway, and MAC address, and enable or disable the NIC.
## Syntax
ifconfig
\[_-a_\]
<_interface_\> <_address_\> \[_netmask _\] \[_gateway _\]
\[_hw ether _\] \[_mtu _\]
\[_inet6 add _\]
\[_inet6 del _\]
\[_up|down_\]
## Parameter Description
**Table 1** Parameters























































Parameter


Description


Value Range


No parameter


Displays information about all NICs, including the IP addresses, subnet masks, gateways, MAC addresses, maximum transmission units (MTUs), and running statuses.


N/A


-a


Displays data sent and received by the protocol stack.


N/A


interface


Indicates the NIC name, for example, eth0.


N/A


address


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


N/A


netmask


Indicates the subnet mask, for example, 255.255.255.0.


N/A


gateway


Indicates the gateway, for example, 192.168.1.1.


N/A


hw ether


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


N/A


mtu


Indicates the MTU size, for example, 1000.


  • For IPv4:

    [68,1500]


  • For IPv6:

    [1280, 1500]



add


Indicates 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. Setting 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


Indicates the IP address of the board.


netmask


Indicates the subnet mask.


gateway


Indicates the gateway.


HWaddr


Indicates the MAC address of the board.


MTU


Indicates the MTU.


Running/Stop


Indicates whether the NIC is running.


Default


Indicates that the NIC is connected to the default gateway.


Link UP/Down


Indicates the connection status of the NIC.



2. Obtaining 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


Indicates the number of normal packets that have been received at the IP layer.


RX error


Indicates the number of error packets that have been received at the IP layer. The errors include the length, verification, IP option, and IP header protocol errors.


RX dropped


Indicates the number of packets that have been discarded at the IP layer. Packets may be discarded due to packet errors, packet forwarding failures, and disabled local NICs.


RX overrun


Indicates the 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


Indicates the total length of normal packets that have been received at the IP layer, excluding the length of the fragments that are not reassembled.


TX packets


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


TX error


Indicates the 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


Indicates the 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


Indicates the total length of the packets that the IP layer has successfully sent or forwarded.



3. Setting 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. Deleting 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
```
点赞 回复
回帖
支持markdown部分语法 ?