首页 > 其他分享 >Why is 127.0.0.1 used for localhost?

Why is 127.0.0.1 used for localhost?

时间:2023-07-07 10:35:57浏览次数:72  
标签:127.0 network 0.1 Why used address rrr localhost

     

Why is 127.0.0.1 used for localhost?

Does anyone know why that number was chosen?

Although it’s not documented anywhere (at least as far as I know), but there are some logical explanations.
But before going over the explanation let’s first give a brief description of what is localhost addresses and what is used for.

What is the localhost address “127.0.0.0/8”?

In computer networking, localhost is a hostname that means this computer. It is used to access the network services that are running on the host via the loopback network interface. Using the loopback interface bypasses any local network interface hardware.

The local loopback mechanism may be used to run a network service on a host without requiring a physical network interface, or without making the service accessible from the networks the computer may be connected to. For example, a locally installed website may be accessed from a web browser by the URL http://localhost to display its home page.

IPv4 network standards reserve the entire 127.0.0.0/8 address block for loopback purposes. That means any packet sent to any of those addresses (127.0.0.1 through 127.255.255.255) is looped back. The address 127.0.0.1 is the standard address normally used for IPv4 loopback traffic; the rest are rarely used in practice. The IPv6 standard assigns only a single address for loopback: ::1.

 

Localhost - Wikipedia

So basically the localhost address used in testing software/applications. It’s a service provided internally by the operating system. You can ping the localhost address even if you have no functional network interface card “NIC”. You can easily test it. Go now and disable your NIC then try to ping 127.0.0.1 “127.x.x.x”.


  • 0 = This
  • The address zero is to be interpreted as meaning "this", as in 
  • "this network". 
  •  
  • For example, the address 0.0.0.37 could be interpreted as 
  • meaning host 37 on this network. 
  •  
  • The address of all ones are to be interpreted as meaning "all", 
  • as in "all hosts". 
  •  
  • For example, the address 128.9.255.255 could be interpreted 
  • as meaning all hosts on the network 128.9. 
  •  
  • The class A network number 127 is assigned the "loopback" 
  • function, that is, a datagram sent by a higher level protocol 
  • to a network 127 address should loop back inside the host. No 
  • datagram "sent" to a network 127 address should ever appear on 
  • any network anywhere. 

RFC 990 - Assigned numbers


  • Pattern/Scheme “First and last IP”

We can easily see that the first and last number of any IP range is almost always special. For example the first Class A IP “0.x.x.x” is reserved, for any network, the first IP is reserved as it represents the whole network and the last IP is reserved for broadcast. So you can see there is some kind of scheme or pattern.
So they decided to use the last classful A network for the purpose of the localhost. Which is something seems so weird today, why would we waste an entire class A network while we just use one IP address. Back then they had no idea that there will be any need for all the possible IPv4 addresses, they just didn’t care about all the wasted IP addresses.

  • 127.rrr.rrr.rrr Reserved [JBP] 
  •  
  • Class B Networks 
  •  
  • Internet Address Name Network References 
  • ---------------- ---- ------- ---------- 
  • 128.000.rrr.rrr Reserved [JBP] 
  • 128.001.rrr.rrr-128.254.rrr.rrr Unassigned [JBP] 
  • 191.255.rrr.rrr Reserved [JBP] 
  •  
  • Class C Networks 
  •  
  • Internet Address Name Network References 
  • ---------------- ---- ------- ---------- 
  • 192.000.001.rrr Reserved [JBP] 
  • 192.000.001.rrr-223.255.254.rrr Unassigned [JBP] 
  • 223.255.255.rrr Reserved [JBP] 
  •  
  • Other Reserved Internet Addresses 
  •  
  • Internet Address Name Network References 
  • ---------------- ---- ------- ---------- 
  • 224.000.000.000-255.255.255.255 Reserved [JBP] 

RFC 790 - Assigned numbers - Dec 1980

As you can see, back in 1980 they just reserved entire classful networks for no good reason.


  • Low level implementation in mind.

The designers of the Internet really knew how the hardware worked, and they designed with low level implementation in mind.

The values 0, 127 and 255 are special in 8 bit assembly and machine language programming because there are "tricks" you can use to test for these values and branch to different code using smaller instructions that execute faster than for other integers. 127 is the highest signed 8 bit integer, so incrementing it by 1 will cause a signed overflow. Similarly, incrementing 255 will cause unsigned overflow. Merely loading the value 0 into a register will usually set a zero flag on the chip. Imagine the networking program looks like this in pseudocode:

 
  • if (value == 0) doLocal(); 
  • if (value == 127) doLoopback(); 
  • if (value == 255) doNetwork(); 
 

Although it depends on the chip, in those days most chips could encode these tests with 2 words, 3 words and 3 words respectively (total 8 words) and further those particular tests were all likely to execute in 1 clock cycle each. Using any other value would probably require 4 words each (total 12 words), a 50% increase in code size and likely a 50% increase in execution time as well.

 

