dig (DNS Lookup) specify DNS server on Windows
Asked Answered
B

3

27

In Linux, I would use dig to specify a DNS server of 127.0.0.1 with the following command:

dig google.com @127.0.0.1

I installed Bind tools for windows (choco install bind-toolsonly). How can I run that same command? I get the following error:

PS C:\Users\jhilden> dig google.com @127.0.0.1
At line:1 char:21
+ dig google.com @127.0.0.1
+                     ~
Missing property name after reference operator.
At line:1 char:16
+ dig google.com @127.0.0.1
+                ~~~~
The splatting operator '@' cannot be used to reference variables in an
expression. '@127' can be used only as an argument to a command. To
reference variables in an expression use '$127'.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingPropertyName
Buckram answered 13/4, 2016 at 19:35 Comment(0)
D
17

Like the error message says: the @ has a special meaning in PowerShell. Escape the character

dig google.com `@127.0.0.1

or put the argument in quotes

dig google.com "@127.0.0.1"
Dikdik answered 13/4, 2016 at 20:9 Comment(0)
T
73

I know this answer doesn't use Bind tools, as you inferred in your question. That said, however, PowerShell comes with the Resolve-DnsName to perform this task. I believe that the following command will do what you are after

Resolve-DnsName -Name google.com -Server 127.0.0.1
Theophylline answered 5/6, 2017 at 15:40 Comment(5)
@r590 Upon investigation, it appears that Resolve-DnsName was added in PowerShell 3.0, so is only available on Windows 8+ / Windows Server 2012+_Theophylline
note that WMF 5.1 (which includes PowerShell 5.1) has been back-ported to Windows 7 SP1 - so anything W7SP1, Server 2008R2SP1 or later should be able to run a full set of PowerShell commands.Tabu
This does not support a port. Any other possibilities?Lefler
Reference docAdalbertoadalheid
He says 'same command'. This isn't the same command. You may as well have mentioned nslookup, too. dig has many more options and gives much more information (stats) on the query. Such a time/ms to receive answer. digwebinterface.com/…Farquhar
D
17

Like the error message says: the @ has a special meaning in PowerShell. Escape the character

dig google.com `@127.0.0.1

or put the argument in quotes

dig google.com "@127.0.0.1"
Dikdik answered 13/4, 2016 at 20:9 Comment(0)
S
-4

I think your parameters are backwards. Server should come first.

Subtotal answered 13/4, 2016 at 20:4 Comment(1)
Nope. Argument order doen't matter here.Dikdik

© 2022 - 2024 — McMap. All rights reserved.