Skip to content

Commit 0cc65cc

Browse files
committed
dns: Add --dns-hosts command-line option.
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.
1 parent 3899e2e commit 0cc65cc

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ def onhostlist(hostlist):
339339
mux.callback()
340340

341341

342-
def main(listenip, ssh_cmd, remotename, python, latency_control, dns,
342+
def main(listenip, ssh_cmd, remotename, python, latency_control,
343+
dns, dns_hosts,
343344
seed_hosts, auto_nets,
344345
subnets_include, subnets_exclude, syslog, daemon, pidfile):
345346
if syslog:
@@ -380,11 +381,12 @@ def main(listenip, ssh_cmd, remotename, python, latency_control, dns,
380381
listenip = listener.getsockname()
381382
debug1('Listening on %r.\n' % (listenip,))
382383

383-
if dns:
384+
if dns or dns_hosts:
384385
dnsip = dnslistener.getsockname()
385386
debug1('DNS listening on %r.\n' % (dnsip,))
386387
dnsport = dnsip[1]
387-
dns_hosts = resolvconf_nameservers()
388+
if dns:
389+
dns_hosts += resolvconf_nameservers()
388390
else:
389391
dnsport = 0
390392
dnslistener = None

main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def parse_ipport(s):
5454
H,auto-hosts scan for remote hostnames and update local /etc/hosts
5555
N,auto-nets automatically determine subnets to route
5656
dns capture local DNS requests and forward to the remote DNS server
57+
dns-hosts= capture DNS requests to these servers and forward (comma-separated)
5758
python= path to python interpreter on the remote server
5859
r,remote= ssh hostname (and optional username) of remote sshuttle server
5960
x,exclude= exclude this subnet (can be used more than once)
@@ -67,7 +68,6 @@ def parse_ipport(s):
6768
V,version print sshuttle's version number
6869
syslog send log messages to syslog (default if you use --daemon)
6970
pidfile= pidfile name (only if using --daemon) [./sshuttle.pid]
70-
dns-hosts= (internal use only)
7171
server (internal use only)
7272
firewall (internal use only)
7373
hostwatch (internal use only)
@@ -113,6 +113,7 @@ def parse_ipport(s):
113113
remotename = opt.remote
114114
if remotename == '' or remotename == '-':
115115
remotename = None
116+
nslist = re.split(r'[\s,]+', opt.dns_hosts.strip()) if opt.dns_hosts else []
116117
if opt.seed_hosts and not opt.auto_hosts:
117118
o.fatal('--seed-hosts only works if you also use -H')
118119
if opt.seed_hosts:
@@ -127,6 +128,7 @@ def parse_ipport(s):
127128
opt.python,
128129
opt.latency_control,
129130
opt.dns,
131+
nslist,
130132
sh,
131133
opt.auto_nets,
132134
parse_subnets(includes),

0 commit comments

Comments
 (0)