Many computer users have encountered the situation of using localhost or 127.0.0.1 or directly entering the local IP. It seems that all three can access the local computer, so why do these three forms exist? What’s the difference between them? It seems simple, but there is a big difference.

In addition, you may also be confused about the relationship between public network and private network, network card and IP. The following are your answers.

🔥 native IP

Our computer motherboard has a variety of built-in network cards, generally there are mainly the following categories:

  • Virtual network card (Loopback)
    • Note: it is virtual, not physical, and is also known as a local loopback address (or interface), commonly referred to as127.0.0.1As aLoopback address.
  • Wired/Ethernet card (Ethernet)
    • This is the Ethernet (local area network) used, we talk about the network card refers to this, plug in is the network cable.
  • Wireless card (WLAN)
    • This is the network card used for wireless LAN, which is often built into laptops. It uses radio technology and does not need to plug in a network cable like an Ethernet card.

All of these network cards are bound to a local IP…

🔥localhost is a special domain name

Localhost is not an IP address, but a special domain name (without a suffix). By default, localhost resolves to a local IP address (127.0.0.1), managed primarily through the host’s hosts file, if you prefer. The localhost domain name can also be resolved to a public IP address, or it can be set to any IP address (that is, it can be changed through the hosts file), but it usually points to:

  • IPv4:127.0.0.1
  • IPv6:[: : 1)

Hosts file location: C:\Windows\System32\drivers\etc

🔥127.0.0.1 is a private IP address reserved by the local host

127.0.0.1 It is a private IP that stands for (or is really the name) the local loopback address, which is essentially the IP bound to the virtual network card (loopback).


So what is a loopback address? What does it do?

Loopback address: A loopback address is a special address (that is, a special destination address) used by the host to send communication to itself.

If two services on the same host use loopback addresses instead of assigned host addresses, they can bypass the lower layer of the TCP/IP stack.

Address 127 is not a network address at all, because the resulting IP packet does not reach the external network interface, but does not leave the host.

127.0.0.1 is one of the reserved addresses that are used frequently to check the TCP/IP stack on the host, and if we can ping it, it means that the network adapter and IP protocol are properly installed on the host.


In fact, IPv4 reserves the entire network segment 127.0.0.0 for loopback testing (except for two special reservations). 127.0.0.1 is just one of them. You can ping all the addresses in this network segment, or you can type any address into a browser to access the local Web service. Another commonly confused IP address is 0.0.0.0, which is the true native address and is used quite differently from 127.0.0.1.

For example, if a computer has two network adapters, one of which uses a public IP address to connect to the Internet and the other uses a private IP address to connect to the LAN, set the server address to 0.0.0.0 if the local computer has set up Web services and you want both the external and internal networks to access the network.

🔥localhost, local IP, 127.0.0.1

  • Different network requirements
    • localhost127.0.0.1No Internet access is requiredEven in a network-free environment, access to both can find this machine.
    • The cable IP address and wireless IP address of the local IP address can be assigned and accessed only after the network is connected to the network.
  • localhostIs native access;127.0.0.1Is native access; Local IP is local or external access.
  • localhostIs a domain name, the default is to127.0.0.1; The local IP address is the IP address that the local machine can access externally, and this web address isIP address bound to a physical NIC.
  • In a LAN, other computers on the same network segment (that is, on the same network segment within the same LAN) can use the IP address above to access your computer (private addresses are described below).

🔥 NIC address & IP address

⭐ NIC address

A NIC address is a MAC address, which is a media access control (MAC) address, or physical address or hardware address, used to define the location of a network device.

In the OSI model, the layer 3 network layer is responsible for IP addresses and the layer 2 data link layer is responsible for MAC addresses. So a host will have a MAC address, and each network location will have its own IP address.

The MAC address is fixed and unique, and is determined by the nic. Figuratively speaking, MAC addresses are like the id numbers on our ID cards, which are globally unique.

⭐ IP address

An IP address is an Internet protocol address. An IP address is a unified address format provided by the IP protocol. It allocates a logical address to each network and each host on the Internet to shield physical address differences.

⭐ summary

  • Generally speaking, the physical address refers to the hardware address of the network card. It is generally solidified on the network card. The physical address of no two network cards in the world is the same.
  • An IP address is a soft address assigned to a network adapter and can be changed.

Note: We can use ipconfig /all to view IP addresses and physical addresses.

🔥 Public IP address and private IP address

You can use 127.0.0.1 to access the local computer, use a private IP address to access other devices in the LAN, and use a public IP address to access other devices on the Internet.

🌊 Public IP address (public IP address)

To build an enterprise network, we need to apply to a “telecom operator ISP” for a broadband connection to the Internet (often called access network), and the ISP will also assign us one or more IP addresses that can be used to connect to the Internet inside the enterprise. The IP that these ISPs give us is the public IP.

The Internet NIC is responsible for the Public address (also called the Public address). These IP addresses are assigned to organizations that register and apply to the Internet NIC. With direct access to the Internet, it is within the wan category.

🌊 Private IP address (private IP address)

The IP that we use to set up the LAN inside the enterprise or home is generally private IP.

A Private address (also known as a Private network address) is an unregistered address for internal use in an organization. It belongs to a local area network (LAN). Private IP addresses are forbidden to appear on the Internet.

To access the Internet, use the NAT technology to convert a private IP address to a public IP address on the enterprise border.

🍺 Access public networks and private networks

If a private NETWORK IP address needs to access public network websites, perform SNAT on the interfaces between the private network and the public network.

