INT 21h

Hi, I am Vladimir Smagin, sysadmin. Telegram Email GPG

OpenVPN dynamic local domain names with dnsmasq

№ 9436 В разделе "Администрирование" от September 25th, 2018,

There two ways:

  • Generate full config once a time
  • Generate many configs separately for all clients

Way #1

pip install openvpn_status

from openvpn_status import parse_status

hostDomain = "vpn"

with open('/etc/openvpn/openvpn-status.log') as logfile:
    status = parse_status(logfile.read())

for client in status.routing_table:
    domain = status.routing_table[client].common_name + "." + hostDomain
    address = status.routing_table[client].virtual_address
    print("address=/{}/{}".format(domain, address))

Way #2

Add to /etc/openvpn/server.conf these lines:

script-security 3 system
client-connect /opt/ovpn-dns/ovpn-dns-connect.sh
client-disconnect /opt/ovpn-dns/ovpn-dns-disconnect.sh

Script /opt/ovpn-dns/ovpn-dns-connect.sh:

#!/bin/bash
echo "address=/$common_name.vpn/$ifconfig_pool_remote_ip" > /etc/dnsmasq.d/$common_name.conf
/bin/systemctl restart dnsmasq

Script /opt/ovpn-dns/ovpn-dns-disconnect.sh:

#!/bin/bash
rm -f /etc/dnsmasq.d/$common_name.conf
/bin/systemctl restart dnsmasq

Нет комментариев »

Leave a Reply

Your email address will not be published. Required fields are marked *

*


© Vladimir Smagin, 2005-2018. Копирование материалов без разрешения запрещено. GPG 0x29AE91B1A37721C3
Яндекс.Метрика