How to change nameserver in resolv.conf in Recovery Mode?
The IP-address and other details (e.g. DNS-server) are usually provided by a DHCP-server in your network if your Mac is booted to Recovery Mode.

The DNS config data is temporarily stored to resolv.conf on a RAM disk (union)-mounted to /private/var/run - a directory also containing some other files. The file /etc/resolv.conf is a link to /private/var/run/resolv.conf only! AFAIR the content of resolv.conf is not relevant for DNS resolution (performed by mDNSResponder) in macOS!

The file is non-persistent!



Usually DNS-server setup in the shell is done with sudo networksetup ... - a tool not available in the Base OS X System of the Recovery Mode.

You should still be able to change the DNS server with scutil in Terminal.app:


Open Terminal.app in the menubar > Utilities
Enter scutil --dns to get your current DNS config
Enter scutil to reach interactive mode
Enter list to get a list of all keys in the data store
If you have several interfaces (you've found several State:/Network/Service/SERVICE_ID/IPv4 entries) determine the one connected to the Internet (based on e.g. your router and its internal network IP settings) - example:

get State:/Network/Service/EB40E2FC-8248-48F2-8567-257D940A31EB/IPv4
d.show


Example output:

&lt;dictionary&gt; {
  Addresses : &lt;array&gt; {
    0 : 192.168.0.8
  }
  ConfigMethod : Manual
  SubnetMasks : &lt;array&gt; {
    0 : 255.255.255.0
  }
}


If your router has the IP-address 192.168.0.1 this should be the proper interface. If your router has e.g. the IP address 192.168.1.1 the interface found above would be the wrong one and you have to search for an interface with an IP in the range 192.168.1.2-192.168.1.254.
Enter get State:/Network/Service/EB40E2FC-8248-48F2-8567-257D940A31EB/DNS use the service ID of the interface connected to the Internet you have found previously (here EB40E2FC-8248-48F2-8567-257D940A31EB)

Entering d.show should show something like:

&lt;dictionary&gt; {
  SearchDomains : &lt;array&gt; {
    0 : some.domain
  }
  ServerAddresses : &lt;array&gt; {
    0 : 192.168.0.1
  }
}


Depending on the DHCP setup of your router the SearchDomains entry and array may be missing.
Enter d.add ServerAddresses * 8.8.8.8 9.9.9.9  - add one or more DNS-server (here Google's 8.8.8.8 and quad9's 9.9.9.9)
Enter set State:/Network/Service/EB40E2FC-8248-48F2-8567-257D940A31EB/DNS 
Enter d.show to check the modified dict entry. It should show something like:

&lt;dictionary&gt; {
  SearchDomains : &lt;array&gt; {
    0 : some.domain
  }
  ServerAddresses : &lt;array&gt; {
    0 : 8.8.8.8
    1 : 9.9.9.9
  }
}

Enter quit to leave the interactive mode of scutil and return to the shell.
Enter scutil --dns or dig to verify your new DNS config.




Tested in macOS 10.12.5 Recovery Mode only!