Mark Wright wrote: > First off, thanks for everyone who helped me find dhcpc. That plus the > mini-HOWTO was enough to get my Debian box working with my office network. > > Unfortunately, I had to go back to a static ip address, because dchpc and > samba aren't cooperating. If I use a static ip address, I can browse the > Debian box from Windows using the "find computer" command, and I can connect > to apache by using the url http://markw_debian/ (where "markw_debian" is the > name in the /etc/hosts file). > > When I install the dhcpc package, this no longer works. I assume that nmbd > is returning the wrong ip address in response to netbios name requests. Any > idea why this is happening, and what I can do to fix this?
This is of course is due to the nature of Microsoft Networking. You see, when IBM invented the protocol they wanted it to be a service which didn't require administration (eg. updating hosts files or dns maps) so instead they devised a scheme of name registration/resolution which relies on broadcast (ok, there are also WINS servers but this doesn't help to illuminate the problem here, see RFCs 1001 and 1002 for gory details). When a host becomes alive on the network it tries to establish ownership of its name by sending out registration requests. If no other host complains because you're trying to steal its name then you send out a name update request. Then the hostname is 'owned'. Later on when other hosts want to find you they send out a name lookup request and you respond. In samba, name registration is maintained (it's an active endeavour) by nmbd. When nmbd starts it figures out what IP address you're sitting on and then goes about the business of staking your claim to that name. It will *never* go back (not, at least, in the current version and I don't ever expect it to) and see if your IP address has changed. What tends to happen is that nmbd is started before your IP address is gotten by dhcpcd. Even if you have the IP address before nmbd starts, nmbd get's your IP address by getting your host name then calling gethostbyname() (ok, I'm inferring this, I haven't read this code). This means that if you haven't updated /etc/hosts with an entry for your hostname reflecting your new IP address it can't find out what IP address it should sit on. (Aside: yes, it could use other means to divine what IP address to use. I imagine the samba group has stayed away from this approach because there's no "standard" way of doing this as far as I know.) "So," you say, "what can I do?" Lots. Basically the approach is: update /etc/hosts and then (re)start nmbd. I use the dhcp-client-beta and that particular program provides a script which gets run when the IP address is got. I use this script to update /etc/hosts: # update_hosts(IP Address) # Updates the /etc/hosts file with the IP address update_hosts () { if sed -e '/^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}[[:space:]]\+.*'$(/bin/hostname)'.*/ s/^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/'$1'/' < /etc/hosts > /etc/hosts.new.$$ then /bin/cp /etc/hosts /etc/hosts.old mv /etc/hosts.new.$$ /etc/hosts else rm /etc/hosts.new.$$ fi } (mind the wrapped lines) -- Jens B. Jorgensen [EMAIL PROTECTED]