Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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 all. I manage a number of remotely deployed linux servers on provate networks. Command line access to these units is rare, and when I have it, is usually unreliable. Thus I have developed a series of scripts and one liner commands that I use to perform various menial, ordinary tasks. One such task that I need to occasionally perform is changing a static machine to DHCP, or the reverse, switching a DHCP box to static.
For these functions I have always used netconfig with its various flags as this is simplest but there has always been a small problem going from DHCP to static with this package. Switching to DHCP works flawlessly:
$ netconfig --bootproto=dhcp
Works like a charm. The reverse mostly works, but not completely:
The problem manifests itself in the form of resolv.conf not being updated with the nameserver provided. Usually, resolv.conf will receive the contents of resolv.conf.predhclient if it exists, regarless of what is provided via the netconfig command and this is the source of the problem. I need resolv.conf to reflect what is requested via netconfig.
Does anyone here have experience with this package? If so, could you provide some suggestions? Thanks.
My first thought is to instead use simple utilities instead of scripting a script. If you were to use ifconfig to make those parameter changes and echo out the nameserver to resolv.conf you wouldn't have to worry about netconfig or some other utility being called from a script you don't have control over. So maybe:
ifconfig --flags ; echo "nameserver 1.2.3.4" > /etc/resolv.conf
Chad, that's not a bad thought but there are a couple reasons why I rejected this solution a while ago. First, ifconfig doesn't have a flag for changing the nameservers, which is why I turned to netconfig. A utility which can ostensibly handle everything ifconfig can handle as well as the nameservers. and even if I used ifconfig, I would still have to call it from a php file. The other challenge with this solution is that I cannot seem to get 'echo' to work from my php page.
I have the apache user added to the sudoers file, and the line in the sudoers file includes the following line:
The netconfig command as well as the service restart commands fire off, but the echo will not. Any suggestions on that front? If I could get that working, my problem would be solved.
I chown'd /etc/resolv.conf to apache.apache just to see what would happen. Once I did that, the php script worked. This makes me think that the sudoers file is not properly configured. Do you see anything incorrect about the way I have this set up (above post for details)?
In short, if apache is listed in the sudoes file with /bin/echo listed an available executable, the `sudo echo ...` should be able to write to a file with these permissions:
-rw-r--r-- 1 root root 25 Dec 3 17:27 /etc/resolv.conf
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.