ifconfig command
-
Function description: Display or set up network devices
-
usage
- ifconfig [interface] [up|down]
- ifconfig interface options | address ...
-
option
option Explain -a Displays the status of all interfaces, including information about inactive interfaces. up Start the specified network device down Turn off the specified network device
Show Network Devices
~]# ifconfig # Displays information about all active network interfaces on the current host ~]# ifconfig -a # Displays the status of all interfaces, including information about inactive interfaces
Example: Display information about all active network interfaces on the current host
[root@www ~]# ifconfig eth0 Link encap:Ethernet HWaddr F8:0F:41:03:97:29 inet addr:192.168.3.254 Bcast:192.168.3.255 Mask:255.255.255.0 inet6 addr: fe80::fa0f:41ff:fe03:9729/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:85770 errors:0 dropped:0 overruns:0 frame:0 TX packets:127036 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:12605281 (12.0 MiB) TX bytes:109423481 (104.3 MiB) Interrupt:16 eth1 Link encap:Ethernet HWaddr 50:78:4C:71:41:18 inet addr:192.168.2.254 Bcast:192.168.2.255 Mask:255.255.255.0 inet6 addr: fe80::5278:4cff:fe71:4118/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:132706 errors:0 dropped:0 overruns:0 frame:0 TX packets:84836 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:112099485 (106.9 MiB) TX bytes:12463939 (11.8 MiB) Interrupt:20 Base address:0xc000 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:168 errors:0 dropped:0 overruns:0 frame:0 TX packets:168 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:10056 (9.8 KiB) TX bytes:10056 (9.8 KiB)
For some explanations of the above information, take eth0 as an example
-
first line
- eth0: represents the first network card
- Link encap: Type of connection, Ethernet for Ethernet
- HWaddr: Hardware address of the network card, also known as MAC address
-
Second line
- inet addr:IPv4 address
- Bcast: Broadcast address (broadcast)
- Mask: Subnet mask (netmask)
-
Third line
- inet6 addr:IPv6 address
- Scope: Scope
-
Line 4
- UP: indicates that the network card is active
- BROADCAST: Indicates that the interface supports broadcasting
- RUNNING: Indicates that the interface is active
- MULTICAST: Represents support for multicast (multicast) functionality
- MTU: Indicates that the maximum transfer unit of a network card cannot exceed 1500 bytes
- Metric: Measure
-
Line 5
- RX: Indicates receipt
- packets: Indicates the number of messages received after the network card is activated.Convert in bytes
- Errors: indicates the number of errors received
- Dropped: indicates the number of dropped packets received
- Overruns: indicates the number of overruns
- Frame: Represents a frame, and a frame error indicates a CRC error after receiving a frame.This can be caused by a damaged cable or by a damaged interface on a machine or switch.
-
Line 6
- TX: means send
- TX packets: Indicates the number of deliveries.Convert in bytes
- TX errors: Indicates the number of errors sent
- Dropped: Indicates the number of packets dropped in a send
- Overruns: indicates the number of overruns
- Carrier: carrier, the higher the value, the lower the network performance
- collisions: The number of conflicting packets whose value should be zero or at least a decimal number, if too large a number indicates that a considerable number of packets in the network are interfering with each other
- txqueuelen: Represents the length of the transmission queue
Note: Normally errors, dropped, overruns, frame s, carrier s should all have values of 0, if greater than 0, they can be network interfaces or cable damage.
Set up network devices
ifconfig interface IP/NETMASK [up|down] ifconfig interface IP netmask MASK [up|down]
Example 2: Modify eth1's network card interface address to 192.168.2.22
Method 1: [root@www ~]# ifconfig eth1 192.168.2.22/24 //Method 2: [root@www ~]# ifconfig eth1 192.168.2.22 netmask 255.255.255.0
Note: Configuration based on the command line is only valid on the current system, but restarting the system is not.Edit the profile to be permanently valid.
Example 3: Enable or turn off confounding mode
[root@www ~]# ifconfig eth0 promisc #Enable mixed mode [root@www ~]# ifconfig eth0 -promisc #Turn off confounding mode
Hybrid mode is a necessary step for us to achieve network monitoring.The effect of enabling the confusion mode is that each host will not receive messages if the destination address is not itself when receiving them. When enabling the confusion mode, if the destination address is not itself, it will also receive messages so that we can grab packets locally and analyze network communication.