Skip to content

Commit

Permalink
dns: Add --dns-hosts command-line option.
Browse files Browse the repository at this point in the history
The --dns switch adds firewall rules to intercept queries only for
nameservers found in resolv.conf ; This command-line option allows
the user to explicitly specify the nameservers to create firewall
redirection rules for.

This is useful when using a local DNS forwarder to redirect DNS queries
to different nameservers.

Example:

  We can use sshuttle to access a private subnet 172.30.0.0/16, which hosts
  a local DNS server resolving private domain names in that subnet.

  Currently, the only way to be able to resolve those domain names is to use
  the --dns switch. However, all DNS queries will then go through the remote
  nameserver, which might not be desirable especially if said nameserver
  does not know how to resolve every query.

  One solution is to run a local DNS forwarder, which knows that the private
  domain names can be resolved through a private IP, say 172.30.128.40.

  Now, we can run :

    sshuttle -r ssh.remoteserver.com -i 172.30.0.0/16 --dns-hosts 172.30.128.40

  DNS queries for private domain names will get forwarded to 172.30.128.40,
  intercepted by the firewall rule and sent through the tunnel to the nameserver
  used by the remote endpoint (which might or might not be 172.30.128.40 !).

Notes :

    * There is nothing preventing --dns-hosts from being used together with
	  --dns, in which case the nameservers found in resolv.conf will also be
	  added to the firewall rules as usual. This defeats the purpose of the
	  example, however.
	  There might be some weird use-case where this is useful ?

    * Since there is no control over which nameserver the query gets sent to
	  after it has crossed the tunnel, the IPs specified in --dns-hosts are
	  irrelevant (as long as they are the same as found in the DNS forwarder
	  configuration). This might be a little counter-intuitive.
  • Loading branch information
Narthorn committed Nov 1, 2013
1 parent 3899e2e commit 0cc65cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions client.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ def onhostlist(hostlist):
mux.callback()


def main(listenip, ssh_cmd, remotename, python, latency_control, dns,
def main(listenip, ssh_cmd, remotename, python, latency_control,
dns, dns_hosts,
seed_hosts, auto_nets,
subnets_include, subnets_exclude, syslog, daemon, pidfile):
if syslog:
Expand Down Expand Up @@ -380,11 +381,12 @@ def main(listenip, ssh_cmd, remotename, python, latency_control, dns,
listenip = listener.getsockname()
debug1('Listening on %r.\n' % (listenip,))

if dns:
if dns or dns_hosts:
dnsip = dnslistener.getsockname()
debug1('DNS listening on %r.\n' % (dnsip,))
dnsport = dnsip[1]
dns_hosts = resolvconf_nameservers()
if dns:
dns_hosts += resolvconf_nameservers()
else:
dnsport = 0
dnslistener = None
Expand Down
4 changes: 3 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def parse_ipport(s):
H,auto-hosts scan for remote hostnames and update local /etc/hosts
N,auto-nets automatically determine subnets to route
dns capture local DNS requests and forward to the remote DNS server
dns-hosts= capture DNS requests to these servers and forward (comma-separated)
python= path to python interpreter on the remote server
r,remote= ssh hostname (and optional username) of remote sshuttle server
x,exclude= exclude this subnet (can be used more than once)
Expand All @@ -67,7 +68,6 @@ def parse_ipport(s):
V,version print sshuttle's version number
syslog send log messages to syslog (default if you use --daemon)
pidfile= pidfile name (only if using --daemon) [./sshuttle.pid]
dns-hosts= (internal use only)
server (internal use only)
firewall (internal use only)
hostwatch (internal use only)
Expand Down Expand Up @@ -113,6 +113,7 @@ def parse_ipport(s):
remotename = opt.remote
if remotename == '' or remotename == '-':
remotename = None
nslist = re.split(r'[\s,]+', opt.dns_hosts.strip()) if opt.dns_hosts else []
if opt.seed_hosts and not opt.auto_hosts:
o.fatal('--seed-hosts only works if you also use -H')
if opt.seed_hosts:
Expand All @@ -127,6 +128,7 @@ def parse_ipport(s):
opt.python,
opt.latency_control,
opt.dns,
nslist,
sh,
opt.auto_nets,
parse_subnets(includes),
Expand Down

0 comments on commit 0cc65cc

Please sign in to comment.