You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.5 KiB

#!/usr/bin/env ruby
require "netaddr"
require "set"
require_relative "lib/lxc"
def update_hetzner_rdns6(user, password, domain, subnet, network)
api =, password)
rdns = api.get("/rdns")
records = {}
rdns.each do |val|
rec = val["rdns"]
cidr = NetAddr::CIDR.create(rec["ip"])
next unless cidr.version == 6 and subnet.contains?(rec["ip"])
records[rec["ip"]] = rec["ptr"]
processed_ips =
network.each do |host, data|
cidr = data["ipv6"]
next if cidr.nil?
cidr = NetAddr::CIDR.create(cidr)
next unless cidr.version == 6 and subnet.contains?(data["ipv6"])
hostname = data["rdns6"] || "#{host}.#{domain}"
ip = cidr.ip(Short: true)
next if processed_ips.include?(ip)
processed_ips << ip
ptr = records.delete(ip)
if ptr.nil? or ptr != hostname
puts "add ptr: #{ip} -> #{hostname}""/rdns/#{ip}", ptr: hostname)
records.each do |ip, ptr|
puts "delete ptr: #{ip} -> #{ptr}"
api.delete("/rnds/#{ip}", allow_404: true)
registry =["zone"] ||= {}
domain =["zone"]["ipv6-domain"] || "lxc"
7 years ago
subnet =["zone"]["ipv6-subnet"]
if subnet
subnet_cidr = NetAddr::CIDR.create(subnet)
credentials ="hetzner.key"))
user, password = credentials.split(":")
network =["network"] || {}
update_hetzner_rdns6(user, password, domain, subnet_cidr, network)
7 years ago
puts "no ipv6-subnet specified in container.json. skip rdns records"