Use of Linux ifconfig command

Use of Linux ifconfig command

1. Command Introduction

The ifconfig (configure a network interface) command is a system administrator command used to view and configure network interfaces.

2. Command format

ifconfig [-v] [-a] [-s] [INTERFACE]
ifconfig [-v] INTERFACE [aftype] OPTIONS | ADDRESS ...

3. Option Description

-a
	Display the status of all interfaces, including those that are down.
	Displays a brief list of interface status, similar to netstat -i
-v
	Verbose mode, error message will be reported if an error occurs INTERFACE
	The name of the interface. This is usually a driver name followed by a unit number, such as eth0 for the first Ethernet interface.
up
	This flag causes the interface to be activated. If an address is assigned to an interface, the interface is implicitly activated down
	This flag is used to shut down the driver of the interface [-]arp
	Enable or disable the interface to use the ARP protocol [-]promisc
	Enable or disable promiscuous mode for an interface. If checked, all packets on the network will be received by the interface [-]allmulti
	Enable or disable all multicast modes. If checked, the interface will receive all multicast packets on the network (mtu N).
	Set the maximum transmission unit of the interface dstaddr ADDR
	Sets the remote IP address for point-to-point links such as PPP. The dstaddr keyword is now obsolete. Use the pointopoint keyword instead. netmask ADDR
	Sets the IP network mask for the interface. This value defaults to the usual class A, B, or C network mask (derived from the interface IP address), but can be set to any value add ADDR/PREFIX_LEN
	Add an IPv6 address to the interface del ADDR/PREFIX_LEN
	Remove the IPv6 address tunnel::aa.bb.cc.dd from the interface
	Creates a new SIT (IPv6-in-IPv4) device that tunnels to the given destination irq ADDR
	Sets the interrupt line used by this device. Not all devices can change their IRQ dynamically Set io_addr ADDR
	Set the starting address mem_start ADDR in the I/O space for the device
	Sets the starting address of shared memory used by this device. Only a few devices require this media TYPE
	Set the physical port or media type to be used by the device. Typical type values ​​are 10base2 (thin Ethernet), 10baseT (10Mbps Ethernet over twisted pair), AUI (external transceiver), etc. Special media types can use auto to tell the driver to automatically sense them. Note that not all devices can change this setting [-]broadcast [ADDR]
	If the address argument is given, sets the protocol broadcast address for this interface. Otherwise set (or clear) the IFF_BROADCAST flag of the interface [-]pointopoint [ADDR]
	This keyword enables point-to-point mode of the interface, which means it is a direct connection between two machines with nobody else listening on it. If the address argument is given, it sets the protocol address of the other end, just like the obsolete dstaddr keyword. Otherwise, set or clear the IFF_POINTOPOINT flag of the interface hw CLASS ADDR
	Sets the physical address of this interface, if the device driver supports this operation. CLASS is the hardware type name and ADDR is the physical address. Currently supported hardware types include ether (Ethernet), ax25 (AMPR AX.25), ARCnet, and netrom (AMPR NET/ROM)
multicast
	Set the multicast flag on the interface. Normally no display settings are needed, as the driver itself will set the correct flag ADDRESS
	IP address of the interface txqueuelen LENGTH
	Sets the length of the device's transmit queue. For slower devices with high latency (modem links, ISDN), it is useful to set this to a small value to prevent fast bulk transfers from interfering too much with interactive communications such as telnet.

4. Common Examples

(1) Check the information of the active network interface.

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)

eth0 represents the first network card.

The first line Link encap:Ethernet indicates that the connection type is Ethernet, and HWaddr 00:16:3E:00:1E:51 is the physical address of the network card;
The second line inet addr:10.160.7.81 is the IPv4 address of the network card, Bcast:10.160.15.255 is the broadcast address, and Mask:255.255.240.0 is the subnet mask;
The third line UP (indicates the network card is turned on), BROADCAST (supports broadcast), RUNNING (indicates that the network cable of the network card is connected), MULTICAST (supports multicast), MTU:1500 (maximum transmission unit 1500 bytes), Metric:1 indicates the priority of the network card routing data packet, the lower the value, the higher the priority;
The fourth and fifth rows: statistics of received and sent data packets;
Line 7: Statistics of the number of bytes of data received and sent.

lo is the loopback address of the host, which is generally used to test a network program. It can only be accessed on the local machine and cannot be accessed by hosts on the LAN or the Internet.

(2) View information about all network interfaces, regardless of whether they are activated or not.

ifconfig -a

(3) View the specified network interface information.

ifconfig eth0

(4) Start and stop the specified network card.

# Start the network card ifconfig eth0 up
# Shut down the network card ifconfig eth0 down

(5) Modify the MAC address.

ifconfig eth0 down
ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE
ifconfig eth0 up

(6) Configure the IP address.

# Configure an IP address for the eth0 network card ifconfig eth0 192.168.1.56

# Configure an IP address and subnet mask for the eth0 network card ifconfig eth0 192.168.1.56 netmask 255.255.255.0 

# Configure an IP address for the eth0 network card, plus the subnet mask and broadcast address ifconfig eth0 192.168.1.56 netmask 255.255.255.0 broadcast 192.168.1.255

(7) Enable and disable ARP protocol.

# Enable the arp protocol for network card eth0 ifconfig eth0 arp
# Disable the arp protocol of network card eth0 ifconfig eth0 -arp

(8) Set the maximum transmission unit.

# Set the maximum packet size that can pass to 1500 bytes
ifconfig eth0 mtu 1500

The above is the detailed content of the use of Linux ifconfig command. For more information about Linux ifconfig command, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Use of Linux gzip command
  • Usage of Linux userdel command
  • Use of Linux date command
  • Use of Linux telnet command
  • Linux gzip command compression file implementation principle and code examples
  • 5 Commands to Use the Calculator in Linux Command Line
  • Use of Linux ls command

<<:  Use of Linux crontab command

>>:  How to completely uninstall node and npm on mac

Recommend

How to connect a Linux virtual machine to WiFi

In life, the Internet is everywhere. We can play ...

Summary of React's way of creating components

Table of contents 1. Create components using func...

Detailed explanation of the flexible use of CSS grid system in projects

Preface CSS grids are usually bundled in various ...

Detailed explanation of daily_routine example code in Linux

First look at the example code: #/bin/bash cal da...

MySQL tutorial DML data manipulation language example detailed explanation

Table of contents 1. Data Manipulation Language (...

Vue implements carousel animation

This article example shares the specific code of ...

JQuery implements hiding and displaying animation effects

This article shares the specific code of JQuery t...

How to output Chinese characters in Linux kernel

You can easily input Chinese and get Chinese outp...

Example code for realizing charging effect of B station with css+svg

difficulty Two mask creation of svg graphics Firs...

How to deal with time zone issues in Docker

background When I was using Docker these two days...

CSS3 new layout: flex detailed explanation

Flex Basic Concepts Flex layout (flex is the abbr...

Nginx Linux installation and deployment detailed tutorial

1. Introduction to Nginx Nginx is a web server th...

JavaScript Basics Variables

Table of contents 1. Variable Overview 1.1 Storag...

How to delete table data in MySQL

There are two ways to delete data in MySQL, one i...