<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Iptables - Tag - blog::weyl.io</title>
    <link>https://weyl.io/tags/iptables/</link>
    <description>Chris Weyl&#39;s technical blog</description>
    <generator>Hugo 0.155.3 &amp; FixIt v0.4.0-alpha.3-20251225101113-8ffb9a95</generator>
    <language>en-us</language>
    <managingEditor>chris@weyl.io (Chris Weyl)</managingEditor>
    <webMaster>chris@weyl.io (Chris Weyl)</webMaster>
    <lastBuildDate>Mon, 13 Feb 2017 00:00:00 +0000</lastBuildDate>
    <atom:link href="https://weyl.io/tags/iptables/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>No, use *my* DNS.  (aka Netflix vs tunnelbroker.net)</title>
      <link>https://weyl.io/2017/02/no-use-my-dns-really/</link>
      <pubDate>Mon, 13 Feb 2017 00:00:00 +0000</pubDate><author>chris@weyl.io (Chris Weyl)</author>
      <guid>https://weyl.io/2017/02/no-use-my-dns-really/</guid>
      <category domain="https://weyl.io/categories/making-things-work/">Making Things Work</category>
      <description>&lt;p&gt;&lt;a href=&#34;https://developers.google.com/speed/public-dns/&#34; target=&#34;_blank&#34; rel=&#34;external nofollow noopener noreferrer&#34;&gt;Google DNS&lt;i class=&#34;fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt; is being&#xA;hardcoded into a significant number of devices now.  Which is nice, because it&#xA;pretty much always works.&lt;/p&gt;&#xA;&lt;p&gt;&amp;hellip;except when you&amp;rsquo;re trying to use Netflix and you have a&#xA;&lt;a href=&#34;http://tunnelbroker.net&#34; target=&#34;_blank&#34; rel=&#34;external nofollow noopener noreferrer&#34;&gt;tunnelbroker&lt;i class=&#34;fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt; IPv6 tunnel.  Ugh.&lt;/p&gt;&#xA;&lt;p&gt;So, this is a brief followup to &lt;a href=&#34;https://weyl.io/2017/01/stupid-openwrt-ipv6-tricks/&#34;&gt;Stupid OpenWRT tricks&lt;/a&gt;.  Or&#xA;maybe &amp;ldquo;Getting Netflix to work when your ISP doesn&amp;rsquo;t support IPv6 yet&amp;rdquo; is a&#xA;better way to put it&amp;hellip;&lt;/p&gt;&#xA;&lt;p&gt;Anyways.  In the previous post it I talked about how to use a local instance&#xA;of bind to strip IPv6 addresses (&lt;code&gt;AAAA&lt;/code&gt; records) from responses.  (Again, I&#xA;can&amp;rsquo;t take credit for that, though I like the way the person who came up with&#xA;the idea thinks!)  That solution works &lt;em&gt;fabulously&lt;/em&gt;.&lt;/p&gt;&#xA;&lt;p&gt;&amp;hellip;unless your device decides it&amp;rsquo;s going to ignore &lt;em&gt;your&lt;/em&gt; DNS servers, and go&#xA;hit up &lt;code&gt;8.8.8.8&lt;/code&gt; or &lt;code&gt;8.8.4.4&lt;/code&gt; (or &lt;code&gt;2001:4860:4860::8888&lt;/code&gt; or&#xA;&lt;code&gt;2001:4860:4860::8844&lt;/code&gt;) directly.  That&amp;rsquo;s going to fail.  Ugh.&lt;/p&gt;&#xA;&lt;p&gt;&lt;a href=&#34;https://en.wikipedia.org/wiki/Network_address_translation#DNAT&#34; target=&#34;_blank&#34; rel=&#34;external nofollow noopener noreferrer&#34;&gt;DNAT&lt;i class=&#34;fa-solid fa-external-link-alt fa-fw fa-xs ms-1 text-secondary&#34; aria-hidden=&#34;true&#34;&gt;&lt;/i&gt;&lt;/a&gt; to the&#xA;rescue!  (Some NAT, like some cholesterol, moderate alcohol intake, and not&#xA;staying up all night &lt;em&gt;too&lt;/em&gt; often, is actually incredibly useful to downright&#xA;fun.  Particularly when staying up all night and the moderate alcohol intake&#xA;are combined with writing ip6tables DNAT rules.)&lt;/p&gt;&#xA;&lt;p&gt;The problem is that we have clients bypassing our DNS in favor of servers out&#xA;on the public Internet.  Our solution?  Find anything that&amp;rsquo;s headed in through&#xA;our LAN interface (typically &lt;code&gt;br-lan&lt;/code&gt;) and is headed to 53/UDP, and DNAT it so&#xA;that it&amp;rsquo;s headed to our router&amp;rsquo;s LAN IP address.  We don&amp;rsquo;t need to try to&#xA;capture or reroute DNS traffic to &lt;code&gt;8.8.8.8&lt;/code&gt; etc, because we don&amp;rsquo;t really want&#xA;any of our clients doing direct DNS queries.  (At least, I can&amp;rsquo;t think of a&#xA;good reason.)&lt;/p&gt;&#xA;&lt;p&gt;OpenWRT makes this pretty easy.  While the Network-&amp;gt;Firewall-&amp;gt;Traffic Rules&#xA;page doesn&amp;rsquo;t support DNAT, it&amp;rsquo;s easy enough to craft a custom rule and plug it&#xA;in on the not very deceptively named &amp;ldquo;Custom Rules&amp;rdquo; page.  OpenWRT also has a&#xA;rather nice setup of iptables chains, including ones for user-defined rules,&#xA;so you can add rules without their being trashed every time the firewall is&#xA;reloaded.&lt;/p&gt;&#xA;&lt;p&gt;For our purposes, this will do the trick:&lt;/p&gt;&#xA;&lt;!-- &lt;script src=&#34;https://gist.github.com/rsrchboy/7d6db3b6fda455c7ba837f7a5fac35f4.js?file=hijack-ipv4.sh&#34;&gt;&lt;/script&gt; --&gt;&#xA;&lt;!-- &lt;script src=&#34;https://gist.github.com/rsrchboy/7d6db3b6fda455c7ba837f7a5fac35f4.js?file=hijack-ipv4.sh&#34;&gt;&lt;/script&gt; --&gt;&#xA;&lt;pre&gt;&lt;code&gt;iptables -t nat -A prerouting_lan_rule \&#xA;  -p udp --dport 53 -j DNAT --to 192.168.1.1 \&#xA;  -m comment --comment &amp;#39;dns capture and redirect DNAT&amp;#39;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note we&amp;rsquo;re using the user rule &lt;code&gt;prerouting_lan_rule&lt;/code&gt;; this rule already only&#xA;has packets coming in on &lt;code&gt;br-lan&lt;/code&gt;, so we can omit the &lt;code&gt;-i br-lan&lt;/code&gt; from our&#xA;rule we&amp;rsquo;d otherwise need.&lt;/p&gt;&#xA;&lt;p&gt;Once you&amp;rsquo;ve saved this, you either need to reboot or just ssh into your router&#xA;and run the command directly, and you should be able to watch Netflix again.&#xA;You can run &lt;code&gt;host netflix.com 8.8.8.8&lt;/code&gt; from a client box to see that no &lt;code&gt;AAAA&lt;/code&gt;&#xA;records are returned.&lt;/p&gt;&#xA;&lt;p&gt;While we&amp;rsquo;re here, we should probably do this for IPv6 as well, just in case.&#xA;First you&amp;rsquo;re going to need to install a couple additional packages:&#xA;&lt;code&gt;kmod-ipt-nat6&lt;/code&gt;, and if your LAN interface is a bridge you&amp;rsquo;ll also need&#xA;&lt;code&gt;kmod-ebtables-ipv6&lt;/code&gt;.  Then this rule should do it:&lt;/p&gt;&#xA;&lt;!-- &lt;script src=&#34;https://gist.github.com/rsrchboy/7d6db3b6fda455c7ba837f7a5fac35f4.js?file=hijack-ipv6.sh&#34;&gt;&lt;/script&gt; --&gt;&#xA;&lt;pre&gt;&lt;code&gt;ip6tables -t nat -A PREROUTING \&#xA;    -i br-lan -p udp --dport 53 -j DNAT \&#xA;    --to 2001:470:XXXX:XXXX::1 \&#xA;    -m comment --comment &amp;#39;dns capture and redirect DNAT&amp;#39;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Note OpenWRT does not set up any chains in the IPv6 NAT table, because you&#xA;should &lt;em&gt;never&lt;/em&gt; use NAT in IPv6.&lt;/p&gt;&#xA;&lt;p&gt;Um, aside from this, naturally.&lt;/p&gt;&#xA;&lt;p&gt;Enjoy!&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
