The difference between local ip and 127.0.0.1

Introduction

Every computer connected to the Internet will have an IP address. Under linux, you can use the command ifconfigto view the ip address of the machine. The ip address of my current computer 192.168.0.30is 127.0.0.1called the local loopback address (loopback). The loopback address is mainly used for network software testing and local machine inter-process communication. No matter what program, once the loopback address is used to send data, the protocol software returns immediately without any network transmission. 127.0.0.1 can be considered as a virtual network card on the computer ip address.

example

It seems that the difference between the two is not explained in this way. For example, if we have a server/client application, the client sends a request to the server, and the server returns the data to the client. The client client and the server server need two different ip addresses. Now we want to test this application locally, then we can use our local ip as the client's address, and 127.0.0.1 as the server's address, the client sends a request to 127.0.0.1, and then gets the return data from 127.0.0.1. Another example is if we have a database on our local computer and another computer wants to connect to the database on our computer, then the address used when specifying the database is the local ip.

Summarize

1. The 127.0.0.1 of the local ip are all ip addresses, but 127.0.0.1 is special. The data sent to 127.0.0.1 or the data returned from 127.0.0.1 will only be transmitted locally, not external network transmission;
2. 127.0.0.1 mainly has the following two functions

  • Test the local network
    When we can ping 127.0.0.1, it means that the local network card and the tcp/ip protocol suite are installed correctly.
  • Test the written network application
    Like the above example, we can say that the local ip and 127.0.0.1 are regarded as the ip addresses of the client and the server respectively, and then complete the test of the client/server application on one computer.
    3. When it comes to network communication between computers, the local ip is used.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324895922&siteId=291194637