INT 21h

Hi, I am Vladimir Smagin, SysAdmin, DevOps and barely good guy. Telegram Email / GIT / Микроблог / Thingiverse / 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(

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/
client-disconnect /opt/ovpn-dns/

Script /opt/ovpn-dns/

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

Script /opt/ovpn-dns/

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 *


Микроблог перейти

# 2019-12-23 09:14:01

Очень интересная концепция, docker-compose для kubernetes #devops #kubernetes #docker

# 2019-12-16 17:21:18

Надо будет почитать для общего развития как оживить кластер в случае проеба сертов #kubernetes #devops

# 2019-12-12 17:33:46

js bootstrap с интерфейсом как в DOS

© Vladimir Smagin, 2005-2019. Копирование материалов без разрешения запрещено. GPG DA4CD0F5E222EA727D6A40C413BCE12E5618F071 *

Fortune cookie: Spam del giorno: 100 Euro per la vostra vedelta