Skip to content

Commit 31f0598

Browse files
committed
Fix: Allow --to-ns and --ns-host without --dns.
If the user specifies --to-ns (tells the remote server which DNS server to use for lookups coming from sshuttle), then either --ns-host or --dns need to also be used (route DNS requests through sshuttle). A previous commit incorrectly made it so --to-ns and --ns-host couldn't be successfully used together. Attempts to fix sshuttle#641.
1 parent f376674 commit 31f0598

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

sshuttle/client.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -688,19 +688,26 @@ def main(listenip_v6, listenip_v4,
688688

689689
fw = FirewallClient(method_name, sudo_pythonpath, ttl)
690690

691-
# If --dns is used, store the IP addresses that the client
692-
# normally uses for DNS lookups in nslist. The firewall needs to
693-
# redirect packets outgoing to this server to the remote host
691+
# nslist is the list of name severs to intercept. If --dns is
692+
# used, we add all DNS servers in resolv.conf. Otherwise, the list
693+
# can be populated with the --ns-hosts option (which is already
694+
# stored in nslist). This list is used to setup the firewall so it
695+
# can redirect packets outgoing to this server to the remote host
694696
# instead.
695697
if dns:
696698
nslist += resolvconf_nameservers(True)
699+
700+
# If we are intercepting DNS requests, we tell the remote host
701+
# where it should send the DNS requests to with the --to-ns
702+
# option.
703+
if len(nslist) > 0:
697704
if to_nameserver is not None:
698705
to_nameserver = "%s@%s" % tuple(to_nameserver[1:])
699-
else:
700-
# option doesn't make sense if we aren't proxying dns
706+
else: # if we are not intercepting DNS traffic
707+
# ...and the user specified a server to send DNS traffic to.
701708
if to_nameserver and len(to_nameserver) > 0:
702-
print("WARNING: --to-ns option is ignored because --dns was not "
703-
"used.")
709+
print("WARNING: --to-ns option is ignored unless "
710+
"--dns or --ns-hosts is used.")
704711
to_nameserver = None
705712

706713
# Get family specific subnet lists. Also, the user may not specify

0 commit comments

Comments
 (0)