At my workplace the DHCP server sometimes goes down.
So I made a script that sets up the IP address and netmask using ifconfig and the default gateway using route. But I'm yet to find the command to assign the DNS server temporarily.
Is there a command I can use to set the DNS server address for eth0 temporarily? So if the DHCP server comes back, I can reconnect using DHCP without hard coding it into a configuration file.
2 Answers
Write it into /etc/resolv.conf:
echo "nameserver 1.2.3.4" | sudo tee /etc/resolv.confUpon successful DHCP connection, it should be overwritten back to the "correct" DNS server.
If you have a Desktop you could just fill in the extra DNS (8.8.8.8.) where i did here. It uses the ones via DHCP first but if those are not reachable it uses 8.8.8.8. You can also switch DHCP on and off. If you switch it off it automatically uses the filled in user settings. Turn the connection off and on again with the switch/button to apply the new network settings. It is all in the GUI.