# FreeBSD 8.0 - slow to bring up network?



## seanthingee (Dec 8, 2009)

I've only been at FreeBSD for a few weeks and now I've decided to try FreeBSD 8.0 Release on my server now that it's out.

The server is a Dell 1750 with a built-in Broadcom dual gigabit ethernet (gbe). I have NTPD and Samba starting at boot (samba is hooked into Active Directory).

On boot, NTPD complains with these log messages:


```
Dec  8 15:54:47 garett kernel: bge0: link state changed to UP
Dec  8 15:54:48 garett ntpd_initres[766]: host name not found: 0.freebsd.pool.ntp.org
Dec  8 15:54:48 garett ntpd_initres[766]: couldn't resolve `0.freebsd.pool.ntp.org', giving up on it
Dec  8 15:54:48 garett ntpd_initres[766]: host name not found: 1.freebsd.pool.ntp.org
Dec  8 15:54:48 garett ntpd_initres[766]: couldn't resolve `1.freebsd.pool.ntp.org', giving up on it
Dec  8 15:54:48 garett ntpd_initres[766]: host name not found: 2.freebsd.pool.ntp.org
Dec  8 15:54:48 garett ntpd_initres[766]: couldn't resolve `2.freebsd.pool.ntp.org', giving up on it
```

Samba with these:


```
[2009/12/08 15:54:45,  0] smbd/server.c:main(1221)
  smbd version 3.2.15 started.
  Copyright Andrew Tridgell and the Samba Team 1992-2009
[2009/12/08 15:54:46,  0] libsmb/nmblib.c:send_udp(839)
  Packet send failed to 192.168.56.2(137) ERRNO=Host is down
[2009/12/08 15:54:46,  0] libsmb/nmblib.c:send_udp(839)
  Packet send failed to 192.168.56.2(137) ERRNO=Host is down
```

However, I am able to SSH into the box just fine after a reboot. I haven't had this problem with FreeBSD 7.2 (though I've only been evaluating FreeBSD for a few weeks).

rc.conf looks like this:


```
defaultrouter="192.168.56.1"
hostname="garett"
ifconfig_bge0="inet 192.168.56.19  netmask 255.255.255.0"
sshd_enable="YES"
ntpd_enable="YES"
ntpd_flags="-q"
nmbd_enable="YES"
samba_enable="YES"
smbd_enable="YES"
winbindd_enable="YES"
```

I can do this successfully after boot: 


```
# ifconfig bge0
bge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=9b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM>
	ether 00:11:43:eb:47:7c
	inet 192.168.56.19 netmask 0xffffff00 broadcast 192.168.56.255
	media: Ethernet autoselect (1000baseT <full-duplex>)
	status: active

# nslookup 0.freebsd.pool.ntp.org
Server:		192.168.56.2
Address:	192.168.56.2#53

Non-authoritative answer:
Name:	0.freebsd.pool.ntp.org
Address: 69.63.177.217
Name:	0.freebsd.pool.ntp.org
Address: 72.167.54.201
Name:	0.freebsd.pool.ntp.org
Address: 64.73.32.134

# ping 192.168.56.2
PING 192.168.56.2 (192.168.56.2): 56 data bytes
64 bytes from 192.168.56.2: icmp_seq=0 ttl=128 time=0.204 ms
64 bytes from 192.168.56.2: icmp_seq=1 ttl=128 time=0.219 ms
64 bytes from 192.168.56.2: icmp_seq=2 ttl=128 time=0.166 ms
64 bytes from 192.168.56.2: icmp_seq=3 ttl=128 time=0.124 ms
^C
--- 192.168.56.2 ping statistics ---
4 packets transmitted, 4 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.124/0.178/0.219/0.037 ms
```


It _appears_ to me that the system isn't bringing up network fast enough. Also on boot, I see a message that says "link state changed to DOWN" as well as ifconfig output that shows 'no carrier'. 

What could be causing this? Can anyone offer any wisdom? Are the daemons that require the network suppose to wait for the network to come up?


Thanks


----------



## phoenix (Dec 9, 2009)

Some gigabit NICs take a long time to negotiate a connection with some switches.  The only fix I've found for this is to add a sleep command to /etc/rc.d/netif in the start) section.  Or to add a custom rc.d script called SLEEP that just sleeps for 10-15 seconds, with REQUIRE: NETWORKING.  Check the output of [cmd=]rcorder /etc/rc.d/* /usr/local/etc/rc.d/*[/cmd] to make sure your network services start after SLEEP.


----------



## DutchDaemon (Dec 9, 2009)

You could try setting the media/mediaopt for bge0 in ifconfig.


----------



## seanthingee (Dec 10, 2009)

Thanks for the responses and ideas. Very helpful. 

Unfortunately media & mediaopt didn't seem to make any improvement.

Sleep: It seems promising, though hackish-feeling (I like avoiding hacks and finding the real problem), but I'm still new to this. I at first set it to sleep 20 seconds, but that wasn't long enough. I set it to 60 seconds and it works, but that seemed excessive...

After that, I edited my script to fork "ping 192.168.56.2" before the sixty-second sleep starts to see just how long it takes to actually bring up the network. It seems it takes 30-some seconds! Even _after_ I see "link state changed to UP". Does this sound reasonable?


Thanks


----------



## phoenix (Dec 10, 2009)

I have firewalls with Intel PRO/1000MT NICs that take just over 30 seconds to negotiate a gigabit link with HP ProCurve gigabit switches.  On 10/100 switch ports, they come up in under 5 seconds.  So that doesn't sound excessive to me.

Whether or not that's correct behaviour ...


----------



## seanthingee (Dec 10, 2009)

Thanks for the help, seems that if I set it to sleep 35 seconds it works well. I reinstalled FreeBSD 7.2 and found it behaving exactly the same way. Not sure how I hadn't noticed it before. 

I do find it strange that I can't find anyone else talking about this issue on these boards or even through Google searches. Naively perhaps, it would seem to me this would be a common problem with servers and starting network services at boot. Maybe I'm not looking with the right keywords.


----------



## radmanly (Dec 13, 2009)

I just wanted to add a "me, too" on this.  I encountered the same issue and adding a sleep script to rc.d (30 seconds) fixed it for me.


----------



## tommybravoman (Jun 6, 2012)

*How do I implement this solution exactly?*

I think I got the same problem, but I don't know how to implement this solution exactly. It seems as though I need to create a script in /etc/rc.d/ that I need to enable somehow in rc.conf (something like sleepscript_enable="YES"). 

But how do I make sure that the sleep command is executed at the right time? (e.g. before the service that has to wait on the networking interface to come up)


----------



## wblock@ (Jun 6, 2012)

You're responding to a thread that's several years old.  See
`% man rc.conf | less -p netwait`


----------



## seanthingee (Jun 20, 2012)

wblock is right. I'm not sure when it came along but it seems netwait is the answer I was looking for when I started this thread.

However, if it helps anyone else, the following is the rc script I wrote to solve my problem. I never wrote a rc script before and I fumbled through it. I'm sure it's not the correct way to write one, but it worked for me.


```
#!/bin/sh
#
# PROVIDE: wait_for_network
# REQUIRE: NETWORKING
#

. /etc/rc.subr

name="wait_for_network"
start_cmd="${name}_start"
stop_cmd=":"

wait_for_network_start()
{
    echo "waiting 30 seconds for network!"
    sleep 30
}

load_rc_config $name
run_rc_command "$1"
```

Place in /usr/local/etc/rc.d/wait_for_network. Make executable: 
`chmod +x /usr/local/etc/rc.d/wait_for_network`


----------

