Skip to main content.

Tunneling traffic through DNS


Live demo in BSD Now Episode 046. | Originally written by TJ for | Last updated: 2014/11/01

NOTE: the author/maintainer of the tutorial(s) is no longer with the show, so the information below may be outdated or incorrect.

Public wifi is great, but sometimes there are annoying restrictions in place to prevent you from using it freely. You've probably been to an airport or coffee shop and seen the "Pay X dollars for an hour of wireless!" messages. They take over your entire browsing session, and the network refuses to load any of the websites you actually want to go to. Sometimes, however, you can bypass these annoyances without paying a dime! For this tutorial, we'll be relying on the (very likely) fact that the company who set up the network misconfigured it to allow DNS requests to pass through. Keep in mind that this is a last ditch effort to get free connectivity. It will be painfully slow for anything more than light web browsing. You will need the following things:

  • A remotely accessible server running SSH (a router is fine too)
  • A client machine (probably your laptop)
  • A domain name whose records you control, or an account at

Once you're connected to the annoying network, a simple way to test is:

$ host

If you get a response like: has address

then you can continue reading. If not, and they're also blocking DNS, this method won't work. In such a case, your best bet is likely to spoof your MAC address to be the same as one of the connected clients, then forcefully spam deauth packets and take over their session. That's not very nice though. The tool we'll be using today is called "iodine" and it's in FreeBSD ports, OpenBSD ports and NetBSD pkgsrc - all under the "net/" category. Install it however you like on both the server and your client machine. The next step is to set up the DNS records for your domain. To keep things organized, we'll be creating the following two subdomains:

  •, with an A record of "" (you'll want the real IP of your server)
  •, with an NS record of ""

How you set those up will vary greatly depending on your provider, so you'll have to figure that one out on your own. Next, we'll start the server half of the utility. Be sure you allow incoming traffic on port 53 in your firewall. Running sshd on a port like 443 will also increase your chances of being able to successfully tunnel out of the restrictive network. Now, on your server, run:

# iodined -u _iodined -t /var/empty -c -f -D -P password

Debug level 1 enabled, will stay in foreground.
Add more -D switches to set higher debug level.
Opened /dev/tun0
Setting IP of tun0 to
Adding route to
add net gateway
Setting MTU of tun0 to 1130
Opened UDP socket
Listening to dns for domain

In this example, we'll be creating the "tun0" interface with an IP address of, and we'll use "password" as the authentication. You should probably use a better password, but keep in mind that it will be visible in the process list. To check that the interface was created correctly, run:

# ifconfig tun0

tun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1130
        inet --> netmask 0xffffffe0 
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
        Opened by PID 42283

You'll also want to make sure your /etc/ssh/sshd_config file does not have the "ListenAddress" line set to your public IP. The server component of iodine can be run in tmux, or as a daemon via /etc/rc.conf (on FreeBSD), /etc/rc.conf.local (on OpenBSD) or via /etc/rc.local. See the man page for more options. Now, switch over to the client system and run the following:

# iodine -f -u _iodined -t /var/empty -P password

Opened /dev/tun0
Opened UDP socket
Sending DNS queries for to
Autodetecting DNS query type (use -T to override).
Using DNS type NULL queries
Version ok, both using protocol v 0x00000502. You are user #0
Setting IP of tun0 to
Adding route to
add net gateway
Setting MTU of tun0 to 1130
Server tunnel IP is
Testing raw UDP data to the server (skip with -r)
Server is at, trying raw login: OK
Sending raw traffic directly to
Connection setup complete, transmitting data.

At this point, the server console should display something similar to this:

IN   login raw, len 16, from user 0
IN   ping raw, from user 0
IN   pkt raw, total 62, from user 0
IN   pkt raw, total 116, from user 0

Also remember to allow incoming/outgoing traffic on the "tun0" interface in your firewall (on both the client and server) if you haven't already. The tunnel should now be set up between the two systems, using only DNS to communicate. A simple way to see if it's working is with SSH, like so:

$ ssh -C

tj@'s password: 

OpenBSD 5.6 (GENERIC) #0: Sat Nov 1 16:25:49 EDT 2014

Welcome to OpenBSD: The proactively secure Unix-like operating system.

Please use the sendbug(1) utility to report bugs in the system.
Before reporting a bug, please try to reproduce it with the latest
version of the code.  With bug reports, please try to ensure that
enough information to reproduce the problem is enclosed, and if a
known fix for it exists, include that as well.


We'll use the "-C" flag for compression, since every bit is precious in this case. To verify you're connected through the tunnel, we'll see what IP we're logged in from.

$ w

 9:16PM  up 61 days, 21:46, 3 users, load averages: 0.34, 0.24, 0.18
tj       p0          9:16PM     0 w 

If you've gotten this far, that means it's all working properly. You can disconnect and set up a SOCKS proxy with SSH, then tunnel all your traffic through that. See our stunnel tutorial and SSH chaining tutorial for more information and interesting ideas.

Latest News

New announcement


We understand that Michael Dexter, Brad Davis, and George Rosamond think there should be more real news....

Two Year Anniversary


We're quickly approaching our two-year anniversary, which will be on episode 105. To celebrate, we've created a unique t-shirt design, available for purchase until the end of August. Shirts will be shipped out around September 1st. Most of the proceeds will support the show, and specifically allow us to buy...

New discussion segment


We're thinking about adding a new segment to the show where we discuss a topic that the listeners suggest. It's meant to be informative like a tutorial, but more of a "free discussion" format. If you have any subjects you want us to explore, or even just a good name...

How did you get into BSD?


We've got a fun idea for the holidays this year: just like we ask during the interviews, we want to hear how all the viewers and listeners first got into BSD. Email us your story, either written or a video version, and we'll read and play some of them for...

Episode 281: EPYC Server battle


Direct Download:MP3 AudioVideo Headlines scp client multiple vulnerabilities Overview SCP clients from multiple vendors are susceptible to a malicious scp server performing unauthorized changes to target directory and/or client output manipulation. Description Many scp clients fail to verify if the objects returned by the scp server match those it asked for. This issue dates back to 1983 and...

Episode 280: FOSS clothing


Direct Download:MP3 AudioVideo Headlines A EULA in FOSS clothing? There was a tremendous amount of reaction to and discussion about my blog entry on the midlife crisis in open source. As part of this discussion on HN, Jay Kreps of Confluent took the time to write a detailed response — which...

Episode 279: Future of ZFS


Direct Download:MP3 AudioVideo Headlines The future of ZFS in FreeBSD The sources for FreeBSD's ZFS support are currently taken directly from Illumos with local ifdefs to support the peculiarities of FreeBSD where the Solaris Portability Layer (SPL) shims fall short. FreeBSD has regularly pulled changes from Illumos and tried to push...

Episode 278: The real McCoy


Direct Download:MP3 AudioVideo Interview - Kirk McKusick - 25 years of FreeBSD How Kirk got started in BSD, at the very beginning Predicting the Future How the code and community grew The leadership of the project, and how it changed over time UFS over the years (reading disks from 1982 in 2018) Conferences The rise and fall of...