<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>DNS &#8211; My Shitty Code</title>
	<atom:link href="https://myshittycode.com/tag/dns/feed/" rel="self" type="application/rss+xml" />
	<link>https://myshittycode.com</link>
	<description>Embracing the Messiness in Search of Epic Solutions</description>
	<lastBuildDate>Thu, 05 Jan 2023 20:19:20 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://myshittycode.com/wp-content/uploads/2022/04/cropped-icon-32x32.png</url>
	<title>DNS &#8211; My Shitty Code</title>
	<link>https://myshittycode.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">205304208</site>	<item>
		<title>Wildcard Subdomains in /etc/hosts</title>
		<link>https://myshittycode.com/2022/03/29/wildcard-subdomains-in-etc-hosts/</link>
					<comments>https://myshittycode.com/2022/03/29/wildcard-subdomains-in-etc-hosts/#respond</comments>
		
		<dc:creator><![CDATA[Shitty Author]]></dc:creator>
		<pubDate>Tue, 29 Mar 2022 20:09:10 +0000</pubDate>
				<category><![CDATA[Operating System]]></category>
		<category><![CDATA[DNS]]></category>
		<category><![CDATA[dnsmasq]]></category>
		<category><![CDATA[MacOS]]></category>
		<category><![CDATA[resolver]]></category>
		<guid isPermaLink="false">https://myshittycode.com/?p=1409</guid>

					<description><![CDATA[<p>This post illustrates how you use a DNS forwarder to manage wildcard subdomains so that you don&#8217;t have to explicitly list each subdomain in /etc/host file. PROBLEM When trying to map multiple subdomains (ex: a.localhost, b.localhost, c.localhost, d.localhost) to the same IP, it is not possible to do the following in /etc/hosts: Rather, each subdomain [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://myshittycode.com/2022/03/29/wildcard-subdomains-in-etc-hosts/">Wildcard Subdomains in /etc/hosts</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>This post illustrates how you use a DNS forwarder to manage wildcard subdomains so that you don&#8217;t have to explicitly list each subdomain in <strong>/etc/host</strong> file.</p>



<h2 class="wp-block-heading">PROBLEM</h2>



<p>When trying to map multiple subdomains (ex: a.localhost, b.localhost, c.localhost, d.localhost) to the same IP, it is not possible to do the following in <strong>/etc/hosts</strong>:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
# /etc/hosts

1.2.3.4 *.localhost
</pre></div>


<p>Rather, each subdomain has to be explicitly defined:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
# /etc/hosts

1.2.3.4 a.localhost b.localhost c.localhost d.localhost
</pre></div>


<p>It requires you to babysit and manage these wildcard subdomains over time, but you do have a good job security.</p>



<h2 class="wp-block-heading">SOLUTION</h2>



<h3 class="wp-block-heading">Configuration</h3>



<p>Install a DNS forwarder using <a href="https://brew.sh/" target="_blank" rel="noopener">Homebrew</a>.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
brew install dnsmasq
</pre></div>


<p>Create a configuration to map the wildcard subdomains to the same IP.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo bash -c \
  &#039;echo &quot;address=/localhost/1.2.3.4&quot; &gt; /usr/local/etc/dnsmasq.d/localhost.conf&#039;
</pre></div>


<p>Restart the service.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo brew services restart dnsmasq
</pre></div>


<p>Create <strong>/etc/resolver</strong> directory.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo mkdir -p /etc/resolver
</pre></div>


<p>Create a custom DNS resolver where the file name is the domain name.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo bash -c \
  &#039;echo &quot;nameserver 127.0.0.1&quot; &gt; /etc/resolver/localhost&#039;
</pre></div>


<h3 class="wp-block-heading">Verification</h3>



<p>Flush the DNS cache first.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
sudo killall -HUP mDNSResponder
</pre></div>


<p>Verify that ping command on each subdomain resolves to the correct IP.</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: bash; title: ; notranslate">
$ ping -c 1 a.localhost
PING a.localhost (1.2.3.4): 56 data bytes

$ ping -c 1 b.localhost
PING b.localhost (1.2.3.4): 56 data bytes

$ ping -c 1 a.b.c.localhost
PING a.b.c.localhost (1.2.3.4): 56 data bytes
</pre></div><p>The post <a rel="nofollow" href="https://myshittycode.com/2022/03/29/wildcard-subdomains-in-etc-hosts/">Wildcard Subdomains in /etc/hosts</a> appeared first on <a rel="nofollow" href="https://myshittycode.com">My Shitty Code</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://myshittycode.com/2022/03/29/wildcard-subdomains-in-etc-hosts/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1409</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Lazy Loading (feed)
Database Caching 52/67 queries in 0.043 seconds using Disk

Served from: myshittycode.com @ 2026-02-20 08:30:25 by W3 Total Cache
-->