Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
mini [HOWTO] dynamically set WINS server for Samba via DHCP
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Tue Jan 10, 2006 3:23 pm    Post subject: mini [HOWTO] dynamically set WINS server for Samba via DHCP Reply with quote

Setting WINS server dynamically by utilizing DHCP server options


Issue:
You have a Samba server configured on your notebook.
This machine travels much between different networks with different WINS server each - thereby acting as wins client. It soon gets annoying to manually reconfigure Samba all the time because it needs a line 'wins server = <ip address of wins server>'.

Solution:
Use dhcp provided values for wins like e.g. Windows clients do too and a client capable of handling the additional option(s).

Prerequisites:
DHCP server which provides option 44, thats netbios-name-servers

- net-fs/samba
- baselayout-1.12.0_pre*
- net-misc/dhcp (only dhclient really needed)
(Unfortunately dhcpcd seems not to be capable to deal with this option...)

create a file
/etc/dhcp/dhclient-exit-hooks wrote:
#!/bin/bash
/usr/bin/sed 's/\(wins server = \)\([0-9][\.0-9]*\)/\1'$new_netbios_name_servers'/' </etc/samba/smb.conf >/tmp/smb.temp
cp /tmp/smb.temp /etc/samba/smb.conf


Code:
chmod +x /etc/dhcp/dhclient-exit-hooks

So smb.conf gets rewritten every time a dhcp lease is given. Any line 'wins server = <ip address>' will be changed (only the addresses) to whatever dhclient gets from the dhcp server.

If the ip address of the wins server changes *during* your machine beeing up you need to inform samba about that...
Code:
/usr/bin/smbcontrol nmbd reload-config

Cannot be done in dhclient-exit-hooks because of a catch-22 8)

Have fun

:oops: *edit*
Many thanks UberLord, found a bad typo in my /etc/dhcp/dhclient-exit-hooks; howto corrected accordingly :)

*edit* smbcontrol moved out of dhclient-exit-hooks
shouldn't be needed though unless the wins server changes during the machine beeing up
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself


Last edited by think4urs11 on Tue Jan 10, 2006 4:20 pm; edited 4 times in total
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6738
Location: Blighty

PostPosted: Tue Jan 10, 2006 3:35 pm    Post subject: Reply with quote

Or you could use baselayout-1.12.0_preX and net-misc/dhcp (dhclient) and create this file and chmod +x it

/etc/dhcp/dhclient-exit-hooks
Code:
#!/bin/sh
/usr/bin/sed 's/\(wins server = \)\([0-9][\.0-9]*\)/\1'$new_netbios_name_servers'/' </etc/samba/smb.conf >/tmp/smb.temp
cp /tmp/smb.temp /etc/samba/smb.conf
/usr/bin/smbcontrol nmbd reload-config


That way your custom modifications are preserved between baselayout upgrades :)
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
think4urs11
Bodhisattva
Bodhisattva


Joined: 25 Jun 2003
Posts: 6659
Location: above the cloud

PostPosted: Tue Jan 10, 2006 3:39 pm    Post subject: Reply with quote

8O tried that (with baselayout-1.12.0_pre13-r1) but etc/dhcp/dhclient-exit-hooks never got started; i'll give it annother try later today.

*edit* checked and howto corrected
_________________
Nothing is secure / Security is always a trade-off with usability / Do not assume anything / Trust no-one, nothing / Paranoia is your friend / Think for yourself
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6738
Location: Blighty

PostPosted: Tue Jan 10, 2006 3:56 pm    Post subject: Reply with quote

I've just tested that it works with my development code for exit hooks. In pre14 you'll be able to use enter hooks too.
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Negated Void
l33t
l33t


Joined: 25 Dec 2002
Posts: 665

PostPosted: Mon Jan 16, 2006 8:31 am    Post subject: Reply with quote

Do i have to do more than just "emerge dhcp" to get support? I was using dhcpcd before..
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6738
Location: Blighty

PostPosted: Mon Jan 16, 2006 8:38 am    Post subject: Reply with quote

If you unmerge dhcpcd so you only have dhclient (net-misc/dhcp) as your dhcp client then no.
Otherwise you have to instruct our scripts to use dhclient in /etc/conf.d/net like so

Code:
modules=( "dhclient" )

_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Negated Void
l33t
l33t


Joined: 25 Dec 2002
Posts: 665

PostPosted: Mon Jan 16, 2006 8:54 am    Post subject: Reply with quote

Mmmkay.

Running dhclient now.

Should this overwrite the "wins server" line in my smb.conf? I'm not seeing that happen when i run the reload line.
Back to top
View user's profile Send private message
Negated Void
l33t
l33t


Joined: 25 Dec 2002
Posts: 665

PostPosted: Thu Feb 09, 2006 7:56 am    Post subject: Reply with quote

.. anyone? I'm really interested in this
Back to top
View user's profile Send private message
UberLord
Retired Dev
Retired Dev


Joined: 18 Sep 2003
Posts: 6738
Location: Blighty

PostPosted: Thu Feb 09, 2006 10:28 am    Post subject: Reply with quote

Post your existing wins server line
_________________
Use dhcpcd for all your automated network configuration needs
Use dhcpcd-ui (GTK+/Qt) as your System Tray Network tool
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum