


How to check the IP address of this machine? I think this problem will certainly not trouble programmers. Everyone must know that if it is a Windows system, then in the cmd window, enter ipconfig. If you want to see more detailed information, enter ipconfig /all.
If it is a Linux system, if you have installed the net-tools tool, you can use the ifconfig command to view it. But if you have not installed this toolkit, you can also view it through ip addr.
Let’s look at the information displayed by typing ip addr on a host.
# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 link/ether 00:16:3e:14:a2:5b brd ff:ff:ff:ff:ff:ff inet 172.16.1.196/20 brd 172.16.15.255 scope global dynamic eth0 valid_lft 291113559sec preferred_lft 291113559sec
This command can display all the network card information on the host. It can be seen that there are currently two network cards on the host, lo and eth0.
IP address
172.16.1.196 is the eth0 network card. IP address, which consists of four parts, each part occupies 8 bits (1 byte), a total of 32 bits. The IP address is the communication address of a network card in the online world, which is equivalent to our house number in the real world. Since it is a house number, everyone is different. If it is the same, an IP address conflict will occur and the Internet will not be able to be accessed.
Classification of IP addresses
Theoretically, there are at most 2 to the 32nd power of IP addresses, which is 4294967296. In fact, there are far more Not nearly so much. IP addresses are divided into 5 categories, and the first three categories A/B/C are actually available.
The following table shows in detail the number of hosts that can be included in the three types of addresses A, B, and C.
Category |
##IP Address Range |
Private IP address range |
Subnet mask | Number of networks |
Maximum number of hosts in a network segment |
A |
##1.0.0.1-127.255.255.254
| ##10.0. 0.0-10.255.255.255
##255.0.0.0 |
##126 (2^ 7- 2) |
##16777214 (2^ 24-2) |
B |
##128.0.0.1-191.255.255.254 |
##172.16.0.0-172.31 .255.255
| ##255.255.0.0
##16383 (2^ 14-1) |
65534 (2^16-2) |
||
##192.168.0.0-192.168.255.255 |
255.255.255.0 |
2097152 (2^ 21-1) |
254 (2^8-2) |
无类型域间选路(CIDR)
看上面表格会发现一个问题,就是C类地址能包含的主机数太少了,只有254个,不够一个大一点的企业使用。而B类又太多了,很少有这么大的单位。所以,就有了一个折中的办法CIDR。
CIDR通过子网掩码将ip地址一分为二,前面的部分为网络号,后面的部分为主机号。下面通过例子看子网掩码是如何划分网络号和主机号的:
172.16.1.196/20
这个地址表示形式就是CIDR。斜杠后面的20即子网掩码,它是由前面连续的20个1组成的,即11111111.11111111.11110000.00000000。表示前20位为网络号,后12位为主机号。所以该网络可用主机数为2的12次方再减去2(一个网络地址、一个广播地址)
将子网掩码和 IP 地址按位AND计算,就可得到网络号。我们来计算下网络号以及第一个可用地址最最后一个可用地址
*.*.00000001.* *.*.11110000.* -------------- 172.16.0.0 <===网络号
获得了网络号,那么第一个可用地址为:172.16.0.1,最后一个可用地址为:172.16.15.254。
伴随着CIDR还有广播地址,172.16.15.255,它是主机号的最后一个。如果发送这个地址,那么172.16.0.0这个网络里的主机都能收到。
公有IP和私有IP
在工作中,基本上不用划分A类、B类还是C类,所以时间长了,大家都忘记了这个分类,只记得CIDR。但是有一点还是要注意的,就是公有 IP 地址和私有 IP 地址。关于私有IP范围,在之前的表格已经给出。当你看到10.x.x.x或172.x.x.x或192.x.x.x时,就要明白,这是个私有ip地址。
那么私有ip和公有ip都是用来干嘛的呢?
公有IP地址是广域网的范畴,通过它能直接访问互联网。如果你想搭建一个网站,让全世界的人都能访问,那么就需要使用公有IP。
私有IP地址:我们企业或家庭内部组建局域网用的IP,一般都会用私有IP。私有地址是局域网范畴内的,私有IP禁止出现在Internet中。
MAC地址
link/ether 00:16:3e:14:a2:5b
这一行显示的是MAC地址,它有12位16进制数组成,用6个字节表示。它是网卡的物理地址,号称全球唯一,不会有两个相同的MAC地址。既然是全球唯一,那么用它来替代ip不是非常好的。
这样是不行的,因为网络中的数据包传递,除了要有确定的地址外,还要有定位功能。MAC地址是不具备远程定位功能的,而IP具有远程定位功能。
MAC地址类似身份证号,每个人身份证号都是唯一的,但是你不能通过这个号去找到这个人的住址。而IP则类似身份证上面的家庭住址信息。
MAC地址虽不具备远程定位功能,但还是有一定的定位功能的(在局域网内)。比如在同一间办公室,你吼一声身份证号xxxxxx是谁,办公室人听到了,有人站起来说是我。但如果这个人在外地(不在同一个网段),你吼破嗓子也没人回应。
总结
IP地址具有定位功能;MAC地址唯一,但不能远程定位
CRID用来划分子网
IP分为公有IP、私有IP。
更多相关技术文章,请访问linux系统教程栏目!
The above is the detailed content of Detailed explanation of the information displayed by ip addr - IP, MAC. For more information, please follow other related articles on the PHP Chinese website!

