Many windows systems are very familiar with the ipconfig command line tool, which is used to obtain and modify network interface configuration information. Linux has a similar tool, that is, ifconfig (interfacesconfig)
Generally, you need to log on as root or use sudo to use ifconfig on Linux machines. Depending on the ifconfig command, the ifconfig tool can be used not only to obtain the network interface configuration information, but also to modify these configurations.
1. command format:
Ifconfig [network device] [Parameters]
2. command functions:
Ifconfig command is used to view and configure network devices. When the network environment changes, you can use this command to configure the network.
3. command parameters:
Up to start the specified network device/NIC.
Down to disable the specified network device/NIC. This parameter can effectively block IP information flows through the specified interface. to permanently disable an interface, we also need to delete all route information of this interface from the core route table.
Arp settings specify whether the Nic supports the ARP protocol.
-Promisc indicates whether the promiscuous mode of the NIC is supported. If this parameter is selected, the NIC receives all the packets sent to the NIC.
-Allmulti: Specifies whether multicast mode is supported. If this parameter is selected, the network adapter receives all multicast packets in the network.
-A: displays all interface information.
-S displays summary information (similar to netstat-I)
Add to configure IPv6 address for the specified Nic
Del deletes the IPv6 address of the specified Nic
<硬件地址> Configure the maximum transmission unit for the network adapter
Mtu <字节数> Sets the maximum transmission unit (bytes) of the NIC)
Netmask <子网掩码> Set the subnet mask of the NIC. The mask can be a 32-bit hexadecimal number with a prefix of 0x, or four decimal numbers separated by dots. If you do not want to divide the network into subnets, skip this option. if you want to use subnets, remember that each system in the network must have the same subnet mask.
Establish a tunnel by using network Guard
Dstaddr sets a remote address to establish point-to-point communication
-Broadcast <地址> Set broadcast protocol for the specified Nic
-Pointtopoint <地址> Set point-to-point communication protocol for NICs
Multicast sets the multicast flag for the NIC
Address: set IPv4 address for the NIC
Txqueuelen <长度> Set the length of the transmission queue for the NIC
4. example:
Instance 1: Displays network device information (activated)
Command: ifconfig
Output:
Copy codeThe code is as follows:
[Root @ localhost ~] # 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 fig: 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)
Note:
Eth0 indicates the first network card. HWaddr indicates the physical address of the network card. you can see that the physical address (MAC address) of this network card is 00: 50: 56: BF: 26: 20.
Inet addr is used to indicate the IP address of the NIC. the IP address of the NIC is 192.168.120.204, the broadcast address, Bcast: 192.168.120.255, and Mask Address Mask: 255.255.255.0.
Lo indicates the host's bad return address. it is generally used to test a network program, but does not want users on the LAN or Internet to view it, you can only run and view the network interfaces on this host. For example, you can enter 127.0.0.1 in your browser to view your website. But you can only see it, and other hosts or users in the Lan cannot know it.
Line 1: connection type: Ethernet (Ethernet) HWaddr (hardware mac address)
Line 2: IP address, subnet, and mask of the NIC
Row 3: UP (indicating that the network card is enabled) RUNNING (indicating that the network card is connected) MULTICAST (supporting MULTICAST) MTU: 1500 (maximum transmission unit): 1500 bytes
4. five elements: Statistics on received and sent data packets
Row 7: Number of bytes of received and sent data.
Instance 2: enable or disable the specified Nic
Command:
Copy codeThe code is as follows:
Ifconfig eth0 up
Ifconfig eth0 down
Note:
Ifconfig eth0 up is the enable Nic eth0; ifconfig eth0 down is the enable Nic eth0. Be careful when logging on to the linux server through ssh. if it is disabled, it cannot be enabled unless you have multiple NICs.
Instance 3: Configure and delete IPv6 addresses for NICs
Command:
Copy codeThe code is as follows:
Ifconfig eth0 add 33ffe: 3240: 800: 1005: 2/64
Ifconfig eth0 del 33ffe: 3240: 800: 1005: 2/64
Note:
Ifconfig eth0 add 33ffe: 3240: 800: 1005: 2/64 configure the IPv6 address for the network adapter eth0;
Ifconfig eth0 add 33ffe: 3240: 800: 1005: 2/64 delete the IPv6 address for the Nic eth0;
During the practice, you must be careful when logging on to the linux server through ssh. if it is disabled, it cannot be enabled unless you have multiple NICs.
Example 4: Use ifconfig to modify the MAC address
Command: ifconfig eth0 hw ether 00: AA: BB: CC: DD: EE
Output:
Copy codeThe code is as follows:
[Root @ localhost ~] # Ifconfig eth0 down // disable the NIC
[Root @ localhost ~] # Ifconfig eth0 hw ether 00: AA: BB: CC: DD: EE // modify the MAC address
[Root @ localhost ~] # Ifconfig eth0 up // start the NIC
[Root @ localhost ~] # 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 fig: 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)
[Root @ localhost ~] # Ifconfig eth0 hw ether 00: 50: 56: BF: 26: 20 // disable the NIC and modify the MAC address
[Root @ localhost ~] # Ifconfig eth0 up // start the NIC
[Root @ localhost ~] # 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 fig: 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)
Instance 5: configure the IP address
Command:
Copy codeThe code is as follows:
[Root @ localhost ~] # Ifconfig eth0 192.168.120.56
[Root @ localhost ~] # Ifconfig eth0 192.168.120.56 netmask 255.255.255.0
[Root @ localhost ~] # Ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255
Note:
Ifconfig eth0 192.168.120.56
Configure IP address for eth0 Nic: 192.168.120.56
Ifconfig eth0 192.168.120.56 netmask 255.255.255.0
Configure the IP address 192.168.120.56 for the eth0 Nic, and add the sub-mask: 255.255.255.0
Ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255
Configure IP address: 192.168.120.56 for the eth0 Nic, add the sub-mask: 255.255.255.0, and add a broadcast address: 192.168.120.255
Instance 6: enable and disable ARP
Command:
Copy codeThe code is as follows:
Ifconfig eth0 arp
Ifconfig eth0-arp
Output:
Copy codeThe code is as follows:
[Root @ localhost ~] # Ifconfig eth0 arp
[Root @ localhost ~] # Ifconfig eth0-arp
Note:
Ifconfig eth0 arp enable the arp protocol of the eth0 Nic;
Ifconfig eth0-arp disable the arp protocol of the eth0 Nic;
Instance 7: set the maximum transmission unit
Command: ifconfig eth0 mtu 1500.
Output:
Copy codeThe code is as follows:
[Root @ localhost ~] # Ifconfig eth0 mtu1480
[Root @ localhost ~] # 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 fig: 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)
[Root @ localhost ~] # Ifconfig eth0 mtu1500
[Root @ localhost ~] # 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 fig: 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)
[Root @ localhost ~] #
Note:
Set the maximum data packet size that can pass to 1500 bytes.
Note: The Nic information configured with the ifconfig command does not exist after the NIC is restarted. To save the above configuration information to your computer forever, you need to modify the Nic configuration file.