Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the Linux ifconfig command

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to use the Linux ifconfig command". The editor shows you the operation process through the actual case. The operation method is simple, fast and practical. I hope this article "how to use the Linux ifconfig command" can help you solve the problem.

The ifconfig command in the Linux system is used to display or set the network device, and ifconfig can set the status of the network device or display the current settings.

Syntax ifconfig [Network device] [down up-allmulti-arp-promisc] [add] [del] [] [io_addr] [irq] [media] [mem_start] [metric] [mtu] [netmask] [tunnel] [- broadcast] [- pointopoint] [IP address] Parameter description:

Add sets the IP address of the network device IPv6.

Del deletes the IP address of the network device IPv6.

Down shuts down the specified network device.

Set the type and hardware address of the network device.

Io_addr sets the Istroke O address of the network device.

Irq sets the IRQ of the network device.

Media sets the media type of the network device.

Mem_start sets the starting address occupied by the network device in the main memory.

Metric specifies the number to be added when calculating the number of forwarding packets.

Mtu sets the MTU of the network device.

Netmask sets the subnet mask for network devices.

Tunnel establishes a tunnel communication address between IPv4 and IPv6.

Up starts the specified network device.

-broadcast treats packets to be sent to the specified address as broadcast packets.

-pointopoint establishes a direct connection with the network device at the specified address. This mode has the function of confidentiality.

-promisc turns off or starts the promiscuous mode of the specified network device.

[IP address] specifies the IP address of the network device.

[network device] specifies the name of the network device.

Ifconfig command practice 1, display network card information (1) display active network card information ifconfig if the network card is closed, it will not be displayed.

(2) display all network card information ifconfig-a (3) display brief information of network card ifconfig-s (4) display information of specified network card ifconfig [name of network card] / example: ifconfig enp0s3 (5) Network card information explain hrx@@@:~$ ifconfig enp0s3 Link encap:Ethernet HWaddr 08:00:27:bd:61:3c inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255 .255.0 inet6 addr: fe80::7035:2dfa:8d80:ea7e/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:4 errors:0 dropped:0 overruns:0 frame:0 TX packets:115 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:930 (930.0 B) TX bytes:14560 (14.5 KB) ) Interrupt:19 Base address:0xd020 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: 1Accord 128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:32 errors:0 dropped:0 overruns:0 frame:0 TX packets:32 errors:0 dropped:0 overruns:0 carrier:0 Collisions:0 txqueuelen:1000 RX bytes:2386 (2.3KB) TX bytes:2386 (2.3KB) Nic name: enp0s3, Lo

Link encap: interface type of network card, Ethernet (Ethernet), Local Loopback (local loopback)

HWaddr: the hardware address of the network card, that is, MAC address

Inet addr:IPv4 address

Bcast: broadcast addr

Mask: subnet mask addr

Inet6 addr:IPv6 address

Scope: used to limit the scope of IPv6 multicast, Host (host local scope), Link (link local scope), Site (site local scope, obsolete), Global (global scope)

UP: indicates that the network card is on. If the network card is closed, it will not be displayed.

BROADCAST: indicates that the network card supports broadcasting

RUNNING: indicates that the network card is running

MULTICAST: indicates that the network card supports multicast. If the network card does not support it, it will not be displayed.

MTU: maximum transmission unit, for more information: https://developer.aliyun.com/article/222535

Metric: the number of hops, usually the number of hops required to reach the destination address, and a hop represents a router. In addition, the higher the hop value, the higher the priority.

RX line: represents the total number of packets, errors, discarded, overloaded and frames received by the Nic since it was started.

TX line: represents the total number of packets, errors, discarded, overloaded and frames sent by the network card since it was started.

Collisions: the number of collisions and collisions of packets. A large number of times means that the network is not very good.

Txqueuelen: send queue length

RX bytes: number of bytes received

TX bytes: number of bytes sent

Interrupt:IRQ interrupt address

Base address: base address

2. Specify the switch of the network card. Here, take the enp0s3 network card as an example. Using ifconfig will not be displayed when the network card is turned off.

/ / start the enp0s3 network card sudo ifconfig enp0s3 up / / disable the enp0s3 network card sudo ifconfig enp0s3 down3 and specify the ARP protocol switch of the network card. Here, take the enp0s3 network card as an example. ARP protocol is an address resolution protocol (Address Resolution Protocol). Each host or router maintains an ARP cache table (ARP table), which contains the mapping from IP address to MAC address, and pairs are recorded in the table, so as to realize the query and translation between IP address and MAC address. For more information: https://blog.csdn.net/jiejiemcu/article/details/88406088

/ / start the ARP protocol of the enp0s3 network card sudo ifconfig enp0s3 arp / / disable the ARP protocol sudo ifconfig enp0s3-arp4 of the enp0s3 network card, and set the IPv4 address and subnet mask (temporary) of the network card. Here, take the enp0s3 network card as an example. Subnet mask conversion: 24 is equal to 255.255.255.0, meaning in binary terms, all 24 bits from the left take 1, and the rest are 0. That is 11111111 11111111 11111111 00000000, that is 255.255.255.0

/ / modify the IPv4 address of the network card enp0s3 sudo ifconfig enp0s3 10.0.2.16 / modify the IPv4 address and subnet mask of the network card enp0s3, method 1 sudo ifconfig enp0s3 10.0.2.16 netmask 24 / modify the IPv4 address and subnet mask of the network card enp0s3, method 2 sudo ifconfig enp0s3 10.0.2.16 netmask 255.255.255.05, configure the virtual interface of the network card (temporary) here take the enp0s3 network card as an example. It is equivalent to configuring another IP address for the network card.

Sudo ifconfig enp0s3:0 10.0.2.16/24 sudo ifconfig enp0s3:1 10.0.2.17/24 sudo ifconfig enp0s3:2 10.0.2.18/24

6. Set the MAC address of the network card (temporary) here take the enp0s3 network card as an example. Note: the network card down needs to be dropped before it can be set, otherwise it will prompt "SIOCSIFHWADDR: device or resource busy-you may need to down the interface"

/ / modify the MAC address sudo ifconfig enp0s3 hw ether 08:00:27:bd:61:3d of the network card

7. Set the maximum transmission unit of the network card (temporary) here take the enp0s3 network card as an example. The units are bytes.

/ / set the maximum transmission unit sudo ifconfig enp0s3 mtu 14808 of the network card, and add and delete the IPv6 address of the network card. Here, take the enp0s3 network card as an example.

/ / add the IPv6 address of the network card sudo ifconfig enp0s3 add fe80::7035:2dfa:8d80:ea7d/64 / / delete the IPv6 address of the network card sudo ifconfig enp0s3 del fe80::7035:2dfa:8d80:ea7d/64 about "how to use the Linux ifconfig command", thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report