Subject: Re: preconfiguring dhclient interfaces
To: Steve Bellovin <smb@research.att.com>
From: Luke Mewburn <lukem@netbsd.org>
List: netbsd-users
Date: 11/25/2002 10:16:08
On Fri, Nov 22, 2002 at 10:57:18AM -0500, Steve Bellovin wrote:
| I want to ensure that dhclient only runs on certain interfaces, to
| prevent it from overwriting the static address for vmnet1. I can't set
| dhclient_flags, because wi0 is sometimes present and sometimes not.
| Instead, I wrote the following script, which I put into
| /etc/rc.conf.d/dhclient (though it could -- should? -- go into
| /etc/rc.d/dhclient.
There's an easier way; just list the interfaces you want dhclient to
attempt to use in /etc/dhclient.conf. For example, on my laptop I have:
interface "wi0" {
media "-mediaopt adhoc nwid SOMETHING nwkey SOMETHINGELSE";
media "-mediaopt adhoc nwid '' -nwkey";
media "mediaopt adhoc -nwkey";
}
interface "tlp0" {
}
dhclient only tries wi0 (if present), cycling through the media
options on each retry, and tlp0 (if present); it doesn't try other
"broadcast capable" interfaces that may be available.
I'd be curious to know if this solution works for you or not.
Luke.
|
|
|
| #!/bin/sh
|
| dhclient_precmd()
| {
| if [ "x$dhclient_flags" = x -a -f /etc/dhcpinterface ]
| then
| iface="/"
| for i in `ifconfig -l`
| do
| iface="$iface$i/"
| done
|
| rc_flags=""
| while read x
| do
| if expr "$x" : "#" >/dev/null
| then
| continue
| fi
| if expr "$iface" : ".*/$x/" >/dev/null
| then
| rc_flags="$rc_flags $x"
| fi
| done </etc/dhcpinterface
| echo $rc_flags
| fi
| }
|
| start_precmd=dhclient_precmd
| restart_precmd=dhclient_precmd
|
|
| The file /etc/dhcpinterface lists the allowable dhcp interfaces;
| however, only those that actually exist are passed in. There are some
| obvious and easy ways to accomplish the match more easily; however, I
| needed something that only used commands in /bin, because at boot time
| dhclient runs before /usr is mounted. (Let's not dredge up *that*
| argument again....)
|
| The script is skipped if dhclient_flags has been set explicitly by the
| user. (Should I be checking rc_flags there?)
|
| In my /etc/apm/resume script, I invoked '/etc/rc.d/dhclient restart'.
|
|
| --Steve Bellovin, http://www.research.att.com/~smb (me)
| http://www.wilyhacker.com ("Firewalls" book)
|