# How to disable resolv.conf re-write?



## jonfr (Sep 29, 2014)

If I run IPv6 on automatic configure the resolv.conf gets rewritten by Generated by resolvconf. I guess this also applies to IPv4 DHCP settings. How do I disable the re-write of resolv.conf?

Thanks for the help.


----------



## SirDice (Sep 30, 2014)

IPv6 SLAAC doesn't change the DNS settings as it doesn't receive any. For IPv4 you can add a bit of code to /etc/dhclient-enter-hooks to prevent /etc/resolv.conf from being overwritten:

```
add_new_resolv_conf() {
        return 0
}
```


----------



## jonfr (Sep 30, 2014)

That is what happened. I got an IPv6 DNS server in resolv.conf, this creating all types of problems in the process. I did add this commands to rc.conf since I was testing my new router IPv6 abilities.


```
ifconfig_bge0_ipv6="inet6 accept_rtadv"
rtsold_enable="YES"
```

This is accordance with the FreeBSD guide.

Thanks for the help.


----------



## kpa (Sep 30, 2014)

SirDice said:
			
		

> IPv6 SLAAC doesn't change the DNS settings as it doesn't receive any.



I'm not sure if you're correct here. It is possible to specify DNS forwarders in rtadvd.conf(5) and at least my laptop that is OS X 10.10 (Yosemite BETA) seems to be picking them up.


----------



## SirDice (Sep 30, 2014)

kpa said:
			
		

> I'm not sure if you're correct here. It is possible to specify DNS forwarders in rtadvd.conf(5) and at least my laptop that is OS X 10.10 (Yosemite BETA) seems to be picking them up.


I've tried this on numerous occasions but neither my FreeBSD machines nor my Windows machines picked them up.


----------



## jonfr (Sep 30, 2014)

I just have to hope that the rules that I added are good enough to prevent IPv6 address assignment overwriting my resolv.conf file.


----------



## jonfr (Sep 30, 2014)

It is important that this re-write of my resolv.conf does not happen. Since I am going to be moving from tunnel IPv6 to native IPv6 soon (I hope). Since Denmark has some support of it according to this website here.

Thanks for the help.


----------



## jonfr (Oct 7, 2014)

That did not work. I got today an Linksys router that is able to connect to tunnelbroker website tunnel without issues. When that happens the resolv.conf is re-written with just this DNS servers.


```
# Generated by resolvconf
search bbsyd.net
nameserver 2001:470:dd6c:0:b675:eff:fef9:fe9b
```

There is no change in IPv4 functions that I can tell. I do want to keep my IPv4 DNS servers in place since I have to use them too. How do I stop this from happening when it comes to IPv6?

Thanks for the help.


----------



## wblock@ (Oct 7, 2014)

You can edit dhclient.conf(5) to override or add DNS servers or other settings.

However, in the past, it was more effective for me to set /etc/resolv.conf as desired and then just set the system immutable flag on it: `# chflags schg /etc/resolv.conf`.  Of course that means it will not change, even when the DHCP data changes, but as long as you are aware of that, it works.


----------



## jonfr (Oct 7, 2014)

This is the dhcp server for my LAN. So it has an static IPv4 address. It also does few other things that need a static LAN IPv4 address. I rather not make the file in so way that is read-only. Since that does not solve this issue.


----------



## wblock@ (Oct 8, 2014)

I'm confused.  Your DHCP server gets a static address from DHCP itself?  Even so, that would not change this.  One way to keep /etc/resolv.conf from being overwritten by dhclient(8) is to set the schg flag on it.  It does not change anything except the DNS settings from that file.


----------



## jonfr (Oct 9, 2014)

No. That is now how my network is set-up. The FreeBSD computer is the dhcp server for my IPv4 network (LAN).

The networks part of my rc.conf.


```
[...]

ifconfig_bge0=" inet 192.168.1.2 netmask 255.255.255.0"
defaultrouter="192.168.1.1"

[...]

ipv6_network_interfaces="bge0"
ipv6_activate_all_interfaces="YES"
ifconfig_bge0_ipv6="inet6 accept_rtadv"
rtsold_enable="YES"

[...]
```

I hope this explains my set-up a bit better. Now all IPv6 connections are handled by my Linksys WRT 1900AC WAN router.

Thanks for the help.


----------



## SirDice (Oct 9, 2014)

