[Comprehensive explanation of Linux commands] 135. Detailed explanation and usage examples of Linux ifconfig command

ifconfig

The ifconfig command is used to configure and display the network parameters of the network interface 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 permanently store the above configuration information in the computer, you need to modify the configuration file of the network card.

grammar

ifconfig(参数)

Parameter Description:

  • add<address>: Set the IP address of the network device IPv6;
  • 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.

Example

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.
  • First line: Connection type: Ethernet HWaddr (hardware MAC address).
  • The second line: the IP address, subnet, and mask of the network card.
  • The third line: UP (represents that the network card is on) RUNNING (represents that the network cable of the network card is connected) MULTICAST (supports multicast) MTU: 1500 (maximum transmission unit): 1500 bytes.
  • The fourth and fifth rows: statistics on receiving and sending data packets.
  • The seventh line: statistical information on the number of data bytes received and sent.

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 delete IPv6 addresses for network cards:

ifconfig eth0 add 33ffe:3240:800:1005::2/64    # 为网卡 eth0 配置 IPv6 地址
ifconfig eth0 del 33ffe:3240:800:1005::2/64    # 为网卡 eth0 删除 IPv6 地址

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    # 开启网卡 eth0 的 ARP 协议
ifconfig eth0 -arp   # 关闭网卡 eth0 的 ARP 协议

Set the maximum transmission unit:

ifconfig eth0 mtu 1500    # 设置能通过的最大数据包大小为 1500 bytes

Other examples:

ifconfig   # 处于激活状态的网络接口
ifconfig -a  # 所有配置的网络接口,不论其是否激活
ifconfig eth0  # 显示 eth0 的网卡信息

Learn from scratchpython

