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 -- tinc-up ends -- Best regards, Ville -------------- seuraava osa -------------- HTML liite on siirretty... URL: <http://www.tinc-vpn.org/pipermail/tinc/attachments/20130711/3e22a86c/attachment.html>
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 > $MACFILEIn 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>
On Thu, Jul 11, 2013 at 07:26:03AM +0300, Ville Mattila wrote:> 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?No. On purpose, tincd itself does not do any configuration of the virtual network interface. Otherwise, there would be an explosion of configuration variables to cater to everyone's needs, and the implementation of these options would need to take care of the differences between all the platforms supported by tinc. The tinc-up script is much more flexible than tincd itself could ever be.> 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 > > -- tinc-up ends --It might feel hacky but I don't see any problem with your script! If you don't like the awk part, you can get the MAC address directly from the /sys tree: #!/bin/sh set -e MACFILE="/etc/tinc/$NETNAME/mac" [ -e $MACFILE ] && ip link set dev $INTERFACE address `cat $MACFILE` || cat /sys/class/net/$INTERFACE/address >$MACFILE dhclient $INTERFACE & -- Met vriendelijke groet / with kind regards, Guus Sliepen <guus at tinc-vpn.org> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 198 bytes Desc: Digital signature URL: <http://www.tinc-vpn.org/pipermail/tinc/attachments/20130711/4ddb5749/attachment.sig>