Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need add a line to a configuration file (e.g. /etc/resolv.conf). If I use

sudo echo "nameserver 192.168.1.6" >> /etc/resolv.conf

I get error message Access denied. Problem is that bash write to file from my account, not from roots account.

Is there any way how to get it works?

I know there is a "solution" to write my commands into file and run them as batch but it is strongly uncomfortable :-(

share|improve this question
    
<3 'sudo echo'. "Won't you take me to, a funky town?" :) – crb Jul 11 '09 at 13:37
up vote 18 down vote accepted
sudo /bin/sh -c 'echo "nameserver 192.168.1.6" >> /etc/resolv.conf'
share|improve this answer

echo "nameserver 192.168.1.6" | sudo tee -a /etc/resolv.conf

share|improve this answer
    
Very interesting solution to me. Thanks. – izidor Jul 13 '09 at 16:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.