LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   need to stop /etc/resolv.conf from changing (https://www.linuxquestions.org/questions/linux-software-2/need-to-stop-etc-resolv-conf-from-changing-4175577203/)

di11rod 04-11-2016 01:50 PM

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

lazydog 04-11-2016 01:56 PM

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.

Emerson 04-11-2016 02:12 PM

You can "weld it down" by setting the immutable flag, but this is dirty solution. Do what lazydog said.

syg00 04-11-2016 08:53 PM

Given that it is arch, the arch wiki is the place to start - maybe Resolv.conf might be the go.

jefro 04-12-2016 05:19 PM

Maybe a router is offering dhcp and dns?

But the wiki page offered above has it.

mr.d.poston 04-12-2016 06:22 PM

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

Emerson 04-12-2016 06:51 PM

Come on, immutable flag is ugly. See man dhcpcd for instance, nohook option stops it touching resolv.conf.

mr.d.poston 04-12-2016 08:17 PM

Quote:

Originally Posted by Emerson (Post 5530162)
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.

lazydog 04-13-2016 10:53 AM

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.

Emerson 04-13-2016 03:14 PM

You are confusing dhcpd with dhcpcd ?


All times are GMT -5. The time now is 08:38 PM.