# DHCP correct configuration



## bmwant21 (Oct 15, 2013)

I have a FreeBSD server behind router. But after startup (I've put 
	
	



```
ifconfig_re0="DHCP"
```
 in my rc.conf) I have


```
ping: cannot resolve google.com: Host name lookup failure
```

error when trying ping google.com. I can only retrieve IP after next commands:


```
ifconfig re0 down
ifcofing re0 up 
dhclient re0
```
OUTPUT:


```
DHCPREQUEST on re0 to 255.255.255.255 port 67
DHCPACK from 192.168.19.20
bound to 192.168.19.140 -- renewal in 43200 seconds.
```
How can I fix this error and correctly configure dhcp on my machine?


----------



## SirDice (Oct 15, 2013)

Have a look at the contents of /etc/resolv.conf when you first booted and after you get it working. Also check you actually received an IP address the first time.


----------



## J65nko (Oct 15, 2013)

The issue is that by default the startup scripts do not wait until your NIC has received configuration info like the IP address, network gateway and nameserver from the DHCP server.

The fix can be found in rc.conf(5):

```
[u]synchronous_dhclient[/u]
                 (bool) Set to ``YES'' to start dhclient(8) synchronously at
                 startup.  This behavior can be overridden on a per-interface
                 basis by replacing the ``DHCP'' keyword in the
                 ifconfig_<interface> variable with ``SYNCDHCP'' or
                 ``NOSYNCDHCP''.
```

So there are two solutions:

Add the following to /etc/rc.conf

```
synchronous_dhclient='YES'
```

Or alternatively

```
ifconfig_re0="SYNCDHCP"
```


----------



## bmwant21 (Oct 15, 2013)

SirDice said:
			
		

> Have a look at the contents of /etc/resolv.conf when you first booted and after you get it working. Also check you actually received an IP address the first time.



Content of resolv.conf doesn't change:

```
#Generated by resolvconf
nameserver 192.168.19.20
```

The first time I also don't receive an IP address (if you mean 
	
	



```
ifconfig re0
```
 output after startup).


----------



## bmwant21 (Oct 15, 2013)

After adding 
	
	



```
ifconfig_re0="SYNCDHCP"
```
 I've got:

```
re0: link state changed to DOWN
Starting dhclient.
re0: no link ....re0: link state changed to UP
got link
DHCPREQUEST on re0 to 255.255.255.255 port 67
DHCPREQUEST on re0 to 255.255.255.255 port 67
DHCPREQUEST on re0 to 255.255.255.255 port 67
DHCPDISCOVER ON RE0 TO 255.255.255.255 PORT 67 INTERVAL 6
......
..
..
DHCPDISCOVER ON RE0 TO 255.255.255.255 PORT 67 INTERVAL 9
No DHCPOFFERS receiver.
Trying recorde lease 192.168.19.140
bound: renewal in 42851 seconds.
Starting Network: l0 re0.
```
But also without Internet connection or IP received


----------



## wblock@ (Oct 15, 2013)

What version of FreeBSD?  Spurious up/down changes have been fixed for some cards in later versions.


----------



## bmwant21 (Oct 15, 2013)

9.1


----------



## bmwant21 (Nov 6, 2013)

OK, I refused DHCP and enter the configuration into rc.conf manually:

```
ifconfig_re0 = "inet 192.168.19.140 netmask 255.255.255.0" # prefered IP
defaultrouter = "192.168.19.20" # my router's IP
```

but after startup I also must enter

```
ifconfig re0 down
ifconfig re0 up
```
to have an Internet connection.

What is wrong?


----------



## wblock@ (Nov 6, 2013)

As in post #6, the drivers for some of those cards, probably including that one, have been fixed in later versions.  It may require 9-STABLE to get the latest code.


----------



## bmwant21 (Nov 6, 2013)

I have updated my system to 9.2 but the problem is still there.


----------



## wblock@ (Nov 6, 2013)

These changes showed up after 9.2 was released.  It will have to be 9-STABLE built from source.


----------

