Filtering DNS traffic based on hostnames inside VPN TUN interface in android kotlin

434 Views Asked by At

I am trying to implement custom DNS resolver inside my Android(kotlin) application through the VPN service.

I am basically intercepting the packets through TUN interface and resolving the queries something similar to this implementation in Virtual Hosts (https://github.com/x-falcon/Virtual-Hosts).

  1. But, I only need certain domain names alone to get resolved inside my application and rest other DNS traffic with device network. 

  2. Currently all DNS traffic is routed to TUN Interface and am resolving the ones that I needed. This has some issues where the DNS queries that I don't resolve are not passing through and am not sure how to handle them.

  3. So figuring out if there is way to split tunnel the DNS traffic to the TUN based on host names?

  4. I could see the iOS is actually doing the same with below piece of code

let settings=NEPacketTunnelNetworkSettings(tunnelRemoteAddress: "x.x.x.x")
... 
let dnsSettings = NEDNSSettings.init(servers: ["x.x.x.x"])
dnsSettings.matchDomains = ["apple.com"]
dnsSettings.matchDomainsNoSearch = true
settings.dnsSettings = dnsSettings

Wondering if there is a similar way in Android or if there is any alternatives to achieve this behaviour without having a performance.

0

There are 0 best solutions below