LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 12-03-2008, 04:14 PM   #1
zeeple
Member
 
Registered: Sep 2006
Distribution: Fedora 8, RHEL 5
Posts: 62

Rep: Reputation: 15
Help with netconfig command


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:

$ netconfig --bootproto=none --ip=10.5.7.6 --netmask=255.0.0.0 --gateway=10.0.0.1 --nameserver=10.0.0.1

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.
 
Old 12-03-2008, 05:21 PM   #2
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 64
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

Might work.

-Chad
 
Old 12-03-2008, 06:12 PM   #3
zeeple
Member
 
Registered: Sep 2006
Distribution: Fedora 8, RHEL 5
Posts: 62

Original Poster
Rep: Reputation: 15
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:

apache ALL= NOPASSWD: /usr/sbin/reboot, /sbin/reboot, /usr/sbin/netconfig, /bin
/rm, /sbin/service, /bin/echo

the line in my php file (when I attempted to include the echo) is as such:

$cmdToExec = "sudo netconfig --bootproto=none --ip=" . $ipAddress . " --netmask=" . $netmask . " --gateway=" . $gateway . " --nameserver=" . $nameserver;

$output = `$cmdToExec; sudo service network restart; sudo echo "nameserver $nameserver" > /etc/resolv.conf`;

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.
 
Old 12-03-2008, 06:57 PM   #4
zeeple
Member
 
Registered: Sep 2006
Distribution: Fedora 8, RHEL 5
Posts: 62

Original Poster
Rep: Reputation: 15
Another interesting observation:

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

Correct? After all, that's the purpose of sudo.
 
Old 12-04-2008, 02:26 PM   #5
zeeple
Member
 
Registered: Sep 2006
Distribution: Fedora 8, RHEL 5
Posts: 62

Original Poster
Rep: Reputation: 15
This is resolved, actually. The solution was to change:

sudo echo 'text' > /etc/resolv.conf

to:

echo 'text' | sudo tee /etc/resolv.conf
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
No netconfig dewy_2006 Linux - Newbie 2 06-12-2008 05:25 PM
"netconfig: command not found" in minimal install of Slack 12 sandugo Slackware 1 07-29-2007 10:11 AM
'netconfig' won't l0rddarkf0rce Slackware 3 07-28-2005 06:30 PM
Netconfig virii1 Linux - Networking 3 03-28-2005 01:56 PM
netconfig knoxville Linux - Newbie 6 11-30-2003 02:56 PM


All times are GMT -5. The time now is 04:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration