Score:1

is there a way on Linux to set DNS servers using a cmd line?

gs flag

I use a script that creates multiple network interfaces with IP adresses. An example of commands used by the script:

ip addr flush eth0 
ip addr flush eth1

ip addr add 192.168.1.10 dev eth0 route add default gw 192.168.1.1 eth0
ip addr add 10.1.1.10 dev eth1 route add default gw 10.1.1.1 eth1

I didn't find an option to set the DNS server. The file at /etc/resolv.conf has a DNS entry but it's not working. And /etc/network/interfaces is empty (just loopback information).

My question is : is there a way to set the DNS servers using a cmd line that I can include in the script? Or do I have to manually add all the information to /etc/network/interfaces?

Marco avatar
in flag
different linux distros use different methods of adding DNS. There is NetworkManager as a GUI. And there is `ifupdown`, `systemd-networkd`, `resolvconf`. Additionally there is `netplan` handling such thing. The dhcp-client can also do this, but there is more than one dhcp-client available (isc-dhcp-client, dnsmasq). You see, your info is not enough to help you.
Nikita Kipriyanov avatar
za flag
`resolf.conf` doesn't work? Strange. What `grep hosts /etc/nsswitch.conf` says?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.