Force a static HWaddr to tinc interface

Guus Sliepen guus at tinc-vpn.org
Thu Jul 11 10:50:18 CEST 2013


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>


More information about the tinc mailing list