I haven't played with it myself but have a look at resolvconf(8). It could be useful.


----------



## pkubaj (Oct 9, 2014)

I've disabled mine with just `chflags schg /etc/resolv.conf`.


----------



## ColorfulOne (Mar 23, 2020)

My  /etc/resolv.conf  was overwritten with  IPv4 . I noticed in  /etc/rc.conf  that I only had lines from the installation for the wireless interface, so I simply added the line: 
	
	



```
ifconfig_rl0="DHCP"
```
 Have not had an issue since.


----------



## mickey (Mar 23, 2020)

It should be possible to keep resolvconf(8) from writing to /etc/resolv.conf entirely:

```
resolvconf assumes it has a job to do.  In some situations resolvconf
     needs to act as a deterrent to writing to /etc/resolv.conf.  Where this
     file cannot be made immutable or you just need to toggle this behaviour,
     resolvconf can be disabled by adding resolvconf=NO to resolvconf.conf(5).
```


----------



## Lamia (Mar 23, 2020)

mickey said:


> It should be possible to keep resolvconf(8) from writing to /etc/resolv.conf entirely:
> 
> ```
> resolvconf assumes it has a job to do.  In some situations resolvconf
> ...


Resolvconf.conf does not fill it with its contents to make matter worse. A number of people have used cron to regularly copy resolv.conf to resolvconf.conf.


----------



## Lamia (Mar 23, 2020)

Lamia said:


> Resolvconf.conf does not fill it with its contents to make matter worse. A number of people have used cron to regularly copy resolv.conf to resolvconf.conf.


I meant copy resolvconf.conf to resolv.conf.


----------



## mickey (Mar 23, 2020)

Lamia said:


> I meant copy resolvconf.conf to resolv.conf.


You should never do that as both files serve completely different purposes. The file /etc/resolv.conf configures how your system resolves names into addresses and vice versa, i.e. what DNS server it uses for that purpose. The file /etc/resolvconf.conf however configures how the resolvconf(8) program, that accumulates information from various sources (i.e. DHCP) and then writes that information into /etc/resolv.conf operates.

Normally you don't need an /etc/resolvconf.conf file, as resolvconf(8) should do the right thing by default, therefore the file doesn't exist by default. If however your goal is to keep resolvconf(8) from ever touching your /etc/resolv.conf file, then you need to create the file /etc/resolvconf.conf with the following content:

```
resolvconf=NO
```


----------



## Zvoni (Mar 24, 2020)

Or if you need special settings you add a supersede or append in /etc/dhclient.conf.
Happened to me.
FreeBSD-PC with 1 NIC (DHCP) connected to my Laptop with LAN-Wire (Address-Range 192.168.3.X), my Laptop connected to Wifi-Router on Address-Range 192.168.2.Y, on my Laptop BIND and DHCP-Server running, serving the 192.168.3.X-Subnet incl. NAT-Rules.
I had to enter the supersede/append to get my FreeBSD-PC to accept an additional DNS


----------



## Jose (Jul 27, 2022)

mickey said:


> You should never do that as both files serve completely different purposes. The file /etc/resolv.conf configures how your system resolves names into addresses and vice versa, i.e. what DNS server it uses for that purpose. The file /etc/resolvconf.conf however configures how the resolvconf(8) program, that accumulates information from various sources (i.e. DHCP) and then writes that information into /etc/resolv.conf operates.
> 
> Normally you don't need an /etc/resolvconf.conf file, as resolvconf(8) should do the right thing by default, therefore the file doesn't exist by default. If however your goal is to keep resolvconf(8) from ever touching your /etc/resolv.conf file, then you need to create the file /etc/resolvconf.conf with the following content:
> 
> ...


The Handbook is pretty lacking in this area. It does not mention resolvconf(8) at all, and leaves the distinct impression that /etc/resolv.conf is rewritten by dhclient-script(8).








						Chapter 31. Network Servers
					

This chapter covers some of the more frequently used network services on UNIX systems




					docs.freebsd.org


----------



## Igor2022 (Jul 28, 2022)

If the goal is to prevent modification of /etc/resolv.conf by `dhclient`, then a simple /etc/dhclient.conf would do the trick: make DHCP client request only essential parameters, but don't request domain-name-servers option.

/etc/dhclient.conf:

```
interface "em0"
{
  request       subnet-mask, broadcast-address, routers;
}
```


----------

