INT 21h

Hi, I am Vladimir Smagin, SysAdmin and Kaptain. Telegram Email / GIT / RSS / GPG

OpenVPN dynamic local domain names with dnsmasq

№ 9436 В разделе Sysadmin от 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 *

*

Облачная платформа
Яндекс.Метрика

Fortune cookie: Kerr's Three Rules for a Successful College: Have plenty of football for the alumni, sex for the students, and parking for the faculty.