# DHCP problems on fresh install



## r619 (Jun 12, 2013)

Decided to play with  FreeBSD out of VirtualBox, making it my primary system. So I got some network specific problems just after a fresh install.

First symptom: I got a 30 s long delay on system initialization with such message "waiting 30s for the default route interface ......." which obviously means that it could not detect startup of my default router interface for some reason.

Second symptom: domains do not resolve, pings return "sendto: no route to host". Thus, I googled this thread.

So, maybe I got the same problem? To check, I did comment 
	
	



```
ifconfig_msk0="DHCP"
```
 string, then used `ifconfig msk0 up && dhclient msk0`.

Output:


```
DHCPDISCOVER on msk0 to 255.255.255.255 port 67 interval 8
DHCPOFFER from 109.*
DHCPREQUEST on msk0 to 255.255.255.255 port 67
DHCPACK from 109.*
bound to 172.* -- renewal in 450 seconds
```

It says everything is fine, but: neither `ping ya.ru` nor `ping 213.180.193.3` worked.

I was about to think this is some kind of driver problem, but `ping 109.*` and `ping 172.*` actually do work, and DHCP offered me something and acknowledged something.

I also tried to push `defaultroute="109.*"` in rc.conf and `reboot` then - same result.


----------



## wblock@ (Jun 12, 2013)

Use SYNCDHCP instead:

```
ifconfig_msk0="SYNCDHCP"
```

That will make the startup scripts wait for your DHCP server to answer.

Most DHCP servers set nameservers in /etc/resolv.conf, but it's not required. Don't set a default route, DHCP does that.

So remove the extra settings from rc.conf, add SYNCDHCP, and reboot.  Watch to see if it gets a DHCP lease, then look at the contents of /etc/resolv.conf.  If that does not work, the next thing to do will be to show your full /etc/rc.conf.


----------



## r619 (Jun 13, 2013)

wblock@ said:
			
		

> Use SYNCDHCP instead



No success.

Everything networking-related in boot log:

```
# dmesg -a
[......]
Setting hostname: pixntre.
msk0: link state changed to DOWN
Starting dhclient.
msk0: no link ....msk0: link state changed to UP
 got link
DHCPDISCOVER on msk0 to 255.255.255.255 port 67 interval 3
DHCPOFFER from 109.*
DHCPREQUEST on msk0 to 255.255.255.255 port 67
DHCPACK from 109.*
bound to 172.* -- renewal in 450 seconds.
Starting Network: lo0 msk0.
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
	options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
	inet6 ::1 prefixlen 128 
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0xa
	inet 127.0.0.1 netmask 0xff000000 
	nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
msk0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=c011b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,TSO4,VLAN_HWTSO,LINKSTATE>
	ether 00:1b:*
	inet 172.* netmask 0xffffffff broadcast 172.*
	nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
	media: Ethernet autoselect (100baseTX <full-duplex>)
	status: active
[......]
dhclient already running? (pid=342)
add net ::ffff:0.0.0.0: gateway ::1
add net ::0.0.0.0: gateway ::1
add net fe80::: gateway ::1
add net ff02::: gateway ::1
Generating host.conf.
Waiting 30s for the default route interface: .............................
```

host.conf:

```
# Auto-generated from nsswitch.conf
hosts
dns
```

rc.conf:

```
hostname="pixntre"
ifconfig_msk0="SYNCDHCP"
powerd_enable="YES"
dumpdev="NO"
```

resolv.conf:

```
# Generated by resolvconf
search ISP-domain-name.ru
nameserver 192.168.12.1
nameserver 192.168.13.1
```


----------



## SirDice (Jun 13, 2013)

I've seen routers supply a default gateway that's outside of the subnet the IP address is in. FreeBSD doesn't accept that. Both Windows and Linux don't seem to have a problem with it.

I think I solved it by creating a /etc/dhclient-enter-hooks script and setting the default gateway this way: `route add default -iface msk0`. But I can't find my script any more. See dhclient-script(8) for some details about the things you can hook.


----------



## r619 (Jun 13, 2013)

SirDice said:
			
		

> I've seen routers supply a default gateway that's outside of the subnet the IP address is in. FreeBSD doesn't accept that. Both Windows and Linux don't seem to have a problem with it.
> 
> I think I solved it by creating a /etc/dhclient-enter-hooks script and setting the default gateway this way: `route add default -iface msk0`. But I can't find my script any more. See dhclient-script(8) for some details about the things you can hook.



Hmm.

I did this:

```
if [ ."$reason" == .PREINIT ]; then
    route add default -iface msk0
fi
```
And it does not work neither with 
	
	



```
ifconfig_msk0="DHCP"
```
 nor with 
	
	



```
ifconfig_msk0="SYNCDHCP"
```
 string in /etc/rc.conf.
With 
	
	



```
ifconfig_msk0="SYNCDHCP"
```
, output of `ping 213.180.193.3` was empty (except for summary report with 100% packet loss). Consequently, he knows route, but it's not working.

Then I commented `if`\`fi` condition in /etc/dhclient-enter-hooks with no success.

I decided to `rm /etc/dhclient-enter-hooks`, and do `route add default -iface msk0` manually after init. It worked, but only with non-commented 
	
	



```
ifconfig_msk0="SYNCDHCP"
```
 (I also have had to wait 30 seconds or `^C` defaultroute script).

Quite non-trivial for newbie. And the handbook lacks HOWTO covering that problem...

Off-topic: I'm not sure that I should place short config strings in CODE tag, as it's multiline tag. I used CMD for such strings, but fonz replaced that with CODE in OP-post. It's simply less convenient to read.


----------



## fonz (Jun 13, 2013)

r619 said:
			
		

> Off-topic: I'm not sure that I should place short config strings in CODE tag, as it's multiline tag. I used CMD for such strings, but fonz replaced that with CODE in OP-post. It's simply less convenient to read.


I agree that using [CODE] isn't always convenient for short pieces. It's still correct, but as an alternative you could "put it in quotes" or use [FILE]. Both would be okay. [CMD] on the other hand is more intended for commands typed at a (shell) prompt.


----------



## r619 (Jun 14, 2013)

Solved it by editing /etc/rc.d/defaultroute:

```
# Wait for a default route
route add default -iface msk0
waited=0
```

This is workaround though. I hate them.


----------

