WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: udhcpc overwriting /etc/resolv.conf [SOLVED]  (Read 19099 times)

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
udhcpc overwriting /etc/resolv.conf [SOLVED]
« on: August 01, 2010, 04:50:12 PM »
udhcpc is overwriting /etc/resolv.conf each time it is called, regardless of file being set to read-only:
Code: [Select]
tc@box:~$ sudo chmod -v a-w /etc/resolv.conf
mode of '/etc/resolv.conf' changed to 0444 (r--r--r--)
tc@box:~$ ls -l /etc/resolv.conf
-r--r--r--    1 root     root           36 Aug  1 14:36 /etc/resolv.conf
tc@box:~$ sudo echo 'nameserver 8.8.8.8' > /etc/resolv.conf
sh: can't create /etc/resolv.conf: Permission denied
I didn't find an explicit option for udhcpc not to request DNS server address or not to "update" /etc/resolv.conf as found in other dhcp client.
How comes an app can overwrite a file chmod'ed to a-w, when even root gets 'permission denied' to write to it?
What are the possible implications on security here?
« Last Edit: December 05, 2010, 05:07:43 PM by tinypoodle »
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11049
Re: udhcpc overwriting /etc/resolv.conf
« Reply #1 on: August 01, 2010, 04:54:54 PM »
Common mistake with the echo, root has all the power ;)

tc@box:~$ sudo echo hello > file # the redirection happens in the shell, which is run by user tc
The only barriers that can stop you are the ones you create yourself.

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: udhcpc overwriting /etc/resolv.conf [SOLVED]
« Reply #2 on: August 01, 2010, 05:27:48 PM »
Ah, thank you very much, learned something!  ;D

Of course the core of the issue remains, how to prevent udhcpc from overwriting /etc/resolv.conf
« Last Edit: December 05, 2010, 05:08:22 PM by tinypoodle »
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline ixbrian

  • Retired Admins
  • Sr. Member
  • *****
  • Posts: 436
Re: udhcpc overwriting /etc/resolv.conf
« Reply #3 on: August 02, 2010, 10:52:46 PM »
Ah, thank you very much, learned something!  ;D

Of course the core of the issue remains, how to prevent udhcpc from overwriting /etc/resolv.conf

I haven't tried it, but maybe you could try changing /sbin/udhcpc in to a shell script wrapper that would recreate /etc/resolv.conf with your custom settings each time after it is called.  Something like this:

Code: [Select]
busybox udhcpc $@
cat > /etc/resolv.conf << EOF
nameserver 0.0.0.0
nameserver 0.0.0.0
EOF

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: udhcpc overwriting /etc/resolv.conf [SOLVED]
« Reply #4 on: August 03, 2010, 08:07:14 AM »
Thanks for the suggestion, I had been thinking about something along the lines of:
Code: [Select]
sudo mv -f /etc/resolv.conf~ /etc/resolv.conf
« Last Edit: December 05, 2010, 05:09:03 PM by tinypoodle »
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)

Offline tinypoodle

  • Hero Member
  • *****
  • Posts: 3857
Re: udhcpc overwriting /etc/resolv.conf [SOLVED]
« Reply #5 on: December 05, 2010, 05:14:31 PM »
Proper solution in following thread:

http://forum.tinycorelinux.net/index.php?topic=8019
"Software gets slower faster than hardware gets faster." Niklaus Wirth - A Plea for Lean Software (1995)