Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
I need to know how to automatically set the dns name server for the nic card using command line or a script. I have the nic card loading fine using the /etc/sysconfig/network-scripts/ifcfg-eht0 file. I have routes loading fine using the /etc/rc.d/rc.local file. I know the dns ip goes in the /etc/resolv.conf file. What I want is to not have to manually put that into the file. Is there a way like the ip address and routes to automatically have it added?
Add a line to the /etc/sysconfig/network file that has:
DNSSRVRS 192.168.0.1 192.168.100.1
Substitute your nameserver ip(s) as appropriate. The /etc/sysconfig/network-scripts/ifup script reads this file and creates /etc/resolv.conf. You may want to check that script and make sure my spelling is correct.
That didn't do anything. I went to /etc/sysconfig/network...added DNSSRVRS 192.168.0.33, saved it and rebooted but it wasn't in the resolv.conf file. And I couldn't ping anything by name.
Added that SEARCH degree.com to the network file and it still did not do anything. If I manually add the nameserver and search info to the resolv.conf file everything works perfectly. But adding those lines to the network file make no changes to resolv.conf.
I think that depends on which distribution you use. You could easily check the ifup script to see if it does anything with the DNSSRVRS variable. You could always add it to the ifup script yourself.
Something like this might work:
if [ "$DNSSRVRS" != "" ]
then
mv /etc/resolv.conf /etc/resolv.conf.sv
for dnsserver in $DNSSRVRS
do
echo nameserver $dnsserver >> /etc/resolv.conf
done
echo search $SEARCH >> /etc/resolv.conf
fi
You'd have to set the SEARCH variable to the right value. I also haven't tested it so you might need to check it to make sure it all works right.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.