Skip to content

Instantly share code, notes, and snippets.

@Daniel15 Daniel15/_README.md
Last active Dec 6, 2018

Embed
What would you like to do?
Routing scripts for Tinc

This Gist contains some scripts for Tinc, in order to configure the routing tables for a remote subnet on Windows (ie. if a remote system wants to expose an entire subnet over the VPN). Tinc does not configure the routing tables by default, which is why these scripts are needed. See the mailing list thread here: https://www.tinc-vpn.org/pipermail/tinc/2018-December/005340.html

Place the files in the Tinc network directory (eg. C:\Program Files\Tinc\netname\) and change $interface in functions.ps1 to match the name of the Tinc interface configured in tinc.conf

$interface = "Tinc" # Should match Interface setting in tinc.conf
# Gets the local IP address of the Tinc interface
function Get-LocalTincIP() {
$config = Get-NetIPConfiguration -InterfaceAlias $interface | Get-NetIPAddress -AddressFamily IPv4
return $config.IPAddress
}
# Converts CIDR (eg. "192.168.0.0/24") to IP and mask (eg. "192.168.0.0" with mask "255.255.255.0")
function Convert-CIDRToMask([Parameter(Mandatory)][String] $subnet) {
$parts = $subnet -split '/'
$ip = $parts[0]
$cidr = [Int32]$parts[1]
# Default to /32 if CIDR not provided
if ($cidr -eq 0) {
$cidr = 32
}
$mask = [IPAddress](([UInt32]::MaxValue) -shl (32 - $cidr) -shr (32 - $cidr))
return [PSCustomObject]@{
ip = $ip;
mask = [String]$mask;
}
}
cd %~dp0
powershell -ExecutionPolicy Bypass ./subnet-down.ps1
. ./functions.ps1
$local_ip = Get-LocalTincIP
$route = Convert-CIDRToMask $Env:SUBNET
Write-Output ('Removing route for {0}, subnet mask {1}' -f $route.ip, $route.mask)
route delete $route.ip mask $route.mask $local_ip
cd %~dp0
powershell -ExecutionPolicy Bypass ./subnet-up.ps1
. ./functions.ps1
$local_ip = Get-LocalTincIP
$route = Convert-CIDRToMask $Env:SUBNET
Write-Output ('Adding route for {0}, subnet mask {1}' -f $route.ip, $route.mask)
route add $route.ip mask $route.mask $local_ip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.