Why is localhost IP 127.0.0.1?


Some people suggest that it’s related to the old computers processor limitation. It was chosen to ensure the simplest calculations by the processor.

Other people think that the reserved range was randomly chosen, but I don’t like this theory.
Although back when the internet was created they didn’t imagine how the internet will be in the next years, Which is completely understanding but these people were geniuses, hard workers, …etc to chose things randomly.


For people out there studying CompTIA Network+ or CCNA, check AlphaPrep.net for high-quality study materials and practice tests.

  • Upvote if you find this useful.
  • Comment if you have a question or something to share.
  • Follow if you are interested in reading more about computers and networks.

Have a nice day : )

 

标签:127.0,network,0.1,Why,used,address,rrr,localhost
From: https://www.cnblogs.com/ioriwellings/p/17534143.html

相关文章

  • Lord Of The Root: 1.0.1实战
    前言Description:我创建这台机器是为了帮助其他人学习一些基本的CTF黑客策略和一些工具。我瞄准了这台机器,使其在难度上与我在OSCP上破解的机器非常相似。这是一个引导到根计算机将不需要任何来宾交互。有两种设计的权限提升方法。靶机环境kali192.168.31.153LordOfther......
  • Silhouette 2023.0.1 CE 影视后期ROTO跟踪抠像合成软件 支持AE/PR/达芬奇/VEGAS/OFX插
    Silhouette是一款被广泛应用于影视剧中Roto、抠像、擦威亚的特效合成辅助软件,正所谓术业有专攻,它就是为了应对这些脏活累活而诞生的。之前还有一款软件CommotionPro,但是已经停止开发,目前已经被这款Silhouette所替代,目前它也属于BorisFX家族的一员。软件下载Silhouette2023.......
  • What does the term epoch mean? Why it is so important?
    在人工智能中,"epoch"(中文称为"训练轮次"或"周期")是指训练神经网络时将整个训练数据集通过神经网络进行一次正向传播和反向传播的过程。每个"epoch"包含一次前向传播和一次后向传播,用于更新神经网络的参数。在每个"epoch"中,神经网络对整个训练数据集进行一次学习和优化,以逐渐提高......
  • 10.12 枚举应用案例
    demoenumSex{ //性别 MALE("男"),FEMALE("女"); //枚举对象 privateStringtitle; //成员属性 privateSex(Stringtitle){ //构造方法 this.title=title; } @Override publicStringtoString(){ //获取对象信息......
  • 10.11 定义枚举结构
    demo1在枚举类中定义成员属性与方法enumColor{ //枚举类 RED("红色"),GREEN("绿色"),BLUE("蓝色"); //枚举对象要写在首行 privateStringtitle;//成员属性 privateColor(Stringtitle){//构造方法初始化属性; this.title=title; } @Override publicStrin......
  • Windows兼容模式怎么设置?140.210.18.x
    服务器兼容是什么意思?服务器兼容性怎么改?兼容性(compatibility)是指硬件之间、软件之间或是软硬件组合系统之间的相互协调工作的程度。兼容的概念比较广,相对于硬件来说,几种不同的电脑部件,如CPU、主板、显示卡等,如果在工作时能够相互配合、稳定地工作,就说它们之间的兼容性比较好,反之就......
  • CentOS安装Redis-5.0.14
     注:以下所有操作均在CentOS7.9x86_64位系统下完成。 #准备工作#在安装Redis之前,请确保已经使用yum安装了以下基础组件:makegccgcc-c++kernel-devel #Redis的安装#开始下载Redis并进行编译安装:wgethttp://download.redis.io/releases/redis-5.0.14.tar.gztar......
  • thinkphp6:使用view视图/模板(thinkphp v6.0.12LTS)
    一,在使用之前,需要用composer安装需要的view模块:参见:https://blog.imgtouch.com/index.php/2023/06/29/thinkphp6-bao-cuo-driver-think-not-supported/二,php代码:<?phpdeclare(strict_types=1);namespaceapp\controller;useapp\BaseController;usethink\fa......
  • 扬州服务器跟宁波服务器哪个好一些?扬州服务器租用140.210.17.x
    相信从事互联网行业的大佬们对扬州服务器和宁波服务器都不陌生,在日常的使用中扬州和宁波的出场率都挺高的,要是拿这两个机房服务器对比,那真的可以用不相上下来形容,其实领域不同,所需的服务器配置也是不同的,要是不知如何选择服务器配置,可以安排测试,测试服务器的整体性能。接下来我给大......
  • Authentication to host '10.167.32.123' for user 'root' using method 'mysql_
    连接Mysql5.7以上的版本的数据库出现报错:C#连接远程连接mysql时,抛异常:Authenticationtohost'10.167.32.123'foruser'root'usingmethod'mysql_native_password'failedwithmessage:Readingfromthestreamhasfailed最终在Mysql官网的bug提交区发现已经有人也遇到......