The five core components of the Linux operating system are: 1. Kernel, 2. System libraries, 3. System tools, 4. System services, 5. File system. These components work together to ensure the stable and efficient operation of the system, and together form a powerful and flexible operating system.

The five core elements of Linux are: 1. Kernel, 2. Command line interface, 3. File system, 4. Package management, 5. Community and open source. Together, these elements define the nature and functionality of Linux.

Linux user management and security can be achieved through the following steps: 1. Create users and groups, using commands such as sudouseradd-m-gdevelopers-s/bin/bashjohn. 2. Bulkly create users and set password policies, using the for loop and chpasswd commands. 3. Check and fix common errors, home directory and shell settings. 4. Implement best practices such as strong cryptographic policies, regular audits and the principle of minimum authority. 5. Optimize performance, use sudo and adjust PAM module configuration. Through these methods, users can be effectively managed and system security can be improved.

The core operations of Linux file system and process management include file system management and process control. 1) File system operations include creating, deleting, copying and moving files or directories, using commands such as mkdir, rmdir, cp and mv. 2) Process management involves starting, monitoring and killing processes, using commands such as ./my_script.sh&, top and kill.

Shell scripts are powerful tools for automated execution of commands in Linux systems. 1) The shell script executes commands line by line through the interpreter to process variable substitution and conditional judgment. 2) The basic usage includes backup operations, such as using the tar command to back up the directory. 3) Advanced usage involves the use of functions and case statements to manage services. 4) Debugging skills include using set-x to enable debugging mode and set-e to exit when the command fails. 5) Performance optimization is recommended to avoid subshells, use arrays and optimization loops.

Linux is a Unix-based multi-user, multi-tasking operating system that emphasizes simplicity, modularity and openness. Its core functions include: file system: organized in a tree structure, supports multiple file systems such as ext4, XFS, Btrfs, and use df-T to view file system types. Process management: View the process through the ps command, manage the process using PID, involving priority settings and signal processing. Network configuration: Flexible setting of IP addresses and managing network services, and use sudoipaddradd to configure IP. These features are applied in real-life operations through basic commands and advanced script automation, improving efficiency and reducing errors.

The methods to enter Linux maintenance mode include: 1. Edit the GRUB configuration file, add "single" or "1" parameters and update the GRUB configuration; 2. Edit the startup parameters in the GRUB menu, add "single" or "1". Exit maintenance mode only requires restarting the system. With these steps, you can quickly enter maintenance mode when needed and exit safely, ensuring system stability and security.

The core components of Linux include kernel, shell, file system, process management and memory management. 1) Kernel management system resources, 2) shell provides user interaction interface, 3) file system supports multiple formats, 4) Process management is implemented through system calls such as fork, and 5) memory management uses virtual memory technology.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Notepad++7.3.1
Easy-to-use and free code editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
