I finally found a way to get around this myself. Apparently this happens when I do not explicitly provide a source address myself and let the system choose. I imagine Linux does some tricks to find out which interface is best to use and RDNS is one of those.
By providing a source_address as follows, everything works fine:
class http_connection(httplib.HTTPConnection):
def __init__(self, dns_server, *args, **kwargs):
httplib.HTTPConnection.__init__(self, *args, **kwargs)
self.resolv = resolver(dns_server, self.source_address)
def connect(self):
self.sock = socket.create_connection((self.resolv(self.host), self.port), self.timeout, self.source_address)
...
x = http_connection(args.dns_server, '%s:%d' % (args.host, args.port), source_address = (args.source_address, 0))