Sửa lỗi xung đột khi chạy song song Tailscale và ZeroTier trên Ubuntu
Khi cài đặt cả Tailscale và ZeroTier trên cùng một máy Ubuntu, bạn thường gặp tình trạng một trong hai (thường là ZeroTier) bị mất kết nối hoặc không thể SSH. Nguyên nhân chủ yếu do cơ chế tự động quét interface để tìm "node láng giềng" của chúng gây ra vòng lặp định tuyến (routing loop) hoặc chiếm quyền ưu tiên của nhau. Cách triệt để nhất để giải quyết vấn đề này là cấu hình Blacklist Interface – buộc ZeroTier bỏ qua hoàn toàn sự hiện diện của Tailscale.
🛠 Bước 1: Xác định tên Interface
Trước tiên, bạn cần biết chính xác tên card mạng ảo mà Tailscale đang sử dụng. Mở terminal và chạy lệnh:
ip link show | grep tailscale
Thông thường, tên interface mặc định sẽ là tailscale0.
🛠 Bước 2: Tạo file cấu hình local.conf cho ZeroTier
ZeroTier cho phép tùy chỉnh các thiết lập sâu thông qua file local.conf. File này mặc định không tồn tại khi mới cài đặt, bạn cần tạo mới nó.
Truy cập vào thư mục cấu hình của ZeroTier:
sudo nano /var/lib/zerotier-one/local.conf
Dán đoạn mã JSON sau vào nội dung file:
{
"settings": {
"interfacePrefixBlacklist": [ "tailscale" ]
}
}
Giải thích: Cấu hình này ra lệnh cho ZeroTier không gửi gói tin discovery và không cố gắng thiết lập kết nối thông qua bất kỳ interface nào có tên bắt đầu bằng "tailscale".
🛠 Bước 3: Khởi động lại dịch vụ
Để thay đổi có hiệu lực, bạn phải khởi động lại daemon của ZeroTier:
sudo systemctl restart zerotier-one
🛠 Bước 4: Kiểm tra kết quả
Bây giờ, hãy kiểm tra xem ZeroTier đã có thể kết nối bình thường chưa bằng cách thử SSH vào IP ZeroTier của máy khác hoặc sử dụng lệnh:
zerotier-cli listpeers
Nếu trạng thái (status) hiện DIRECT hoặc RELAY ổn định và không còn bị ngắt quãng khi Tailscale đang chạy, bạn đã thành công.
Script :
#!/bin/bash
# Configuration paths
ZT_CONF_DIR="/var/lib/zerotier-one"
ZT_CONF_FILE="$ZT_CONF_DIR/local.conf"
# Ensure the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (use sudo)."
exit 1
fi
# 1. Check if ZeroTier is installed
echo "Checking if ZeroTier is installed on this host..."
if ! command -v zerotier-cli &> /dev/null && [ ! -d "$ZT_CONF_DIR" ]; then
echo "❌ Error: ZeroTier is not installed on this system."
echo "Please install ZeroTier first before running this script."
exit 1
fi
echo "✅ ZeroTier detected."
# 2. Check for existing blacklist configuration
echo "Checking for Tailscale blacklist in local.conf..."
BLACKLIST_EXISTS=false
if [ -f "$ZT_CONF_FILE" ]; then
# Check if the file contains both the key and the value
if grep -q "interfacePrefixBlacklist" "$ZT_CONF_FILE" && grep -q "tailscale" "$ZT_CONF_FILE"; then
BLACKLIST_EXISTS=true
fi
fi
if [ "$BLACKLIST_EXISTS" = true ]; then
echo "✅ Success: ZeroTier is already configured to blacklist Tailscale."
exit 0
else
echo "⚠️ Warning: Tailscale is NOT in the ZeroTier blacklist."
read -p "Do you want to add 'tailscale' to the blacklist? (y/n): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
# Create directory if it doesn't exist (safety)
mkdir -p "$ZT_CONF_DIR"
# Backup existing file if it exists
if [ -f "$ZT_CONF_FILE" ]; then
cp "$ZT_CONF_FILE" "${ZT_CONF_FILE}.bak"
echo "Backup of existing config created at ${ZT_CONF_FILE}.bak"
fi
# 3. Create or update local.conf
cat <<EOF > "$ZT_CONF_FILE"
{
"settings": {
"interfacePrefixBlacklist": [ "tailscale" ]
}
}
EOF
echo "Configuration written to $ZT_CONF_FILE."
# 4. Restart ZeroTier service
echo "Restarting ZeroTier service..."
systemctl restart zerotier-one
if [ $? -eq 0 ]; then
echo "✅ Done! ZeroTier now ignores Tailscale interfaces. Conflict resolved."
else
echo "❌ Error: Failed to restart ZeroTier. Please check 'systemctl status zerotier-one'."
fi
else
echo "Operation cancelled. No changes were made."
fi
fi