I have this app that is supposed to change the DNS servers of a Linux machine programatically but I can't seem to find a proper way to do it. Some versions are good with updating resolv.conf
, others only work if you play with netplan
etc. Is there a proper way of doing this thing that works on all instances?
So far I found these options:
resolv.com
- works on some instances but it is ineffective on others
netplan
- only used and present on newer versions of ubuntu (and possibly others) so I can't rely on it being effective either
changing dns-nameservers
inside /etc/network/interfaces
- I have to restart the network after that and I'm still not sure it's a solution that works
Which route do you guys suggest I should go or is there something that I'm missing? How does one programatically change the DNS servers of a box?
How to resolve the requested task is highly distribution dependent. Therefore there is no standard way of doing it properly which matches different distributions.
In case of
Debian
andUbuntu
it should be save to use/etc/network/interfaces
.In case of
Red Hat Enterprise Linux
,CentOs
,Fedora
related files are found in/etc/sysconfig/network-scripts
.