ifconfig
Command Function
This command can be used to:
- Query and set network interface card (NIC) parameters, such as the IP address, network mask, gateway, and MAC address.
- Disable or enable a NIC.
Syntax
ifconfig
[-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
- 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
- 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
-
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 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
-
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)
The following table describes the output parameters.
Table 3 ifconfig -a output description
-
Set 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
-
Delete 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