You can specify a DNS server in nslookup in two modes: interactive and non-interactive.
Interactive mode
In interactive mode, you can specify a DNS server using the server
or lserver
commands. The server
command sets the default DNS server for the current nslookup session, while the lserver
command sets the default DNS server for the current nslookup session, but also uses the local DNS resolver to resolve the IP address of the new DNS server.
To specify a DNS server using the server
command, type the following command:
server <DNS server address>
For example, to set the default DNS server to 8.8.8.8, you would type the following command:
server 8.8.8.8
To specify a DNS server using the lserver
command, type the following command:
lserver <DNS server address>
For example, to set the default DNS server to 8.8.8.8, but also use the local DNS resolver to resolve the IP address of the new DNS server, you would type the following command:
lserver 8.8.8.8
Non-interactive mode
In non-interactive mode, you can specify a DNS server by appending the DNS server address to the end of the nslookup command.
To specify a DNS server in non-interactive mode, type the following command:
nslookup host <DNS server address>
For example, to look up the IP address of the host google.com
using the DNS server 8.8.8.8, you would type the following command:
nslookup google.com 8.8.8.8
Specifying the port number
DNS servers typically use port 53. However, some DNS servers may listen on a different port. In this case, you can specify the port number using the -port
option.
To specify the port number, type the following command:
nslookup -port <port number> host <DNS server address>
For example, to look up the IP address of the host google.com
using the DNS server 8.8.8.8 on port 42, you would type the following command:
nslookup -port 42 google.com 8.8.8.8