Configure and display network parameters of Linux system network card
ifconfig command is used to configure and display network parameters of network interfaces in the Linux kernel. The network card information configured with the ifconfig command will no longer exist after the network card is restarted and the machine is restarted. If you want to store the above configuration information in your computer forever, you need to modify the configuration file of the network card.
ifconfig(parameter)
add<address>: Set the IPv6 ip address of the network device;
del<address>: Delete the IP address of the network device IPv6;
down: Shut down the specified network device;
<hw<network device type><hardware address>: Set the type and hardware address of the network device;
io_addr<I/O address>: Set the I/O address of the network device;
irq<IRQ address>: Set the IRQ of the network device;
media<network media type>: Set the media type of the network device;
mem_start <memory address>: Set the starting address occupied by the network device in the main memory;
metric<number>: Specifies the number to be added when calculating the number of packet transmissions;
mtu<byte>: Set the MTU of the network device;
netmask<subnet mask>: Set the subnet mask of the network device;
tunnel<address>: establish the tunnel communication address between IPv4 and IPv6;
up: Start the specified network device;
-broadcast<address>: Treat the data packet sent to the specified address as a broadcast packet;
-pointopoint<address>: Establish a direct connection with the network device at the specified address. This mode has a confidentiality function;
-promisc: Close or enable the promiscuous mode of the specified network device;
IP address: Specify the IP address of the network device;
Network device: Specify the name of the network device.
Display network device information (activated):
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:16:3E:00:1E:51
inet addr:10.160.7.81 Bcast:10.160.15.255 Mask:255.255.240.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:61430830 errors:0 dropped:0 overruns:0 frame:0
TX packets:88534 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3607197869 (3.3 GiB) TX bytes:6115042 (5.8 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:56103 errors:0 dropped:0 overruns:0 frame:0
TX packets:56103 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5079451 (4.8 MiB) TX bytes:5079451 (4.8 MiB)
illustrate:
eth0 represents the first network card, where HWaddr
represents the physical address of the network card. You can see that the current physical address (MAC address) of this network card is 00:16:3E:00:1E:51
.
inet addr is used to represent the IP address of the network card. The IP address of this network card is 10.160.7.81
, the broadcast address Bcast:10.160.15.255
, and the mask address Mask:255.255.240.0
.
lo represents the return address of the host. This is generally used to test a network program, but does not want users on the LAN or external network to view it. It can only run and view the network interface used on this host. . For example, specify the return address of the httpd server and enter 127.0.0.1 in the browser to see your WEB website. But only you can see it, other hosts or users on the LAN have no way of knowing.
Start and shut down the specified network card:
ifconfig eth0 up
ifconfig eth0 down
ifconfig eth0 up
is to start the network card eth0, and ifconfig eth0 down
is to shut down the network card eth0. Be careful when logging into a Linux server via ssh. Once it is turned off, it cannot be turned on unless you have multiple network cards.
Configure and remove IPv6 addresses for network cards:
ifconfig eth0 add 33ffe:3240:800:1005::2/64 #Configure the IPv6 address for the network card eth0
ifconfig eth0 del 33ffe:3240:800:1005::2/64 #Delete the IPv6 address for the network card eth0
Use ifconfig to modify the MAC address:
ifconfig eth0 hw ether 00:AA:BB:CC:dd:EE
Configure IP address:
[root@localhost ~]# ifconfig eth0 192.168.2.10
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0
[root@localhost ~]# ifconfig eth0 192.168.2.10 netmask 255.255.255.0 broadcast 192.168.2.255
Enable and disable arp protocol:
ifconfig eth0 arp #Enable the arp protocol of the network card eth0
ifconfig eth0 -arp #Close the arp protocol of the network card eth0
Set maximum transmission unit:
ifconfig eth0 mtu 1500 #Set the maximum packet size that can be passed to 1500 bytes
Other examples
ifconfig #Activated network interface
ifconfig -a #All configured network interfaces, regardless of whether they are activated or not
ifconfig eth0 #Display the network card information of eth0