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 271: Automatic drive tests


Direct Download:MP3 AudioVideo Headlines MidnightBSD 1.0 now available I’m happy to announce the availability of MidnightBSD 1.0 for amd64 and i386. Over the years, many ambitious goals were set for our 1.0 release. As it approached, it was clear we wouldn’t be able to accomplish all of them. This release is...

Episode 270: Ghostly releases


Direct Download:MP3 AudioVideo Headlines OpenBSD 6.4 released See a detailed log of changes between the 6.3 and 6.4 releases. See the information on the FTP page for a list of mirror machines. Have a look at the 6.4 errata page for a list of bugs and workarounds. signify(1) pubkeys for this release: base: RWQq6XmS4eDAcQW4KsT5Ka0KwTQp2JMOP9V/DR4HTVOL5Bc0D7LeuPwA fw: RWRoBbjnosJ/39llpve1XaNIrrQND4knG+jSBeIUYU8x4WNkxz6a2K97 pkg:...

Episode 269: Tiny daemon lib


Direct Download:MP3 AudioVideo Headlines FreeBSD Foundation Update, September 2018 MESSAGE FROM THE EXECUTIVE DIRECTOR Dear FreeBSD Community Member, It is hard to believe that September is over. The Foundation team had a busy month promoting FreeBSD all over the globe, bug fixing in preparation for 12.0, and setting plans in motion to...

Episode 268: netcat demystified


Direct Download:MP3 AudioVideo Headlines Six Metrics for Measuring ZFS Pool Performance Part 1 The layout of a ZFS storage pool has a significant impact on system performance under various workloads. Given the importance of picking the right configuration for your workload and the fact that making changes to an in-use ZFS...