[Learn python from scratch] 92. Use Python’s requests library to send HTTP requests and process responses
[Learn python from scratch] 91. Use decorators and dictionaries to manage request paths in a simple web application
[Learn python from scratch] 93. Use dictionary management Request path
[Learn python from scratch] 89. Use WSGI to build a simple and efficient Web server
[Learn python from scratch] 88. Detailed explanation of WSGI interface: realize simple and efficient web development
[Learn python from scratch] 87. Manually build an HTTP server in Python Implementation and multi-threaded concurrent processing
[Learn python from scratch] 86. In-depth understanding of the HTTP protocol and its role in browser and server communication
[Learn python from scratch] 85. Application of parallel computing technology in Python process pool
[Learn python from scratch] ] 84. In-depth understanding of threads and processes
[Learn python from scratch] 83. Python multi-process programming and the use of process pools
[Learn python from scratch] 82. Chat program implementation based on multi-threading
[Learn python from scratch] 81. Python more Application of thread communication and queue
[Learn python from scratch] 80. Thread access to global variables and thread safety issues
[Learn python from scratch] 79. Thread access to global variables and thread safety issues
[Learn python from scratch] 78. File download case
[ Learn python from scratch] 77. TCP server programming and precautions
[learn python from scratch] 76. Server and client: key components of network communication
[learn python from scratch] 75. TCP protocol: reliable connection-oriented transmission layer communication protocol
[Learn python from scratch] 74. UDP network program: Detailed explanation of port issues and binding information
[Learn python from scratch] 73. UDP network program - sending data
[Learn python from scratch] 72. In-depth understanding of Socket communication and creation of sockets Method
[Learn python from scratch] 71. Network ports and their functions
[Learn python from scratch] 70. Network communication methods and their applications: from direct communication to routers to connect multiple networks
[Learn python from scratch] 69. Network communication and IP address classification analysis
[Learn python from scratch] 68. Greedy and non-greedy modes in Python regular expressions
[Learn python from scratch] 67. The re module in Python: regular replacement and advanced matching technology
[Learn python from scratch] 66 .In-depth understanding of regular expressions: a powerful tool for pattern matching and text processing
[Learn python from scratch] 65. Detailed explanation of Python regular expression modifiers and their applications
[Learn python from scratch] 64. The re.compile method in Python regular expressions Detailed explanation of usage
[Learn python from scratch] 63. Introduction to the re.Match class and its attributes and methods in regular expressions
[Learn python from scratch] 62. Python regular expressions: a powerful string matching tool
[Learn python from scratch] 61. Detailed explanation and application examples of property attributes in Python
[Learn python from scratch] 60. Exploration generator: a flexible tool for iteration
[Learn python from scratch] 59. Iterator: An efficient tool for optimizing data traversal
[Learn python from scratch] 58. Custom exceptions in Python and methods of raising exceptions
[Learn python from scratch] 57. Use the with keyword in Python to correctly close resources
[Learn python from scratch] 56. The importance and application of exception handling in programming
[Learn python from scratch] 55. Serialization and sum in Python Deserialization, application of JSON and pickle modules
[Learn python from scratch] 54. Writing data in memory
[Learn python from scratch] 53. CSV files and Python’s CSV module
[Learn python from scratch] 52. Reading and writing files - Python file operation guide
[Learn python from scratch] 51. Opening and closing files and their applications in Python
[Learn python from scratch] 49. Object-related built-in functions in Python and their usage
[Learn python from scratch] 48 .Detailed explanation of inheritance and multiple inheritance in Python
[Learn python from scratch] 47. The concept and basic use of inheritance in object-oriented programming
[Learn python from scratch] 46. Analysis of __new__ and __init__ methods and singletons in Python Design Patterns
[Learn python from scratch] 45. Class methods and static methods in Python
[Learn python from scratch] 44. Private properties and methods in object-oriented programming
[Learn python from scratch] 43. Examples in Python object-oriented programming Properties and class attributes
[Learn python from scratch] 42. Built-in properties and methods in Python
[Learn python from scratch] 41. python magic method (2)
[Learn python from scratch] 40. python magic method (1)
[Learn python from scratch] 39. Basic object-oriented syntax and application examples
[Learn python from scratch] 38. How to use and import Python packages
[Learn python from scratch] 37. The use and precautions of Python custom modules
[Learn python from scratch] Learn python] 36. Methods and techniques of using pip for third-party package management in Python
[Learn python from scratch] 35. Python common system modules and their usage
[Learn python from scratch] 34. Detailed explanation of the import and use of Python modules
[ Learn python from scratch] 33. The role of decorators (2)
[Learn python from scratch] 32. The role of decorators (1)
[Learn python from scratch] 31. In-depth understanding of higher-order functions and closures in Python
[From Learn python from scratch】30. In-depth understanding of recursive functions and anonymous functions
【learn python from scratch】29. "Detailed explanation of function parameters" - understand the different uses of Python function parameters
【learn python from scratch】28. Local variables and global variables in Python Variables
[Learn python from scratch] 27. The use of Python functions and nested calls
[Learn python from scratch] 25. Functions: a tool to improve the efficiency of code writing
[Learn python from scratch] 24. String operations and traversal methods in Python
[Learn python from scratch] 23. How to use sets (set) and common operations in Python
[Learn python from scratch] 22. Add, delete, modify, and query dictionary variables in Python
[Learn python from scratch] 21. Python tuples and dictionaries
[Learn python from scratch] 20. Python list operation skills and examples
[Learn python from scratch] 19. Applications of looping through lists and list nesting
[Learn python from scratch] 18. Detailed explanation of the basic operations of Python lists (1)
[From Learning python from scratch】 17. The format method of Python strings (2)
【Learning python from scratch】 16. The format method of Python strings (1)
【Learning python from scratch】 15. In-depth understanding of strings and character set encoding
【From Learning python from scratch】14. Common operations on Python strings (2)
【Learning python from scratch】13. Common operations on Python strings (1)
【Learning python from scratch】12. Python string operations and applications
【Learning python from scratch】 11. Python loop statements and control flow
[Learn python from scratch] 10. Detailed explanation of Python conditional statements and if nesting
[Learn python from scratch] 09. Conditional judgment statements in Python
[Learn python from scratch] 08. Python understands bit operations operator, operator priority
[Learn python from scratch] 07. Detailed explanation of Python operators: assignment, comparison and logical operators
[Learn python from scratch] 06. Use arithmetic operators in Python for calculations and string concatenation
[Learn from scratch] python ] 05. Output and input in Python
[Learn python from scratch] 04. Basics of Python programming: variables, data types and identifiers
[Learn python from scratch] 03. Python interactive programming and detailed explanation of comments
[Learn python from scratch] 02. Introduction to development tools
[Learn python from scratch] 01. Install and configure python

Guess you like

Origin blog.csdn.net/qq_33681891/article/details/132896165