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
Usage
- The ifconfig 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: 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 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
The following table describes the output parameters.
Table 2 Output description
-
Example 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
-
Example 3: setting 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: deleting 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