Search code examples
powershelldnsdig

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

Solution

  • 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"