Redirecting requests
Sometimes you may want certain DNS requests to be sent to one server, and other requests to be sent to a different server.
For example, you may see an exchange such as:
DNS REQUEST: 21-05-26 16:21:55.965 [/0:0:0:0:0:0:0:1] Tx: 4708, q:true, #qs:1, #as:0, #ns:0, #ad:0, code:OK
Q - type: PTR - name: 69.1.168.192.in-addr.arpa
DNS RESPONSE: 21-05-26 16:21:55.971 [/0:0:0:0:0:0:0:1] Tx: 4708, q:false, #qs:0, #as:0, #ns:0, #ad:0, code:Name error
These are reverse lookups -- someone is asking DNS for the name corresponding to the given address (which is written in reverse, with in-addr.arpa at the end).
This will fail in this case if we're using an external DNS server (like Google at 8.8.8.8), as there is no way for it to know the name of your machine on your network. The DNS service therefore returns a Name error code, indicating that it doesn't know what to do with this request.
In cases like this, you may want to direct DNS requests to different servers depending on their content, or whatever condition suits you.
The first thing is to go into the project and define a new secondary connection to the other DNS server we want to use for these queries, as shown here.
Note that the Default connection checkbox is not selected -- this indicates a secondary connection, which is used only for redirecting requests.
Once that secondary connection is in place, we can create a new filter of type JavaScript request filter - DNS and configure it as shown here.
The regular expression is: .+\.1\.168\.192\.in-addr\.arpa but of course you might need to change that for your network.
For more details on regular expression, see the Regular expressions page.
Finally, we can do the redirection in the filter's code -- it's a single line of code:
context.result.connectionName = "Local DNS";
By setting the context.result.connectionName variable to the name of a connection, you are instructing Gallium Data to send this request using that connection rather than the default connection.
That's all there is to it -- now when someone issues the same request, it is redirected to the local DNS server and is successful:
DNS REQUEST: 21-05-26 16:59:43.065 [/0:0:0:0:0:0:0:1] Tx: 16457, q:true, #qs:1, #as:0, #ns:0, #ad:0, code:OK
Q - type: PTR - name: 69.1.168.192.in-addr.arpa
DNS RESPONSE: 21-05-26 16:59:44.078 [/0:0:0:0:0:0:0:1] Tx: 16457, q:false, #qs:1, #as:1, #ns:1, #ad:1, code:OK
Q - type: PTR - name: 69.1.168.192.in-addr.arpa
A - type PTR - name 69.1.168.192.in-addr.arpa pointer: My-Mac
NS - type NS - name 69.1.168.192.in-addr.arpa server name: dsldevice
AR - type A - name 69.1.168.192.in-addr.arpa address: /192.168.1.254