Why do our home IPs start with 192.168?

2023.01.09

Why do our home IPs start with 192.168?

The IP address is like the sending and receiving addresses filled in the express delivery. It is a series of numbers used to identify your location in the complicated network world.

Yes, I am still Xiaobai, a technical blogger, an old emotional blogger. Tell a story. The veteran old licking dog Xiao Zhang is very excited today, and he wants to invite everyone to drink milk tea no matter what. Because he said that he felt that he was going to get married with the girl he liked, Xiao Luxiu. Ask why. His ears were red, and he said, "I think Xiao Lu is hinting at me. She said she likes to watch Avatar, and I happen to look like Avatar."

It made people frown. He continued: "She said she likes Sagittarius, and I just happen to be." I scratched my head: "Okay, stop talking, I understand. She lives in Shanghai, and you live in Shanghai too. You two are living together." He was stunned for a while , looked at me: "Don't talk like a dog, but what you said actually makes sense. Last time she asked me to help her repair the computer, I found out that her home's ip is 192.168.xx.xx. Coincidentally, my home Also, I suspect we live very close."

Very touched.

I didn't even dare to tell him that my home IP also starts with 192.168, and I guess yours does too, just you who are reading this article right now.

But here comes the question, why everyone's IP is 192.168.xx.xx?

Let's talk about this topic today.

what is the ip address

We know that the essence of network communication is to send and receive data packets. If sending and receiving data packets is the same as sending and receiving express delivery. The IP address is similar to the receiving address and sending address filled in the courier. With it, the router can start to act as a courier, and find out who should receive the data packet in this complicated network world. .

picture

Sending and receiving data is like sending and receiving express delivery

Since our current mainstream is still IPV4 addresses, we will take IPV4 as an example to explain by default.

This IP looks like this.

picture

IPv4 address

You can see it by executing ifconfig in the console. 192.168.31.170 next to inet is the IP address.

$ ifconfig  
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500  
    optinotallow=400<CHANNEL_IO>  
    ether 88:36:3d:33:a0:15  
    inet6 fe70::1009:aabf:ecc6:2d10%en0 prefixlen 64 secured scopeid 0x6  
    inet 192.168.31.170 netmask 0xffffff00 broadcast 192.168.31.255  
    nd6 optinotallow=201<PERFORMNUD,DAD>  
    media: autoselect  
    status: active  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

To put it bluntly, it is a special number, which is used to uniquely locate a certain machine on the Internet.

In order to represent this number, the IP address is divided into 4 bytes​, one byte is 8 bits​, a total of 32 bits​, which can be used to represent up to 2 ^32​, which is 4.2 billion addresses.

seemingly. . . A little less?

In 2021, there will be 7.8 billion in the world, and this year it will exceed 8 billion, which means that the per capita IP cannot be achieved.

picture

current global population

For this reason, many years ago, it was said that IPV4 addresses were not enough, and they were going to be exhausted, so there will be later IPV6 addresses.

IPv6 uses more bytes, so more addresses can be represented. It looks like this.

picture

IPv6 address

Is it very strange, I feel like I have never seen it before.

now it's right.

Have you noticed that after so many years of use, most people are still using IPV4 addresses, isn't it that they are going to be exhausted?

Why are you still using IPV4?

Don't worry, let's talk about the pre-knowledge point, the classification of IP addresses.

Classification of IP addresses

In order to better manage the use of these 4.2 billion IP addresses. We should have seen such a picture of IP classification in textbooks.

picture

Classification of IP addresses

It probably means that in the 32-bit address, the one starting with 0 is a class A address. Those starting with 10 are class B, and those starting with 110 are class C. After that, split the remaining bytes into two segments, one for the network number and the other for the host number.

The relationship between the network number and the host number is like the relationship between a parking lot number and a parking space number. There are many parking lots in a city, and there are many parking spaces in the parking lot. Each parking space can park a car, and a car here is actually a computer (host).

There are few large parking lots, but many cars can be parked. There are few network numbers corresponding to class A addresses, but many host numbers.

Small parking lots are everywhere, but generally there are few cars that can be parked. There are many network numbers corresponding to Class C addresses, but few host numbers.

The bosses divided the network in this way at the beginning, in fact, it was also for the convenience of management. For example, Class A addresses are used for large organizations, and the number of digits in the host address is as high as 1600w+​. Class C addresses are used for small companies, and the host number is only 200+.

