简体   繁体   中英

dig (DNS Lookup) specify DNS server on Windows

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

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

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"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM