Many windows are familiar with the ipconfig command-line tool, which is used to obtain and modify network interface configuration information. The Linux system has a similar tool, the ifconfig (Interfaces config). You typically need to log in as root or use sudo to use the Ifconfig tool on a Linux machine. Depending on the options properties used in the Ifconfig command, the Ifconfig tool can be used to simply obtain network interface configuration information and modify these configurations.
1. Command format:
ifconfig [Network Devices] [parameters]
2. Command function:
The Ifconfig command is used to view and configure network devices. This command can be used to configure the network appropriately when the network environment changes.
3. Command parameters:
Up starts the specified network device/NIC.
Down to turn off the specified network device/NIC. This parameter can effectively block the IP traffic through the specified interface, and if you want to permanently shut down an interface, we also need to remove all the routing information from the core routing table from that interface.
-A displays all interface information
-S Display summary information (similar to netstat-i)
Add to configure the IPV6 address for the specified NIC
Del deletes the IPV6 address of the specified network card
4. Usage examples:
Example 1: Displaying network device information (active state)
Command:
Ifconfig
Output:
[Email protected] ~]# ifconfig
Eth0 Link encap:ethernet HWaddr 00:50:56:bf:26:20
inet addr:192.168.120.204 bcast:192.168.120.255 mask:255.255.255.0
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:8700857 errors:0 dropped:0 overruns:0 frame:0
TX packets:31533 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:596390239 (568.7 MiB) TX bytes:2886956 (2.7 MiB)
Lo Link encap:local Loopback
inet addr:127.0.0.1 mask:255.0.0.0
Up LOOPBACK RUNNING mtu:16436 metric:1
RX packets:68 errors:0 dropped:0 overruns:0 frame:0
TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2856 (2.7 KiB) TX bytes:2856 (2.7 KiB)
Description
Eth0 represents the first network card, where HWaddr represents the physical address of the network card, you can see the current physical address of the network card (MAC address) is 00:50:56:bf:26:20
Inet addr is used to indicate the IP address of the network card, the IP address of this network card is 192.168.120.204, broadcast address, bcast:192.168.120.255, mask address mask:255.255.255.0
Lo is the return of the host's bad address, which is generally used to test a network program, but do not want to let the local area network or extranet users can view, can only run on this host and view the network interface used. For example, the HTTPD server is assigned to the bad address, in the browser input 127.0.0.1 will be able to see your Web site. But you can only see that the other host or user of the LAN is unknown.
First line: Connection type: Ethernet (Ethernet) HWADDR (Hardware MAC address)
Second line: IP address, subnet, mask of network card
Third line: Up (for Nic on) RUNNING (network cable on behalf of the NIC is connected) multicast (support multicast) mtu:1500 (Maximum transmission Unit): 1500 bytes
Line fourth to fifth: Receive, send packet statistics
Line seventh: Receive, send data byte count statistics.
Example 2: Start and close the specified NIC
Command:
Ifconfig eth0 up
Ifconfig eth0 Down
Output:
Description
Ifconfig eth0 up is the boot Nic eth0, ifconfig eth0 down to turn off the NIC Eth0. SSH login Linux Server operation be careful, shut down can not be turned on, unless you have multiple network cards.
Example 3: Configuring and removing IPV6 addresses for network cards
Command:
Ifconfig eth0 Add 33FFE:3240:800:1005::2/64
Ifconfig eth0 del 33ffe:3240:800:1005::2/64
Output:
Description
Ifconfig eth0 Add 33ffe:3240:800:1005::2/64 to configure the IPV6 address for the NIC Eth0;
Ifconfig eth0 Add 33ffe:3240:800:1005::2/64 to remove the IPV6 address for the NIC Eth0;
Practice, SSH login Linux server operation to be careful, shut down can not be opened, unless you have multiple network cards.
Example 4: Modifying MAC addresses with Ifconfig
Command:
ifconfig eth0 hw ether 00:aa:bb:cc:dd:ee
Example 5: Configuring IP Addresses
Command:
Output:
[Email protected] ~]# ifconfig eth0 192.168.120.56
[Email protected] ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0
[Email protected] ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255
Description
Ifconfig eth0 192.168.120.56
Configure IP to eth0 NIC: 192.168.120.56
Ifconfig eth0 192.168.120.56 netmask 255.255.255.0
Configure IP address for eth0 NIC: 192.168.120.56, plus child mask: 255.255.255.0
Ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255
/to the ETH0 network card configuration IP address: 192.168.120.56, plus the child mask: 255.255.255.0, plus a broadcast address: 192.168.120.255
Note: The NIC information configured with the Ifconfig command does not exist after the machine restarts after the network card restarts. In order to keep the above configuration information in the computer forever, it is necessary to modify the network card configuration file.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
37. Ifconfig command