Force a static HWaddr to tinc interface
Nick Hibma
nick at anywi.com
Thu Jul 11 09:38:27 CEST 2013
On 11 Jul 2013, at 06:26, Ville Mattila <ville at mattila.fi> wrote:
> Hi,
>
> I have been working with tinc network where one host will provide the IP addresses over DHCP to each connected node. Tinc runs in switch mode.
>
> It seems that the HWaddr of the tinc interface is regenerated every time when tinc is (re)started. As a result, DHCP server will assign a new IP for the host. Is there any configuration variable we could use to avoid HWaddr changing?
>
> Currently, I have added a short snippet into tinc-up script that persists the (once given) HWaddr to a file and tries to reset it before starting dhclient. This works, but I feel it a bit hacky solution...
>
> -- tinc-up --
>
> #!/bin/sh
> set -e
>
> MACFILE="/etc/tinc/mynet/mac"
> if [ -e $MACFILE ]; then
> MAC=`cat $MACFILE`
> ifconfig $INTERFACE hw ether $MAC
> fi
>
> dhclient $INTERFACE &
> MAC=`ip link show mynet | awk '/ether/ {print $2}'`
> echo $MAC > $MACFILE
In my configuration we do:
AWMAC1="$(printf '42:00:00:00:01:%02x' $AWSUBNET)"
AWMAC2="$(printf '42:00:00:00:02:%02x' $AWSUBNET)"
AWMAC3="$(printf '42:00:00:00:03:%02x' $AWSUBNET)"
AWSUBNET is a number in the range of 190 - 199 in our case. Notice how 42 sets b2 in top byte, the 'locally administered' bit (see http://en.wikipedia.org/wiki/MAC_address). Isn't it the answer to everything?
tinc-up looks like:
/sbin/ifconfig $INTERFACE ether '@@AWMAC2@@'
/sbin/ifconfig $INTERFACE up
Background: The culprit is not so much tinc as is the underlying OS that has to generate a globally unique MAC address. for generated interfaces The same problem occurs on bridges on FreeBSD (very annoying when trying to use static IP through DHCP there). I guess that we applied this approach for the same reason that you do, but not sure.
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.tinc-vpn.org/pipermail/tinc/attachments/20130711/5cce298d/attachment.html>
More information about the tinc
mailing list