search
HomeOperation and MaintenanceLinux Operation and MaintenanceDetailed explanation of the information displayed by ip addr - IP, MAC

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.

Detailed explanation of the information displayed by ip addr - IP, MAC

The following table shows in detail the number of hosts that can be included in the three types of addresses A, B, and C.

##10.0. 0.0-10.255.255.255##255.255.0.0##C192.0.0.1-223.255.255.254

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

##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

##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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Linux's Essential Components: Explained for BeginnersLinux's Essential Components: Explained for BeginnersApr 17, 2025 am 12:08 AM

The core components of Linux include the kernel, file system, shell and common tools. 1. The kernel manages hardware resources and provides basic services. 2. The file system organizes and stores data. 3. Shell is the interface for users to interact with the system. 4. Common tools help complete daily tasks.

Linux: A Look at Its Fundamental StructureLinux: A Look at Its Fundamental StructureApr 16, 2025 am 12:01 AM

The basic structure of Linux includes the kernel, file system, and shell. 1) Kernel management hardware resources and use uname-r to view the version. 2) The EXT4 file system supports large files and logs and is created using mkfs.ext4. 3) Shell provides command line interaction such as Bash, and lists files using ls-l.

Linux Operations: System Administration and MaintenanceLinux Operations: System Administration and MaintenanceApr 15, 2025 am 12:10 AM

The key steps in Linux system management and maintenance include: 1) Master the basic knowledge, such as file system structure and user management; 2) Carry out system monitoring and resource management, use top, htop and other tools; 3) Use system logs to troubleshoot, use journalctl and other tools; 4) Write automated scripts and task scheduling, use cron tools; 5) implement security management and protection, configure firewalls through iptables; 6) Carry out performance optimization and best practices, adjust kernel parameters and develop good habits.

Understanding Linux's Maintenance Mode: The EssentialsUnderstanding Linux's Maintenance Mode: The EssentialsApr 14, 2025 am 12:04 AM

Linux maintenance mode is entered by adding init=/bin/bash or single parameters at startup. 1. Enter maintenance mode: Edit the GRUB menu and add startup parameters. 2. Remount the file system to read and write mode: mount-oremount,rw/. 3. Repair the file system: Use the fsck command, such as fsck/dev/sda1. 4. Back up the data and operate with caution to avoid data loss.

How Debian improves Hadoop data processing speedHow Debian improves Hadoop data processing speedApr 13, 2025 am 11:54 AM

This article discusses how to improve Hadoop data processing efficiency on Debian systems. Optimization strategies cover hardware upgrades, operating system parameter adjustments, Hadoop configuration modifications, and the use of efficient algorithms and tools. 1. Hardware resource strengthening ensures that all nodes have consistent hardware configurations, especially paying attention to CPU, memory and network equipment performance. Choosing high-performance hardware components is essential to improve overall processing speed. 2. Operating system tunes file descriptors and network connections: Modify the /etc/security/limits.conf file to increase the upper limit of file descriptors and network connections allowed to be opened at the same time by the system. JVM parameter adjustment: Adjust in hadoop-env.sh file

How to learn Debian syslogHow to learn Debian syslogApr 13, 2025 am 11:51 AM

This guide will guide you to learn how to use Syslog in Debian systems. Syslog is a key service in Linux systems for logging system and application log messages. It helps administrators monitor and analyze system activity to quickly identify and resolve problems. 1. Basic knowledge of Syslog The core functions of Syslog include: centrally collecting and managing log messages; supporting multiple log output formats and target locations (such as files or networks); providing real-time log viewing and filtering functions. 2. Install and configure Syslog (using Rsyslog) The Debian system uses Rsyslog by default. You can install it with the following command: sudoaptupdatesud

How to choose Hadoop version in DebianHow to choose Hadoop version in DebianApr 13, 2025 am 11:48 AM

When choosing a Hadoop version suitable for Debian system, the following key factors need to be considered: 1. Stability and long-term support: For users who pursue stability and security, it is recommended to choose a Debian stable version, such as Debian11 (Bullseye). This version has been fully tested and has a support cycle of up to five years, which can ensure the stable operation of the system. 2. Package update speed: If you need to use the latest Hadoop features and features, you can consider Debian's unstable version (Sid). However, it should be noted that unstable versions may have compatibility issues and stability risks. 3. Community support and resources: Debian has huge community support, which can provide rich documentation and

TigerVNC share file method on DebianTigerVNC share file method on DebianApr 13, 2025 am 11:45 AM

This article describes how to use TigerVNC to share files on Debian systems. You need to install the TigerVNC server first and then configure it. 1. Install the TigerVNC server and open the terminal. Update the software package list: sudoaptupdate to install TigerVNC server: sudoaptinstalltigervnc-standalone-servertigervnc-common 2. Configure TigerVNC server to set VNC server password: vncpasswd Start VNC server: vncserver:1-localhostno

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)