openharmony 鸿蒙 kernel-small-debug-shell-net-ifconfig

2022-08-09 浏览 (981)

ifconfig

Command Function

This command can be used to:

  • Query and set parameters of a network interface card (NIC), such as the IP address, network mask, gateway, and MAC address.

  • Enable or disable a NIC.

Syntax

ifconfig [option]

option:

  • [-a]

  • <interface> <address> [netmask <mask>] [gateway <address>]

  • [hw ether <address>] [mtu <size>]

  • [inet6 add <address>]

  • [inet6 del <address>]

  • [up|down]

Parameters

Table 1 Parameter description

ParameterDescriptionValue Range
No parameterDisplays 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
-aDisplays data sent and received by the protocol stack.N/A
interfaceSpecifies the NIC name, for example, eth0.N/A
addressSpecifies the IP address, for example, 192.168.1.10. The NIC name must be specified.N/A
netmaskSpecifies the subnet mask, for example, 255.255.255.0.N/A
gatewaySpecifies the gateway, for example, 192.168.1.1.N/A
hw etherSpecifies the MAC address, for example, 00:11:22:33:44:55. Currently, only the ether hardware type is supported.N/A
mtuSpecifies the MTU size, for example, 1000.- IPv4: [68, 1500]
- IPv6:[1280, 1500]
addSpecifies the IPv6 address, for example, 2001:a:b:c:d:e:f:d. The NIC name and inet6 must be specified.N/A
delDeletes an IPv6 address. You need to specify the NIC name and add the inet6 option. For details, see the example.N/A
upEnables the data processing function of the NIC. The NIC name must be specified.N/A
downDisables the data processing function of the NIC. The NIC name must be specified.N/A

Usage Guidelines

  • This command can be used only after the TCP/IP stack is enabled.

  • 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.

Example

  • ifconfig eth0 192.168.100.31 netmask 255.255.255.0 gateway 192.168.100.1 hw ether 00:49:cb:6c:a1:31

  • ifconfig -a

  • ifconfig eth0 inet6 add 2001:a:b:c:d:e:f:d

  • ifconfig eth0 inet6 del 2001:a:b:c:d:e:f:d

Output

  • Example 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
    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
    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
    

    Table 2 Parameter description

ParameterDescription
ipIP address of the board.
netmaskSubnet mask.
gatewayGateway.
HWaddrMAC address of the board.
MTUMaximum transmission unit.
Running/StopWhether the NIC is running.
DefaultIndicates that the NIC is connected to the default gateway.
Link UP/DownConnection status of the NIC.
  • Example 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)
    

    Table 3 ifconfig -a parameter description

ParameterDescription
RX packetsNumber of normal packets received at the IP layer.
RX errorNumber of error packets received at the IP layer. The errors include the length error, verification error, IP option error, and IP header protocol error.
RX droppedNumber of packets discarded at the IP layer. Packets are discarded due to packet errors, packet forwarding failures, and disabled local NICs.
RX overrunNumber 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.
RX bytesTotal length of normal packets received at the IP layer, excluding the length of the fragments that are not reassembled.
TX packetsNumber of packets that have been normally sent or forwarded at the IP layer.
TX errorNumber 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 droppedNumber of packets that the MAC layer discards due to delivery failures, for example, the NIC driver fails to process the packets.
TX overrunNot used currently.
TX bytesTotal length of the packets successfully sent or forwarded at the IP layer.
  • Example 3: Set an IPv6 address.

    OHOS:/$ ifconfig eth0 inet6 add 2001:a:b:c:d:e:f:d
    NetifStatusCallback(eth0): nsc event: 0x8
    NetifStatusCallback(eth0): nsc status changed: 0
    NetifStatusCallback(eth0): nsc event: 0x200
    NetifStatusCallback(eth0): nsc event: 0x8
    NetifStatusCallback(eth0): nsc status changed: 1
    NetifStatusCallback(eth0): nsc event: 0x200
    NetifStatusCallback(eth0): nsc event: 0x200
    OHOS:/$ ifconfig
    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
    eth0    ip:192.168.1.10 netmask:255.255.255.0 gateway:192.168.1.1
            ip6: 2001:A:B:C:D:E:F:D/64
            HWaddr 66:2f:e5:bd:24:e6 MTU:1500 Running Default Link UP
    
  • Example 4: Delete an IPv6 address.

    OHOS:/$ ifconfig eth0 inet6 del 2001:a:b:c:d:e:f:d
    NetifStatusCallback(eth0): nsc event: 0x200
    OHOS:/$ ifconfig
    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
    eth0    ip:192.168.1.10 netmask:255.255.255.0 gateway:192.168.1.1
            HWaddr 66:2f:e5:bd:24:e6 MTU:1500 Running Default Link UP
    

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Kernel

harmony 鸿蒙Kernel Coding Specification

harmony 鸿蒙Standard Libraries

harmony 鸿蒙Interrupt Management

harmony 鸿蒙Event

harmony 鸿蒙Mutex

harmony 鸿蒙Queue

harmony 鸿蒙Semaphore

harmony 鸿蒙Doubly Linked List

harmony 鸿蒙Memory Management

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/22b228641ba84333afcd0ad6df9c07a7