This gap is a bit big, and it is unreasonable today. If I open an Internet cafe, there may be more than 200 machines, right? If you use Class C, you think there are too few host numbers, and if you use Class A, you think there are too many host numbers. Therefore, this classification mechanism is actually rarely used now.

Instead, the solution is to directly cancel the so-called ABC classification, and only keep the network number and host number, and the number of digits of the network number is not as limited as before. Use a slash to tell the user how many digits are the network number, and the rest are host numbers. For example, 172.20.61.69/20​, the number of digits of the network number is 20 digits, and the number of digits of the host number is 32-20=12 digits, which can hold 4096 machines, which is very flexible and sufficient.

picture

This is the so-called CIDR (Classless Inter-Domain Routing, Classless Inter-Domain Routing).

Not enough IP addresses?

But no matter how you classify, under the limit of 32 bits, even if you spend more time playing, as long as you add up class A + class B + class C + class X, the number of IPs will still be at most 4.2 billion. Still not enough.

Since addition doesn't work, we use multiplication.

What do you mean?

The number of 4.2 billion is too big for everyone. For the sake of easy understanding, we changed it to 6 IPs.

Assuming that 6 is split into 4+2​, and then 4 is multiplied by 2, the result of 8 must be greater than 6.

At the beginning, the network world we understood had only one layer, and each person had an IP, so only 6 people could access the Internet.

picture

Adding up can only allow 6 people to go online

Now we divide the network into two layers. like below.

picture

Multiplication allows 8 people to go online

Every 2 people form a "small network" and share an IP externally, but everyone's IP inside is different, and the 4 small networks together form a "big network". For example, Xiao Ming's computer is the No. 6 machine under the No. 1 network, and Xiao Hong's computer is the No. 6 machine under the No. 2 network. This can also achieve the effect of uniquely identifying a certain machine.

As above, each small network composed of 2 people is called a local area network, that is, the so-called intranet, and the IPs used (5, 6 above) are also called private IPs or intranet IPs, and the "big network" mentioned above "Network" is a wide area network, and the IP used is called a public IP or public network IP.

In this way, originally only 6 people could get online, but now 8 people can get online at the same time. This is still the case where there are only 6 IPs. If the number is changed back to 4.2 billion, it will be able to support machines much larger than 4.2 billion to go online.

picture

The concept of public and private IP

According to this idea, returning to the above ABC class IP addresses, the bosses also divided them into private and public parts.

The range of private addresses is defined in the rfc1918 document. They don't appear in the WAN, only in the LAN.

* A类地址:10.0.0.0--10.255.255.255  
* B类地址:172.16.0.0--172.31.255.255  
* C类地址:192.168.0.0--192.168.255.255  
  • 1.
  • 2.
  • 3.

At this time, look at the private address range in class C again, isn't it familiar?

192.168.xx.xx is one of the IP addresses in this network segment. There are about 60,000+ host numbers in this range, what family conditions can be used up?

As a result, it becomes a street or a community, or several buildings in the community share a public network IP, and internal network IPs such as 192.168.xx.xx​ are used internally. So as long as you are at home, there is a high probability that your IP address is 192.168.xx.xx of class C.

picture

Several buildings share one public network IP

But in fact, as long as you want, the private addresses of class A and class B can also be used in the local area network.

When you go to the company and execute the ifconfig command, you may find that your LAN IP does not start with 192.168, but starts with 172 or 10.

This is because in the company's intranet, the number of IPs required will be larger. IPs starting with 172 and 10 can represent more hosts. For example, IPs starting with 10 can represent 1600w+ hosts.

Not to mention anything else, only a class A address, only a network number starting with 10 is used as an internal network IP to represent 1600w+ host numbers, and the remaining 100+ class A network numbers are used as public network addresses. Multiply according to the algorithm mentioned above, the number of public network IPs * the number of internal network IPs = (100+ * 1600w) * 1600w, don't worry about my calculations, anyway, it can be used by many devices, let alone It is not counted that there are still B and C categories.

Moreover, only one layer of LAN is considered above. In fact, the LAN can be divided into multiple layers, and LANs can be nested in the LAN. Just like the following, the number of IPs that can be used is more.

picture

LAN within LAN

Therefore, although there are not many IP addresses, they are actually enough, which is why we have been delaying in switching to IPv6. It is enough and can run, why change it?

Talking here, I actually answered the question in the title of the article. Why everyone’s IP starts with 192.168 is because IPv4 addresses are limited. In order to effectively use these limited addresses, we can divide the network into LAN and WAN, and divide IP into For private IP and public network IP, more than N machines in a LAN can share one WAN IP, thus achieving the effect of "multiplication", greatly increasing the "number of available IPs", and several buildings in the community can share one Public network IP, and because there are not many devices, generally choose C-class private addresses, that is, addresses starting with 192.168.

