[NCLUG] Teaching dhclient to lie.

Kyle Anderson kyle at xkyle.com
Fri Oct 8 12:47:21 MDT 2010


John,
Usually, I say use what works :)

But does your nm-applet support just using static ips? For me I setup
a few commonly used static ip profiles I end up using, and then when
I'm in that environment, I just click on them when I need them. See
attached screenshots.

To me this is the easiest way to set static ips (outside the router).
Just be sure to put them outside your dhcp range to prevent conflicts.

Kyle

On 10/8/10, John Gilmore <j.arthur.gilmore at gmail.com> wrote:
> I recently got three laptops, and want them all to have static IP addresses
> on my home wireless. Unfortunately, the router doesn't support dynamically
> assigning static IP's. Also, I want to keep networkmanager running so that
> my wife can easily connect to wifi wherever she goes using the handy-dandy
> little gnome widget.
>
> So, I came up with a way to make it work anyway. I'll include the script,
> which I put in as
> /etc/dhcp3/dhclient-enter-hooks.d/static-route-on-local-wireless
>
> I just wanted to ask if any of you knew a better way to do this, or if this
> will cause other sorts of problems that I haven't noticed yet. It does seem
> to be working fine so far.
>
> The reason I ask this is that I noticed that the output from dhclient still
> lists the router assigned IP address:
> Listening on LPF/wlan0/00:14:d1:46:13:02
> Sending on   LPF/wlan0/00:14:d1:46:13:02
> Sending on   Socket/fallback
> DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 4
> DHCPOFFER from 192.168.1.1
> DHCPREQUEST on wlan0 to 255.255.255.255 port 67
> DHCPACK from 192.168.1.1
> 192.168.1.52
> bound to 192.168.1.103 -- renewal in 38828 seconds.
>
> the ".52" is from /etc/hots, the ".103" is the router assigned address. The
> router assigned address is the only one echoed, the ".52" address wouldn't
> show up at all, but my script leaks it (the "echo | grep" bit echos to
> console, I forgot the >/dev/null on the end)
>
> Here's the script, so you know what I'm talking about. With this script on
> each laptop, and the same hosts file, I'll just need to set the hostname
> properly.
>
> # $Id: static route on local wireless ,v 1.2 2010/10/01 jgilmore
>
> ESSID_MINE=linksys_OW_25001
> INTERFACE_MINE=wlan0
>
> case "$reason" in
>         BOUND|RENEW|REBOOT)
>         if [ "$interface" = "$INTERFACE_MINE" ]; then
>                 #Check. If ESSID has been set to our local ESSID, create a
> static
>                 # IP
>                 /sbin/iwconfig "$interface" | grep "linksys_OW_25001"
>>/dev/null
>                 if [ $? -eq "0" ]; then
>                         #Find our hostname in /etc/hosts, and try to grab
> our ip address.
>                         hostname=`cat /etc/hostname`
>                         IP_MINE=`cat /etc/hosts | grep $hostname | sed
> 's/.*\(192\.168\.[0-9]\{1,3\}\.[0-9]\{1,3\}\).*/\1/'`
>                         if echo $IP_MINE | grep
> '192\.168\.[0-9]\{1,3\}\.[0-9]\{1,3\}'; then
>                                 #Lie about the dhcp response we got.
>                                 logger "the script in
> /etc/dhcp3/dhclient-enter-scripts.d/static-route-on-local-wireless just lied
> about dhclient assigned IP addresses."
>                                 logger "The assigned ip address was
> $new_ip_address, but we're going to use $IP_MINE"
>                                 new_ip_address=$IP_MINE
>                         else
>                                 #Failed to automatically determine static IP
> address.
>                                 logger "The automatic IP fetching scheme
> failed for
> /etc/dhcp3/dhclient-enter-scripts.d/static-route-on-local-wireless, we got
> $IP_MINE, using assigned $new_ip_address"
>                         fi
>                 fi
>         fi
>         ;;
> esac
> _______________________________________________
> NCLUG mailing list       NCLUG at lists.nclug.org
>
> To unsubscribe, subscribe, or modify
> your settings, go to:
> http://lists.nclug.org/mailman/listinfo/nclug
>


More information about the NCLUG mailing list