General we call operators set up network for the public, is mainly responsible for connect the company or home network, the IP is public IP, also will only appear inside of public IP routing, therefore the private network IP into the public, there is no routing, discarded, so the above mentioned private network access to the public, need SNAT, Change a private IP address to a public IP address.

Smart you must think, public network to access private network how to do? This actually involves DNAT, VPN and other technologies.

There are two private networks to cross public network communication how to do? This can be solved by VPN.


Supplement: Intranet can be simply understood as private network, but in fact, the starting point of this concept is that for enterprises, private network is called inside the enterprise, and external network is called outside the enterprise.

Conceptually, a network outside an enterprise can include the network of the carrier (public network), the network of other enterprises or families (private network).

So, the external network and the public network can not be equal sign. But in fact, there is no so deliberately to distinguish, public network = external network, private network = internal network, can be simple so understand, there is no need to go to the literal word (but at least to understand the difference between the external network and the public network I said above).

⭐ Range of all IP addresses

IP addresses are divided into five categories as follows:

  • A kind of IP:1.0.0.1127.255.255.254
  • A class B IP:128.0.0.1191.255.255.254
  • Class C IP:192.0.0.1223.255.255.254
  • Class D IP:"239.255.255.255
  • E class IP:240.0.0.0255.255.255.255

Among them, there are A, B and C types that can be used on the Internet or by users. Class D addresses are called broadcast addresses for special protocols to send information to selected nodes, while Class E addresses are reserved for future use.

🌊 Special website:

  1. Addresses where each byte is 0 (“0.0.0.0“) corresponding to the current host;
  2. An IP address in which each byte is 1 (“255.255.255.255“Is the broadcast address of the current subnet;
  3. All class E IP addresses starting with 11110 are reserved for future and experimental use.
  4. The IP address cannot start with decimal 127, which is a number127.0.0.1127.255.255.255For loop testing, e.g. :127.0.0.1Can represent the local IP address.http://127.0.0.1″You can test the Web server configured on the machine.
  5. The first 6-bit group of the network ID cannot be all 0s. All 0s indicate the local network.

⭐ Range of public IP addresses

Among the three main types of IP addresses, three areas are reserved as private addresses, that is, common IP addresses. The address range is as follows:

  • Class A public IP:
    • 1.0.0.0 ~ 9.255.255.255
    • 11.0.0.0 ~ 126.255.255.255
  • Class B public IP:
    • 128.0.0.0 ~ 172.15.255.255
    • 172.32.0.0 ~ 191.255.255.255
  • Class C public IP:
    • 192.0.0.0 ~ 192.168.255.255
    • 192.169.0.0 ~ 223.255.255.255

⭐ Range of private IP addresses

  • Class A private IP addresses: 10.0.0.0 to 10.255.255.255, that is, 10.0.0.0/8
  • Class B private IP addresses: 172.16.0.0 to 172.31.255.255 (172.16.0.0/12)
  • Class C private IP address: 192.168.0.0 to 192.168.255.255 that is, 192.168.0.0/16

These addresses are not assigned by the Internet, and they are not routed on the Internet. Although they cannot be directly connected to the Internet, they can still communicate with the Internet through technical means (NAT technology). We can select the appropriate address class as needed and use these addresses as public IP addresses on the internal LAN. On the Internet, devices that do not need to communicate with the Internet, such as printers and manageable hubs, can also use these addresses to save IP address resources.

🔥 Network segment & LAN

Network segment refers to the part of a computer network that can communicate directly with the same physical layer devices (such as hubs and switches). That is, each computer can communicate directly with other computers in the same network segment.

A LOCAL area network (LAN) is a network system consisting of switches. All devices in a LAN are on the same network segment and can communicate with each other directly. However, a LAN can also be divided into multiple network segments, such as vlans.

About the introduction of VLAN, we can see this blog post (push) : info.support.huawei.com/info-finder…

Only devices on the same network segment on the same LAN can communicate with each other directly. So my understanding is that when there is only one network segment in a LAN, the LAN can be equivalent to a network segment.

⭐ How to distinguish whether the network segment is the same

After understanding the network segment, we will explain how to determine whether two network segments are the same network segment.

Determine the IP address segment based on the mask. Only the IP address is required&Subnet mask!

Case 1

For example, the following two IP addresses

  • IP address 1:192.168.1.1Subnet mask:255.255.255.0
  • IP address 2:192.168.1.2 insteadSubnet mask:255.255.255.0

We can directly determine that they belong to the same IP address (192.168.1.0) network segment.

Case 2

What about something like this?

  • IP address 1:192.168.1.1Subnet mask:255.255.255.0
  • IP address 2:192.168.1.2 insteadSubnet mask:255.255.0.0

Although the two IP addresses are similar without the mask, they are not in the same network segment.

This can be determined by the subnet mask:

IP 192.168.1.1 and subnet mask 255.255.255.0 Belong to network segment 192.168.1.0.

IP 192.168.1.2 and mask 255.255.0.0 belong to the 192.168.0.0 network segment.

Example 3

  • IP address 1:192.168.1.1Subnet mask:255.255.252.0
  • IP address 2:192.168.2.1Subnet mask:255.255.252.0

Obviously, our IP address is the same as the IP address in example 1 above, but the subnet mask is different. If you do not look at the subnet mask, you may first misjudge that they are not in the same network segment.

Both IP addresses belong to the 192.168.0.0 network segment. Therefore, they belong to the same network segment.

We hope this article will help you 🧠 feel free to leave your thoughts in the comments 🌊, we will discuss and share 🔥