本地主机(也称为“环回地址”)用于建立与您自己的计算机或机器的 IP 连接或呼叫。环回地址通常在网络环境中使用,并为计算机提供验证 IP 堆栈的能力。
任何有网络背景或对网络感兴趣的人都会发现学习和理解该领域的附属计算机术语很重要。本地(Localhost)主机就是这样一个对任何计算机技术人员都有益的术语。了解 localhost 的重要性和用途也是开始您的网络术语之旅的好地方。
什么是 LocalHost 以及它是如何使用的?(What Is LocalHost and How Is It Used?)
localhost 不仅是一个术语,还可以是一个域名,例如netflix.com或google.com。就像(Just)任何域一样,本地主机也将拥有自己的Internet 协议(Internet Protocol)(IP) 地址。
所需的地址取决于所使用的互联网协议。使用最常见的 IP 地址IPv4(IPv4)调用 localhost的范围为 127.0.0.0 到 127.255.255.255,但通常默认为 127.0.0.1。IPv6用户可以通过输入 :1 来建立环回。
互联网协议(Internet Protocol)
互联网协议(Internet Protocol)(IP)的实施是为了建立计算机与网络上其他设备通信的标准方法。它不仅管理地址,还管理本地网络和互联网上的数据发送和接收方式。
IPv4是Internet 协议(Internet Protocol)版本 4,是全球最常用的协议。IPv4严重依赖传输控制协议(Transmission Control Protocol)( TCP ) 来处理大量数据问题,例如传输、排序和完整性。该 IP 被设计为用于基于以太网的机器上的无连接协议。
IPv6已开始慢慢取代IPv4。随着数字繁荣,对 IP 地址的需求呈指数增长。越来越多的设备使用互联网,因此开发了IPv6以适应这种增长并解决IPv4中发现的一些基本缺陷。
IPv4允许使用大约 43 亿个唯一 IP 地址,而IPv6(IPv4)将(IPv6)允许多达 340 万亿个。
除了数字,IPv6还提供网络优势。它在其他启用IPv6(IPv6)的网络的设备之间开辟了更容易的检测,允许用户使用服务而无需最终用户操作。使用IPv6(IPv6)时,对网络地址转换(Network Address Translation)( NAT ) 的需求也大大减少。NAT允许IPv4客户端共享单个 IP 地址。
鉴于IPv4是两种使用的互联网协议中更常见的一种,这将是我们前进的重点。
127.0.0.1 的工作原理(How 127.0.0.1 Works)
当您建立到 127.0.0.1 环回地址的IPv4连接时,将分配一个 255.0.0.1 子网掩码。因此,如果任何公共交换机、路由器或网关接收到以您的环回为目的地的数据包,则不会记录数据的信息。
这意味着如果数据包在本地主机之外被丢弃,信息将不会继续传输到网络上的另一台计算机。这有助于通过防止您的机器拾取可能试图激活其他服务作为响应的杂散数据包来维护网络安全。
本地主机的常见用途(Common Uses For Localhost)
除了安全功能之外,localhost 在其他一些场景中也很有用。环回地址有三个主要用途,被认为对计算机网络技术人员有用。
运行速度测试(Running A Speed Test)
发送 ping 请求是环回地址最常见的用途。使用Windows 命令提示符(Windows Command Prompt),您可以测试您的连接并发现您的计算机当前可能面临的任何性能问题。(performance issues)
要对 localhost 执行 ping 请求:
- 打开运行(Run)功能(Windows键 + R)对话框并输入cmd。按Enter。
- 您还可以在任务栏搜索(Taskbar Search)框中键入cmd ,然后从列表中选择命令提示符。(Command Prompt )
- 建议以管理员身份运行(Running as Administrator)。
- 键入ping 127.0.0.1并按Enter。
结果将显示在屏幕上。显示的数据将包括发送、接收、丢失的数据包数量以及数据传输的大致往返时间。
阻止网站(Blocking Websites)
当您需要阻止对某些网站的访问时,localhost 可以解决问题。环回对于防止浏览器进入恶意站点非常有用。要做到这一点,您需要知道主机文件是什么以及它们在此上下文中的用途。
每次您的计算机尝试使用该域名访问网站或远程计算机时,计算机都会向域名服务器(Domain Name Server)( DNS ) 发送请求以搜索本地存储的主机文件(locally stored host file)。
例如,IPv4地址 127.0.0.1,将在DNS中显示为“localhost” 。您访问的任何新网站的域名也会发现自己存储为主机文件。这为对同一站点的任何回访创建了更快的负载响应。
主机文件还将包含它存储的所有域名的 IP 地址。您必须编辑这些 IP 地址(edit these IP addresses)以匹配环回地址 127.0.0.1 才能阻止它们。这样做会导致流量被引导回本地主机。
虽然它在紧要关头工作,但使用 localhost 作为防止访问不良网站的方法并不是最好的解决方案。主要原因是,如果您需要访问这些站点,则必须以管理员身份手动删除该条目。只有创建初始条目的管理员才能执行此操作,从而将出于某种原因需要访问特定站点的其他人拒之门外。
测试新程序或 Web 应用程序(Testing New Programs Or Web Applications)
每当触发回送时,您的操作系统就会成为模拟服务器。这使得可以将程序的任何必要文件加载到服务器中以测试功能。
结合其他软件,您甚至可以使用环回来允许侧载移动应用程序访问桌面服务器组件或向特定API发送请求。
What Is Localhost and How Can You Use It?
The localhost – also referred to as ‘the loopback address’ – is usеd to establish an IP connectiоn or call, to your own computer or machine. The looрback address is typically used in the context of networking and provides a computer the сapаbilitу to validate the IP stack.
Anyone with a background or interest in networking will find it important to learn and understand the affiliated computer terminology with the field. Localhost is one such piece of terminology seen as beneficial to any computer technician. Understanding the importance and uses of localhost is also a great place to begin your journey into networking terminology.
What Is LocalHost and How Is It Used?
Not just a term, localhost can also be a domain name, like netflix.com or google.com. Just like any domain, the localhost will also have its own Internet Protocol (IP) address.
The address needed will depend on the internet protocol being used. Calling the localhost using IPv4, which is the most common IP, will have a range of 127.0.0.0 to 127.255.255.255 but will typically default to 127.0.0.1. IPv6 users can establish a loopback by entering :1.
Internet Protocol
The Internet Protocol (IP) was put in place to establish a standard method for computers to communicate with other devices on the network. It not only governs addresses but also how your data is sent and received for both local networks and on the internet.
IPv4, which is Internet Protocol version 4, is the one most commonly used globally. IPv4 relies heavily on the Transmission Control Protocol (TCP) to handle the bulk of data concerns such as delivery, sequencing, and integrity. This IP was designed as a connectionless protocol to be used on ethernet-based machines.
IPv6 has begun slowly replacing IPv4. The demand for IP addresses has grown exponentially in the wake of the digital boom. More and more devices are using the internet, so IPv6 was developed to accommodate the increase and address a few of the fundamental flaws found in IPv4.
Where IPv4 allows for approximately 4.3 billion unique IP addresses for use, IPv6 will permit up to 340 trillion, trillion.
Aside from numbers, IPv6 also offers networking advantages. It opens up easier detection between devices of other IPv6 enabled networks, allowing users to use services without the need for end-user action. The need for the Network Address Translation (NAT) is also significantly reduced when using IPv6. The NAT is what allows IPv4 clients to share a single IP address.
Seeing as IPv4 is the more common of the two used internet protocols, it will be our focus moving forward.
How 127.0.0.1 Works
When you establish an IPv4 connection to the 127.0.0.1 loopback address, a 255.0.0.1 subnet mask is assigned. So, if any public switch, router, or gateway receives a data packet with your loopback as its destination, the data’s information will not be logged.
This means that if a data packet is dropped off outside of the localhost, the information will not continue on to another computer on the network. This helps to maintain network security by preventing your machine from picking up stray data packets that may attempt to activate other services in response.
Common Uses For Localhost
Aside from security capabilities, localhost can be useful in a few other scenarios. There are three primary purposes for the loopback address considered useful to a computer network technician.
Running A Speed Test
Sending a ping request is the most common use you’ll find for the loopback address. Using the Windows Command Prompt, you can test your connection and discover any performance issues your computer may currently be facing.
To perform a ping request to localhost:
- Open the Run function (Windows key + R) dialog and type cmd. Press Enter.
- You can also type cmd into the Taskbar Search box and select Command Prompt from the list.
- Running as Administrator is advised.
- Type ping 127.0.0.1 and press Enter.
The results will be displayed on the screen. The data shown will include the number of data packets sent, received, lost, and the approximate round trip time of the data transmission.
Blocking Websites
When you need to block access to certain websites, localhost can do the trick. The loopback can be quite useful in the prevention of your browser from entering malicious sites. To pull this off, you’ll need to know what host files are and the purpose they serve in this context.
Each time your computer attempts to access a website or remote computer using the domain name, the computer will send a request to the Domain Name Server (DNS) in search of a locally stored host file.
For example, the IPv4 address 127.0.0.1, will be displayed as ‘localhost’ in the DNS. The domain name of any new website you visit will also find itself stored as a host file. This creates a faster load response for any return visits to the same site.
The host file will also contain the IP addresses of all the domain names it stores. You’ll have to edit these IP addresses to match the loopback address 127.0.0.1 in order to block them. Doing so will cause traffic to be directed back to the localhost instead.
Though it works in a pinch, using localhost as a method to prevent access to undesirable websites is not the best solution. The primary reason being that if you were to need access to those sites, you would have to manually remove the entry as an administrator. Only the administrator who created the initial entry will be able to do this, locking out others who need to reach the specific site for one reason or another.
Testing New Programs Or Web Applications
Whenever a loopback is triggered, your operating system becomes a simulated server. This makes it possible to load any necessary files of a program into the server in order to test functionality.
In combination with other software, you can even use loopback to allow side-loaded mobile apps to access desktop server components or send requests to a specific API.