But here comes the question, how do I know what my public IP address is?

Query your own public IP address

On the computer at home, you can get your own intranet IP address through ifconfig​, for example, mine is 192.168.31.170.

$ ifconfig  
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500  
    optinotallow=400<CHANNEL_IO>  
    ether 88:36:3d:33:a0:15  
    inet6 fe70::1009:aabf:ecc6:2d10%en0 prefixlen 64 secured scopeid 0x6  
    inet 192.168.31.170 netmask 0xffffff00 broadcast 192.168.31.255  
    nd6 optinotallow=201<PERFORMNUD,DAD>  
    media: autoselect  
    status: active  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.

But what if you want to know your public IP address?

There is an easy way. You can directly search for "my IP address" on Baidu, and you can see your public IP address.

picture

Don't ping this address, this picture has been p by me.

If you are using a certain cloud machine. You'll also find that your machine has both a private IP address and a public IP address.

picture

Aliyun can assign public and private IPs at the same time

is also a graph of p.

When you go to ping the above private address 172.21.56.59, you will find that it cannot be pinged at all.

$ ping 172.21.56.59  
PING 172.21.56.59 (172.21.56.59): 56 data bytes  
Request timeout for icmp_seq 0  
Request timeout for icmp_seq 1  
Request timeout for icmp_seq 2  
^C  
--- 172.21.56.59 ping statistics ---  
4 packets transmitted, 0 packets received, 100.0% packet loss  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

However, the public network address 46.101.121.11 can be pinged. That is to say, in your home LAN, you can only access this cloud server through the public IP address.

$ ping 46.101.121.11  
PING 46.101.121.11 (46.101.121.11): 56 data bytes  
64 bytes from 46.101.121.11: icmp_seq=0 ttl=48 time=273.481 ms  
64 bytes from 46.101.121.11: icmp_seq=1 ttl=48 time=268.018 ms  
64 bytes from 46.101.121.11: icmp_seq=2 ttl=48 time=266.606 ms  
^C  
--- 46.101.121.11 ping statistics ---  
3 packets transmitted, 3 packets received, 0.0% packet loss  
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.

At this time, people who have used their servers may have a question.

As long as you apply for a cloud service, a certain cloud can give you a public network IP address, how to do it?

This. . . so rich?

In fact, a certain Liyun and the IP management organization rent a batch of IP addresses. When you need it, you can rent it to you for a fee, and you can recycle it and distribute it to others when you don’t use it.

And under the public network IP address, you can actually hang multiple cloud servers, and use the method mentioned above to let multiple cloud servers share one IP.

Therefore, there is little need to worry about IP exhaustion.

Summarize

• The IP address is like the sending and receiving addresses filled in the courier, it is a string of numbers used to identify your location in the complicated network world.

• IPv4 has 32 bits and can represent up to 4.2 billion IP addresses. In order to better manage them, there have been ABC classification methods in textbooks, and in the ABC class, they are also divided into private addresses and public addresses. However, it is currently popular to use the CIDR method for classification.

• In order to represent more hosts, we can divide the network into WAN and LAN, where WAN uses public addresses and LAN uses private addresses. Multiplying the public address by the private address can represent far more than 4.2 billion machines.

• The home network is relatively small, often several buildings in the community form a local area network, and these buildings share a public IP address. The private address of class C is selected in the LAN, that is, the ip starting with 192.168.xx, so you will find that the IPs in our home basically start with 192.168.

• Search "My IP Address" on baidu, you can see your public IP address.

It's almost there, let me leave you a question

As mentioned above, the network is divided into wide area network and local area network, and IP is divided into public and private. All machines in a local area network use a public IP externally and private IP internally.

So here comes the problem. Private IPs are not used in the public network. If a private IP in a LAN wants to access a public IP outside the LAN, an IP conversion must be done. Where is the conversion done?

picture

Where is the conversion between private IP and public IP

At last

When I was writing an article, I encountered a little easter egg.

When I open the console of the browser with F12 in the webpage searched by baidu.

I saw the following passage. I found out that it was a recruitment promotion article. Thinking about it, the people who can open the console to read it are basically people who are related to programmers. This wave is accurate drainage.

picture

The recruitment slogan is really well written.

After reading my emo, when I graduated, I also thought that one day I could change the world by writing code.

After many years, I found that being able to change myself is already very remarkable.