Skip to content

A script to automatically synchronize all Tailscale ipv4 and ipv6 addresses with thier MagicDNS names in the /etc/hosts file of your system.

Notifications You must be signed in to change notification settings

gabesw/sync-tailscale-hosts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Sync Tailscale Hosts

This is a simple script intended to be used on a Pi-hole that listens on Tailscale. I found it annoying to constantly update the /etc/hosts file on my Pi-hole every time I added or removed a device from my Tailnet. This script uses the tailscale status command and updates the hosts file of the Pi-hole with the IPv4 and IPv6 IPs of each device and their MagicDNS names.

Customization/Setup

Variable Usage Default
HOSTS_FILE The path to the hosts file '/etc/hosts'
START_MARKER A comment in the hosts file to tell the script where to insert the tailscale hosts '# Tailscale Start'
END_MARKER The end of the tailscale IPs block '# Tailscale End'

You must add two lines to the hosts file for the script to work:

...
<START_MARKER>
<END_MARKER>

By default, this should be:

...
# Tailscale Start
# Tailscale End

All of the dynamically added hosts will be between these two comments.

Usage

The script must be run with root privilege as the hosts file is owned by root. Create a cron job to run this script so that it will update consistantly. I have mine set to run every hour.

About

A script to automatically synchronize all Tailscale ipv4 and ipv6 addresses with thier MagicDNS names in the /etc/hosts file of your system.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages