<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>DNS | The End of the Tunnel</title><link>https://development--vigilant-hodgkin-644b1e.netlify.com/tags/dns/</link><atom:link href="https://development--vigilant-hodgkin-644b1e.netlify.com/tags/dns/index.xml" rel="self" type="application/rss+xml"/><description>DNS</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><copyright>© 2019 Derek Murawsky</copyright><lastBuildDate>Wed, 29 Aug 2018 12:05:52 -0400</lastBuildDate><image><url>https://development--vigilant-hodgkin-644b1e.netlify.com/img/icon-32.png</url><title>DNS</title><link>https://development--vigilant-hodgkin-644b1e.netlify.com/tags/dns/</link></image><item><title>Rebuilding the Homestead’s DNS with Consul, DNSMasq, and Ansible</title><link>https://development--vigilant-hodgkin-644b1e.netlify.com/post/rebuilding-homestead-dns/</link><pubDate>Wed, 29 Aug 2018 12:05:52 -0400</pubDate><guid>https://development--vigilant-hodgkin-644b1e.netlify.com/post/rebuilding-homestead-dns/</guid><description>
&lt;p&gt;My friend Jason recently posted an update on his blog over at &lt;a href=&#34;https://peaksandprotocols.com/home-network-dns-infrastructure/&#34; target=&#34;_blank&#34;&gt;Peaks and Protocols&lt;/a&gt; about redoing his home network’s DNS setup. This reminded me that I really needed to do an update on my own recent DNS rebuild, which was based around &lt;a href=&#34;https://www.hashicorp.com/&#34; target=&#34;_blank&#34;&gt;Hashicorp&lt;/a&gt;‘s &lt;a href=&#34;https://www.consul.io/&#34; target=&#34;_blank&#34;&gt;Consul&lt;/a&gt;, &lt;a href=&#34;http://www.thekelleys.org.uk/dnsmasq/doc.html&#34; target=&#34;_blank&#34;&gt;DNSMasq&lt;/a&gt; and &lt;a href=&#34;https://www.ansible.com/&#34; target=&#34;_blank&#34;&gt;Ansible&lt;/a&gt; running on some &lt;a href=&#34;https://www.raspberrypi.org/&#34; target=&#34;_blank&#34;&gt;Raspberry Pi 3&lt;/a&gt;s. Overkill? Probably. But if you can’t have fun with your home network, what’s the point? On to the setup…&lt;/p&gt;
&lt;figure&gt;
&lt;a data-fancybox=&#34;&#34; href=&#34;images/homenet.png&#34; &gt;
&lt;img src=&#34;images/homenet.png&#34; alt=&#34;&#34; &gt;&lt;/a&gt;
&lt;/figure&gt;
&lt;h2 id=&#34;consul&#34;&gt;Consul&lt;/h2&gt;
&lt;p&gt;
&lt;figure&gt;
&lt;a data-fancybox=&#34;&#34; href=&#34;images/consul-logo.png&#34; &gt;
&lt;img src=&#34;images/consul-logo.png&#34; alt=&#34;&#34; width=&#34;100&#34; &gt;&lt;/a&gt;
&lt;/figure&gt;
Consul started life as a distributed service locator and key-value store. It has grown significantly over the years and is now becoming a full-fledged service mesh. It allows for any server to register and provide one or multiple services, with simple config files or api calls. Further, Consul supports the idea of multiple locations natively and even has health checks. This means it will give you your local, healthy service endpoint.&lt;/p&gt;
&lt;p&gt;One of the main reasons I chose Consul is because it makes itself available via DNS as the .consul domain. Want to know where your git server is? dig git.service.consul. Your documentation hosted on a webserver somewhere? dig docs.service.consul. This makes finding a service you have running somewhere trivial, and means never having to update a DNS zone file again.&lt;/p&gt;
&lt;p&gt;Another reason, which I’m not using yet, is that it has a solid key-value store. This is great for storing configuration settings for distributed applications. There are a ton of tools that take advantage of this, and even provide dynamic reloading capabilities to the app when a key is changed in Consul.&lt;/p&gt;
&lt;h2 id=&#34;dnsmasq&#34;&gt;DNSMasq&lt;/h2&gt;
&lt;p&gt;In order to take advantage of Consul’s DNS features you need a DNS server that can point to Consul for just that domain, while passing through all other traffic to a normal DNS resolver. I chose DNSMasq for this because it is simple and well understood. There were some security issues with it last year, but they have since been addressed. I may migrate to &lt;a href=&#34;https://nlnetlabs.nl/projects/unbound/about/&#34; target=&#34;_blank&#34;&gt;unbound&lt;/a&gt; in the long run, but DNSMasq is fine for my use cases.&lt;/p&gt;
&lt;h2 id=&#34;ansible-putting-it-all-together&#34;&gt;Ansible &amp;amp; Putting it All Together&lt;/h2&gt;
&lt;figure&gt;
&lt;a data-fancybox=&#34;&#34; href=&#34;images/ansible-logo.png&#34; &gt;
&lt;img src=&#34;images/ansible-logo.png&#34; alt=&#34;&#34; width=&#34;100&#34; &gt;&lt;/a&gt;
&lt;/figure&gt;
&lt;p&gt;Ansible is the glue that makes sure I can redo this config easily should something happen to the PIs. It is a configuration management system that just works, with minimal extra craziness. I could go on for days about Ansible, and probably should write a dozen posts on it alone, but there’s so much out there already that I don’t feel the need. Bottom line is, this is the tool that sets up Consul and DNSMasq for me, and ensures that I can reset everything to a known working state in the event of configuration drift.&lt;/p&gt;
&lt;p&gt;I used several modules to help get this project running quickly.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/idealista/consul-role&#34; target=&#34;_blank&#34;&gt;idealista-consul-role&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/Oefenweb/ansible-dnsmasq&#34; target=&#34;_blank&#34;&gt;oefenweb.dnsmasq&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/geerlingguy/ansible-role-ntp&#34; target=&#34;_blank&#34;&gt;geerlingguy.ntp&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I ended up having to change some of the roles around to suit the raspberry pi environment, but otherwise it was fairly easy. I created my own baseline role which updates and upgrades and installs some packages, including python and its tools. This base role also creates a user account for me and Ansible itself. The first time I ran it, I had to pass parameters to login as the default Raspbian user, but after that it can run using the Ansible user instead.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-yaml&#34;&gt;- name: Update Apt and Upgrade Packages
apt:
update_cache: yes
cache_valid_time: 3600
name: &amp;quot;*&amp;quot;
state: latest
tags:
- packages
- name: Install Baseline Apps
apt:
name: &amp;quot;{{ packages }}&amp;quot;
state: present
vars:
packages:
- python
- python-pip
- python3
- python3-pip
- virtualenv
- python3-virtualenv
- python-pip
- dnsutils
tags:
- packages
- name: Install pi base python packages
pip:
name: &amp;quot;{{ packages }}&amp;quot;
state: present
vars:
packages:
- python-consul
- hvac
- name: Create Ansible management user
user:
name: ansible
comment: Ansible system user
group: admin
state: present
- name: Create dmurawsky user
user:
name: dmurawsky
comment: Derek Murawsky
group: admin
state: present
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For my group_vars, I created a DNS.yml file with the needed variables for consul and DNSMasq.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-yaml&#34;&gt;# Consul Configuration
consul_version: 1.2.2
#consul_package: consul_1.2.2_linux_arm.zip
consul_server: true
consul_agent: true
consul_ui: true
consul_server_nodes:
- 192.168.1.2
- 192.168.1.3
# Services #
consul_agent_services: true
consul_services_register:
# Register NTP in consul
- name: ntp
port: 123
tags:
- udp
- name: dns
port: 53
tags:
- udp
# Hashicorp Vault
vault_version: 0.10.4
vault_pkg: vault_{{ vault_version }}_linux_arm.zip
vault_pkg_sum: 384e47720cdc72317d3b8c98d58e6c8c719ff3aaeeb71b147a6f5f7a529ca21b
# DNSMasq
dnsmasq_dnsmasq_conf:
- |
port=53
bind-interfaces
server=8.8.8.8
server=8.8.4.4
dnsmasq_dnsmasq_d_files_present:
cache:
- |
domain-needed
bogus-priv
no-hosts
dns-forward-max=150
cache-size=1000
neg-ttl=3600
no-poll
no-resolv
consul:
- |
server=/consul/127.0.0.1#8600
homestead-murawsky-net:
- address=/usg.homestead.murawsky.net/192.168.1.1
- address=/ns1.homestead.murawsky.net/192.168.1.2
- address=/ns2.homestead.murawsky.net/192.168.1.3
# NTP
ntp_enabled: true
ntp_manage_config: true
ntp_area: &#39;us&#39;
ntp_servers:
- &amp;quot;0{{ ntp_area }}.pool.ntp.org iburst&amp;quot;
- &amp;quot;1{{ ntp_area }}.pool.ntp.org iburst&amp;quot;
- &amp;quot;2{{ ntp_area }}.pool.ntp.org iburst&amp;quot;
- &amp;quot;3{{ ntp_area }}.pool.ntp.org iburst&amp;quot;
ntp_timezone: America/New_York
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And finally, the simple site.yml file.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-yaml&#34;&gt;- name: Configure System Baselines
hosts: all
roles:
- { role: baseline, tags: [&#39;baseline&#39;]}
- name: Configure DNS hosts
hosts: dns
roles:
- { role: ntp, tags: [&#39;ntp&#39;] }
- { role: dnsmasq, tags: [&#39;dnsmasq&#39;] }
- { role: consul, tags: [&#39;consul&#39;] }
- { role: hashivault, tags: [&#39;hashivault&#39;] }
&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&#34;results&#34;&gt;Results&lt;/h2&gt;
&lt;p&gt;DNS resolution worked perfectly out of the gate as expected, but what about Consul?&lt;/p&gt;
&lt;p&gt;
&lt;figure&gt;
&lt;a data-fancybox=&#34;&#34; href=&#34;images/consul-screenshot.png&#34; &gt;
&lt;img src=&#34;images/consul-screenshot.png&#34; alt=&#34;&#34; width=&#34;600&#34; &gt;&lt;/a&gt;
&lt;/figure&gt;
Brilliant! Sure, the services that I have loaded are pretty simple and don’t really benefit from a service locator, but they’re examples of what is possible. Now I can register any new service by loading the consul agent onto the server and simply adding a definition file in the appropriate folder! This should make future expansion of services much easier.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I currently have two consul servers. This is bad and not highly available. I have to get one more consul server online. Debating between another pi or putting on the home server.&lt;/p&gt;
&lt;h2 id=&#34;future-plans&#34;&gt;Future Plans&lt;/h2&gt;
&lt;p&gt;You’ll notice there’s no real security around the deployment above either. That needs to be fixed in terms of Consul ACLs, Vault, and password/key management for user accounts. There’s also a cool tool called &lt;a href=&#34;https://pi-hole.net/&#34; target=&#34;_blank&#34;&gt;pi-hole&lt;/a&gt; which is a dns level ad blocker that I want to integrate into my environment. I also plan on setting up Docker on my home server in the not too distant future to make it easier to host some fun services like &lt;a href=&#34;https://prometheus.io/&#34; target=&#34;_blank&#34;&gt;Prometheus&lt;/a&gt;, &lt;a href=&#34;https://grafana.com/&#34; target=&#34;_blank&#34;&gt;Grafana&lt;/a&gt;, &lt;a href=&#34;https://www.home-assistant.io/&#34; target=&#34;_blank&#34;&gt;HomeAssistant&lt;/a&gt;, and some other cool tools. I’ll also have to extend the network to my barn as the office is moving out there. Lastly, I want to build a portable lab that I can take with me when doing demos or presentation at local user groups.&lt;/p&gt;</description></item><item><title>How to clear all Workstation DNS caches from PowerShell</title><link>https://development--vigilant-hodgkin-644b1e.netlify.com/post/clear-dns-caches-powershell/</link><pubDate>Thu, 04 Sep 2014 16:20:07 -0400</pubDate><guid>https://development--vigilant-hodgkin-644b1e.netlify.com/post/clear-dns-caches-powershell/</guid><description>&lt;p&gt;I recently found myself in need of the ability to clear the DNS cache of all the laptops in my company. I found a very powerful and simple way to do so and thought I would share.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-powershell&#34;&gt;$c = Get-ADComputer -Filter {operatingsystem -notlike &amp;quot;*server*&amp;quot; }
Invoke-Command -cn $c.name -SCRIPT { ipconfig /flushdns }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first line queries Active Directory for all computers that are not servers. The second line simply invokes the normal windows command “ipconfig /flushdns” on all computers.&lt;/p&gt;
&lt;p&gt;This technique could be used to run any command across all workstations. Very powerful, and dangerous. Use at your own risk!&lt;/p&gt;</description></item><item><title>Monitoring and Caching Dns</title><link>https://development--vigilant-hodgkin-644b1e.netlify.com/post/monitoring-and-caching-dns/</link><pubDate>Thu, 20 Jun 2013 15:18:48 -0400</pubDate><guid>https://development--vigilant-hodgkin-644b1e.netlify.com/post/monitoring-and-caching-dns/</guid><description>
&lt;figure&gt;
&lt;a data-fancybox=&#34;&#34; href=&#34;images/rabbit-hole-150.jpg&#34; &gt;
&lt;img src=&#34;images/rabbit-hole-150.jpg&#34; alt=&#34;&#34; &gt;&lt;/a&gt;
&lt;/figure&gt;
&lt;p&gt;Had an interesting issue today. One of the production systems suddenly went dark, and we found out about it from the client. This is never a good way to start a Thursday. It turns out that the client was having DNS issues and the domain was no longer valid. Relatively simple fix, crisis averted…&lt;/p&gt;
&lt;p&gt;But why didn’t the monitoring system pick it up?&lt;/p&gt;
&lt;p&gt;We use &lt;a href=&#34;Dotcom-Monitor&#34; target=&#34;_blank&#34;&gt;Dotcom-Monitor&lt;/a&gt; to check each of our sites on a regular basis. The monitor actually logs in to each website to verify functionality. What in the DNS world could cause this issue in such a scenario? How about a caching nameserver? Turns out, to limit the stress on their nameserver, Dotcom Monitor set up a standard caching nameserver that keeps a record in cache until the record expires. So even though DNS was no longer working for this site, the monitor thought everything was A-OK.&lt;/p&gt;
&lt;p&gt;What can we do to fix this issue? Not much unfortunately. Dotcom Monitor will have to implement a change in their infrastructure which will likely increase the load on their DNS servers significantly. Since that’s not likely, it looks like I’ll have to build a service into our internal monitor (&lt;a href=&#34;http://www.zabbix.com/&#34; target=&#34;_blank&#34;&gt;Zabbix&lt;/a&gt; based) to check for the domain against the SOA for it.&lt;/p&gt;</description></item><item><title>Flush Dns Cache for Single Domain</title><link>https://development--vigilant-hodgkin-644b1e.netlify.com/post/flush-dns-cache-for-single-domain/</link><pubDate>Tue, 11 Jun 2013 15:05:15 -0400</pubDate><guid>https://development--vigilant-hodgkin-644b1e.netlify.com/post/flush-dns-cache-for-single-domain/</guid><description>&lt;p&gt;I was working on the site today and ran into an issue: Our caching DNS server (Windows 2008) was holding on to the old webserver’s IP. This wasn’t a problem for me locally as I used the old hosts file trick to point to the new server. However, this meant I couldn’t show other folks the site until either the cache was completely flushed or the record expired.&lt;/p&gt;
&lt;p&gt;A little googling later, and I found this little command from &lt;a href=&#34;ServerFault&#34; target=&#34;_blank&#34;&gt;ServerFault&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4&#34;&gt;&lt;code class=&#34;language-shell&#34; data-lang=&#34;shell&#34;&gt;dnscmd dnsserver.local /NodeDelete ..Cache whatever.com &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt;/Tree&lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt; &lt;span style=&#34;color:#f92672&#34;&gt;[&lt;/span&gt;/f&lt;span style=&#34;color:#f92672&#34;&gt;]&lt;/span&gt;
/tree Specifies to delete all of the child records.
/f Executes the command without asking &lt;span style=&#34;color:#66d9ef&#34;&gt;for&lt;/span&gt; confirmation.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This allows you to clear just a small portion of the cache, as you define it. Pretty handy!&lt;/p&gt;</description></item></channel></rss>