<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Jonathan Lloyd | Blog</title>
    <link>https://blog.thisisjonathan.com/index.xml</link>
    <description>Recent content on Jonathan Lloyd | Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <copyright>&amp;copy; Jonathan Lloyd 2018</copyright>
    <lastBuildDate>Sun, 22 Apr 2018 19:18:45 +0100</lastBuildDate>
    <atom:link href="https://blog.thisisjonathan.com/index.xml" rel="self" type="application/rss+xml" />
    
    <item>
      <title>Why localhost is local: 127.0.0.1 vs 0.0.0.0</title>
      <link>https://blog.thisisjonathan.com/post/why-you-cant-see-localhost-on-your-local-ip/</link>
      <pubDate>Sun, 22 Apr 2018 19:18:45 +0100</pubDate>
      
      <guid>https://blog.thisisjonathan.com/post/why-you-cant-see-localhost-on-your-local-ip/</guid>
      <description>

&lt;p&gt;&lt;em&gt;Note: this post is based on experience with Linux.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;We&amp;rsquo;ve all been there - you&amp;rsquo;re working on a server on your local machine and
need to show it to someone else on your local network. You grab your machine&amp;rsquo;s
IP using &lt;code&gt;netstat&lt;/code&gt;, &lt;code&gt;ifconfig&lt;/code&gt;, or similar and send it over. And&amp;hellip; they can&amp;rsquo;t
connect.&lt;/p&gt;

&lt;p&gt;If there isn&amp;rsquo;t an issue with your firewall settings, and you Google the right
thing, you may find a StackOverflow post telling you that your server has to
bind on &lt;code&gt;0.0.0.0&lt;/code&gt; rather than &lt;code&gt;127.0.0.1&lt;/code&gt;. But what does this mean and how does
it work?&lt;/p&gt;

&lt;h1 id=&#34;the-loopback-interface&#34;&gt;The Loopback Interface&lt;/h1&gt;

&lt;p&gt;Network Interfaces are objects within the kernel that represent an entry point
for the host on a particular network for sending/receiving packets. They can be
used to represent physical Network Interface Cards but they can also be
virtualised for other purposes.&lt;/p&gt;

&lt;p&gt;The purpose of the loopback interface, &lt;code&gt;lo&lt;/code&gt;, is to give the host the ability to
efficiently send packets to itself. The kernel implements this by returning
packets straight back to the interface without going any deeper into the
kernel&amp;rsquo;s networking stack.&lt;/p&gt;

&lt;p&gt;When your server process binds to &lt;code&gt;127.0.0.1&lt;/code&gt; it is bound to the &lt;code&gt;lo&lt;/code&gt; Network
Interface.  This is why you cannot connect to it from your local network - the
&lt;code&gt;lo&lt;/code&gt; interface can only be reached from your local machine.&lt;/p&gt;

&lt;h1 id=&#34;0-0-0-0-special-case&#34;&gt;0.0.0.0 Special Case&lt;/h1&gt;

&lt;p&gt;If you can&amp;rsquo;t connect to the server process from your local network when it is
bound to &lt;code&gt;127.0.0.1&lt;/code&gt;, what should you do instead? One option is to bind to your
machine&amp;rsquo;s address on your local network (&lt;code&gt;192.168.1.12&lt;/code&gt; or whatever). However,
it can be quite tedious to work out which interface is connected to your local
network and the IP that has been assigned to that interface.&lt;/p&gt;

&lt;p&gt;Another option is to bind to an address that can be routed to from &lt;em&gt;all&lt;/em&gt;
Network Interfaces. This is what happens when you bind to &lt;code&gt;0.0.0.0&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;0.0.0.0&lt;/code&gt; is a non-routable address that, by convention, will receive packets
from every Network Interface on the host.&lt;/p&gt;

&lt;p&gt;So, the next time you want to host something on your local network, remember to
bind to &lt;code&gt;0.0.0.0&lt;/code&gt;.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>