8

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 :-(

1
  • <3 'sudo echo'. "Won't you take me to, a funky town?" :)
    – crb
    Jul 11, 2009 at 13:37

2 Answers 2

20
sudo /bin/sh -c 'echo "nameserver 192.168.1.6" >> /etc/resolv.conf'
13

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

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .