avoiding duplicate IPs in tinc scripts

Hamish Moffatt hamish at moffatt.email
Wed Aug 1 05:49:25 CEST 2018


On 01/08/18 11:42, Hamish Moffatt wrote:
>
> I notice that tinc runs the subnet-up script for the local subnet 
> immediately after the tinc-up script, with $REMOTEADDRESS empty, so I 
> tried putting some of the interface configuration there instead. This 
> seemed to work fine. So tinc-up says only:
>
> #!/bin/bash
> ip link set dev $INTERFACE up
>
> and subnet-up says
>
> #!/bin/sh
> if [ -z "$REMOTEADDRESS" ]; then # local network
>     ip addr add $SUBNET dev $INTERFACE
> fi 

Oops, this only works when the local subnet is a /32. Otherwise it ends 
up assigning a local IP of eg 192.168.42.0/24, which actually seems to 
work but isn't what's intended.

Instead I put

if [[ -z "$REMOTEADDRESS" && $SUBNET != */* ]]; then # local /32 subnet
     ip addr add $SUBNET dev $INTERFACE
fi


and then for the hosts with bigger subnets I add those to tinc-up instead.


Hamish


More information about the tinc mailing list