# Edit DNS Settings



## jj05u3 (May 30, 2013)

Hello, I'm running a FreeBSD virtual machine for learning purposes. After settings it up it didn't have a proper IPv4 configuration so I edited it through sysconfig. I enabled DHCP.

What happens is I can ping public IPs but not ping by DNS; I of course need DNS enabled, particularly because I want to download the kernel source code and when trying to I'm receiving an error of name resolution (that's how I found out what happened).

I've searched for a long time now and I do get valid suggestions, like 





> You can create a file called /etc/resolv.conf.tail and add your own additional settings, but to supersede the information from dhcp you need to instruct the client to do so.
> 
> To do this you'll need to edit /etc/dhclient.conf, you can add simply:
> supersede domain-name-servers 127.0.0.1;



but I can't edit the dhclient.conf or resolver.conf files, it doesn't let me save. I've verified permissions on dhclient.conf and it starts with RW, I'm supposed to be able to edit the file since I'm the root. 

I'm pretty sure it's getting complicated for me because I'm learning, so every solution I'm pointed to I need to investigate how to get there in the first place. 

What's the best way to add a DNS server manually to my FreeBSD machine?

Kind regards,

JosuÃ©


----------



## graudeejs (May 30, 2013)

You need to become root user to edit these files. Use su(1) to do so. You will need to enter root users password.


----------



## wblock@ (May 30, 2013)

DHCP sets DNS nameservers in /etc/resolv.conf.  Note the spelling of that file, it's important.  If the DHCP server does not hand out valid DNS settings, you will have to ask the admin about that.

If DHCP is wrong and will not be fixed, one easy way to prevent DHCP from messing with /etc/resolv.conf is to put the right values in that file and then set the schg flag on it to keep anything from overwriting it.


----------



## SirDice (May 31, 2013)

wblock@ said:
			
		

> If DHCP is wrong and will not be fixed, one easy way to prevent DHCP from messing with /etc/resolv.conf is to put the right values in that file and then set the schg flag on it to keep anything from overwriting it.


A better solution is to create a /etc/dhclient-enter-hooks script:

```
add_new_resolv_conf() {
        # We don't want /etc/resolv.conf changed
        # So this is an empty function
        return 0
}
```


----------



## jj05u3 (May 31, 2013)

All right, I'll test this and come back to you after it's done. Thanks for the input.

JosuÃ©


----------



## jj05u3 (May 31, 2013)

Is this after modifying the /etc/resolv.conf or should I put the DNS settings *i*n this file? I did not understand if this is an additional step or in substitution of what @wblock@ previously suggested. Could you please clarify?


```
add_new_resolv_conf() {
        # We don't want /etc/resolv.conf changed
        # So this is an empty function
        return 0
}
```


----------



## jj05u3 (May 31, 2013)

Ok guys, I appreciate the help and will certainly keep it in mind if it happens again; I was able to resolve the DHCP problem so I'm now able to download the source code; I'll go back to this when I'm more advanced on this.

Kind regards,

JosuÃ©


----------



## SirDice (Jun 2, 2013)

jj05u3 said:
			
		

> Is this after modifying the /etc/resolv.conf or should I put the DNS settings *i*n this file? I did not understand if this is an additional step or in substitution of what @wblock@ previously suggested. Could you please clarify?
> 
> 
> ```
> ...



This bit of code prevents dhclient(8) from touching /etc/resolv.conf. So it will never overwrite anything you have put in there, regardless of the DHCP server issuing DNS addresses.


----------

