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.
The ARP setting specifies whether the NIC supports the ARP protocol.
-promisc sets whether the promiscuous mode of the NIC is supported, and if this parameter is selected, the NIC will receive all packets sent to it in the network
-allmulti Settings Support multicast mode, if you select this parameter, the NIC will receive all multicast packets in the network
-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
< hardware address > Configure the Maximum transmission unit of the NIC
mtu< bytes > Set the Maximum Transmission Unit (bytes) of the NIC
netmask< Subnet mask > Set subnet mask for network card. The mask can be a 32-bit hexadecimal number with a prefix of 0x, or 4 decimal digits separated by dots. If you do not plan to divide the network into subnets, you can ignore this option, and if you want to use subnets, remember that each system in the network must have the same subnet mask.
Tunel establishing a tunnel
DSTADDR set a remote address to establish point-to-point communication
-broadcast< address > Set up a broadcast protocol for a specified network card
-pointtopoint< address > Set up Point-to-point communication protocol for network card
Multicast setting the multicast flag for the network card
Address sets IPV4 addresses for network cards
txqueuelen< length > Set the length of the transmission queue for the 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 NIC,
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 designation of the HTTPD server to the return bad address, in the browser output
You'll be able to see your Web site in 127.0.0.1. 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
Output:
[[email protected] ~]# ifconfig eth0 down//close NIC
[[email protected] ~]# ifconfig eth0 hw ether 00:aa:bb:cc:dd:ee//Modify MAC Address
[[email protected] ~]# ifconfig eth0 up//start NIC
[Email protected] ~]# ifconfig
Eth0 Link encap:ethernet HWaddr 00:aa:bb:cc:dd:ee
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)
[[email protected] ~]# ifconfig eth0 hw ether 00:50:56:bf:26:20//Turn off NIC and modify MAC address
[[email protected] ~]# ifconfig eth0 up//start NIC
[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
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, Configure the IP address for the ETH0 network card: 192.168.120.56, plus the child mask: 255.255.255.0, plus a broadcast address: 192.168.120.255
Example 6: Enabling and shutting down the ARP protocol
Command:
Ifconfig eth0 ARP
Ifconfig Eth0-arp
Output:
[[email protected] ~]# ifconfig eth0 ARP
[Email protected] ~]# ifconfig eth0-arp
Description
Ifconfig eth0 ARP to open the network card eth0 ARP protocol;
Ifconfig Eth0-arp shut down the network card eth0 ARP protocol;
Example 7: Setting the Maximum transmission unit
Command:
Ifconfig eth0 MTU 1500
Output:
[[email protected] ~]# ifconfig eth0 MTU 1480
[Email protected] ~]# ifconfig
Eth0 Link encap:ethernet HWaddr 00:50:56:bf:26:1f
inet addr:192.168.120.203 bcast:192.168.120.255 mask:255.255.255.0
Up broadcast RUNNING multicast mtu:1480 metric:1
RX packets:8712395 errors:0 dropped:0 overruns:0 frame:0
TX packets:36631 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:597062089 (569.4 MiB) TX bytes:2643973 (2.5 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:9973 errors:0 dropped:0 overruns:0 frame:0
TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:518096 (505.9 KiB) TX bytes:518096 (505.9 KiB)
[[email protected] ~]# ifconfig eth0 MTU 1500
[Email protected] ~]# ifconfig
Eth0 Link encap:ethernet HWaddr 00:50:56:bf:26:1f
inet addr:192.168.120.203 bcast:192.168.120.255 mask:255.255.255.0
Up broadcast RUNNING multicast mtu:1500 metric:1
RX packets:8712548 errors:0 dropped:0 overruns:0 frame:0
TX packets:36685 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:597072333 (569.4 MiB) TX bytes:2650581 (2.5 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:9973 errors:0 dropped:0 overruns:0 frame:0
TX packets:9973 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:518096 (505.9 KiB) TX bytes:518096 (505.9 KiB)
[Email protected] ~]#
Description
Set the maximum packet size that can be passed to bytes
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.
Linux command--52 ifconfig (GO)