LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-11-2016, 02:50 PM   #1
di11rod
Member
 
Registered: Jan 2004
Location: Austin, TEXAS
Distribution: CentOS 6.5
Posts: 211

Rep: Reputation: 32
need to stop /etc/resolv.conf from changing


I'm running Arch linux on a beaglebone black as an embedded iOT device. Spontaneously, a process changes /etc/resolv.conf to have nameserver point at 127.0.0.1. I do not want that to happen again under any circumstances.

I've tried to set up a cron job that will overwrite that file with a correct backup pointing at the valid nameserver, but arch linux cron isn't in the format I am familiar with and I can't get that to work.

Code:
root@beaglebone:~# more /etc/crontab
# /etc/crontab: system-wide crontab

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user	command

*/3 * * * * 'cp /etc/backupresolv.conf /etc/resolv.conf'

Any ideas on welding this file down so it can't be modified? Any ideas on getting cron to work? All creative solutions appreciated!

--di11rod
 
Old 04-11-2016, 02:56 PM   #2
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
I think the first thing you should do is figure out what process is doing this and fix the process.
Crontab is just a band-aid.
 
Old 04-11-2016, 03:12 PM   #3
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 7,231

Rep: Reputation: Disabled
You can "weld it down" by setting the immutable flag, but this is dirty solution. Do what lazydog said.
 
Old 04-11-2016, 09:53 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 20,186

Rep: Reputation: 3757Reputation: 3757Reputation: 3757Reputation: 3757Reputation: 3757Reputation: 3757Reputation: 3757Reputation: 3757Reputation: 3757Reputation: 3757Reputation: 3757
Given that it is arch, the arch wiki is the place to start - maybe Resolv.conf might be the go.
 
Old 04-12-2016, 06:19 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,282

Rep: Reputation: 3458Reputation: 3458Reputation: 3458Reputation: 3458Reputation: 3458Reputation: 3458Reputation: 3458Reputation: 3458Reputation: 3458Reputation: 3458Reputation: 3458
Maybe a router is offering dhcp and dns?

But the wiki page offered above has it.
 
Old 04-12-2016, 07:22 PM   #6
mr.d.poston
LQ Newbie
 
Registered: Apr 2016
Posts: 4

Rep: Reputation: Disabled
Are you using dhcp to setup your IP address?

I've used arch in the past, but on a desktop. I setup my arch box to use a static IP address and I added my nameservers to /etc/resolv.conf. With the static IP method the /etc/resolv.conf file always is the same. In fact, in all my linux installations, I always use a static IP address and my nameservers in /etc/resolv.conf file doesn't change.

If you try or had tried the static IP method and it still changes your /etc/resolv.conf file, then use the immutable flag as Emerson suggested

chattr +i /etc/resolv.conf

Last edited by mr.d.poston; 04-12-2016 at 07:27 PM.
 
Old 04-12-2016, 07:51 PM   #7
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 7,231

Rep: Reputation: Disabled
Come on, immutable flag is ugly. See man dhcpcd for instance, nohook option stops it touching resolv.conf.
 
Old 04-12-2016, 09:17 PM   #8
mr.d.poston
LQ Newbie
 
Registered: Apr 2016
Posts: 4

Rep: Reputation: Disabled
Quote:
Originally Posted by Emerson View Post
Come on, immutable flag is ugly. See man dhcpcd for instance, nohook option stops it touching resolv.conf.
It's more of a suggestion as a last resort if all other means to resolve the issue fails.
 
Old 04-13-2016, 11:53 AM   #9
lazydog
Senior Member
 
Registered: Dec 2003
Location: The Key Stone State
Distribution: CentOS Sabayon and now Gentoo
Posts: 1,249
Blog Entries: 3

Rep: Reputation: 194Reputation: 194
I'm not sure the nohook is the best option because you will want dhcpd updating resolv.conf on laptops and other devices.

OP: If you are using an ip address in your dhcp range then you need to exclude that ip address from the range and make it static on the server. Doing this will stop dhcp from overwriting your resolv.conf.
 
Old 04-13-2016, 04:14 PM   #10
Emerson
LQ Sage
 
Registered: Nov 2004
Location: Saint Amant, Acadiana
Distribution: Gentoo ~arch
Posts: 7,231

Rep: Reputation: Disabled
You are confusing dhcpd with dhcpcd ?
 
  


Reply

Tags
arch, cron, dns, file locking


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
How do I stop stuff from overwriting /etc/resolv.conf? Red Squirrel Linux - Networking 8 07-01-2014 11:57 PM
resolv.conf keeps changing solution cuco76 Linux - Networking 4 10-02-2006 05:57 PM
DHCP client overwriting resolv.conf... how to stop it? gauge73 Linux - Networking 6 05-04-2005 12:51 PM
resolv.conf changing everytime network restart cuco76 Linux - Networking 4 11-29-2004 09:19 PM
/etc/resolv.conf keeps changing silvercastle Linux - Networking 2 04-15-2004 11:51 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:19 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
Open Source Consulting | Domain Registration