Configuring DNS in an openVPN based routing VPN setup

Hi all

I have an openVPN server which is configured for routing based VPN. Multiple clients connect to this VPN server.

The network address range for the VPN is 10.111.10.0/24
The server’s VPN IP address is 10.111.10.1
The server is also connected directly on the internet with a static IP address on eth0 – some p.q.r.s

Right now I end up addressing all the clients and the server using IP addresses. But I intend to set up different services on the server like a mailhost, git, apache, etc. and I plan to use different hostnames for all of these services but all running on the same server. I’m planning to use a private domain example.site for all the hosts in the VPN.

Could someone guide me through the setup for this ?

I’ve already installed the bind package and went through pages about BIND and named.conf, the zones and such. But it is still kind of confusing how do I put all these together.
Also, what DNS options should I be pushing to the openVPN clients so that their resolv.conf can use the DNS server on the VPN for querying only the hostnames for the example.site domain. All other queries should go through the client’s default nameserver already in the resolv.conf.

Thanks.

UPDATE:

I was able to set up the name server for my VPN and it seems to be working. I’m also able to push the DOMAIN and DNS server options from my openvpn server.conf. And all the clients are able to resolve the hostname using either just hostnames or hostname.example.site. Now I’d like to enable dynamic DNS updates for enabling the clients to register themselves with the name server server on the VPN so that multiple clients can also address each other using hostnames. Could some one help me with that ?

These are my config files.

/etc/named.conf

Code:
options {
    directory "/var/lib/named";
    managed-keys-directory "/var/lib/named/dyn/";
    dump-file "/var/log/named_dump.db";
    statistics-file "/var/log/named.stats";
    listen-on-v6 { none; };
    notify no;
    disable-empty-zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.IP6.ARPA";
    include "/etc/named.d/forwarders.conf";
     allow-query { 127.0.0.1; 10.111.10/24; };
     listen-on port 53 { 127.0.0.1; 10.111.10.1; };
};

zone "." in {
    type hint;
    file "root.hint";
};

zone "localhost" in {
    type master;
    file "localhost.zone";
};

zone "0.0.127.in-addr.arpa" in {
    type master;
    file "127.0.0.zone";
};

zone "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" in {
    type master;
    file "127.0.0.zone";
};

include "/etc/named.conf.include";
logging {
    category default { log_syslog; };
    channel log_syslog { syslog; };
};
 zone "example.site" in {
     file "master/example.site";
    type master;
    allow-transfer { any; };
};
 zone "10.111.10.in-addr.arpa" in {
     file "master/10.111.10.in-addr.arpa";
    type master;
     allow-transfer { any; };
  };

/var/lib/named/master/example.site

Code:
$TTL 2d
 @        IN SOA        ns1.example.site.    root.example.site. (
                2012052901    ; serial
                3h        ; refresh
                1h        ; retry
                1w        ; expiry
                1d )        ; minimum

 example.site.    IN MX        0 mothership.example.site.
 example.site.    IN NS        mothership.example.site.
 mothership    IN A        10.111.10.1
ns1        IN CNAME    mothership
mail        IN CNAME    mothership

/var/lib/named/master/10.111.10.in-addr.arpa

Code:
$TTL 2d
 @        IN SOA        ns1.example.site.    root.example.site. (
                2012053000    ; serial
                3h        ; refresh
                1h        ; retry
                1w        ; expiry
                1d )        ; minimum

 10.111.10.in-addr.arpa.    IN NS        ns1.example.site.
 1.10.111.10.in-addr.arpa.    IN PTR        mothership.example.site.

Set static client’s VPN IP

Kali ini kita akan memberikan static VPN IP untuk setiap client openVPN :

buatlah sebuah direktori ccd di bawah /etc/openvpn/:

mkdir /etc/openvpn/ccd

Tambahkan satu baris di  OpenVPN server.conf  yang berada di bawah  /etc/openvpn/,:

client-config-dir ccd

simpan.

Sekarang di dalam /etc/openvpn/ccd kita buat sebuah file untuk setiap user agar memiliki ip address yang tetap. Anda harus memberi nama file persama dengan username dari VPN, jika Anda menambahkan user melalui perintah useradd di mesin lokal, atau menggunakan user yang dibuat dalam FreeRADIUS, maka nama file tersebut harus sama dengan nama username.

Contoh : saya memiliki username : smk1jkt dan dalam file OpenVPN server.conf kita gunakan subnet 10.8.0.0/24, jika kita ingin memberikan smk1jkt IP 10.8.0.100 kita lakukan di bawah ini :

cd /etc/openvpn/ccd/
touch safesrv

Dan kemudian tambahkan satu baris ke dalam file yang bernama smk1jkt :

ifconfig-push 10.8.0.100 10.8.0.101

Restart OpenVPN:

service openvpn restart

User smk1jkt akan mendapat  IP 10.8.0.100 =)

MySQL Create Database with utf8mb4 Character Set Syntax

Create database

I frequently create database with utf8mb4 character set:

CREATE DATABASE 'mydb' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; GRANT ALL ON 'mydb'.* TO 'username'@localhost IDENTIFIED BY 'password'; FLUSH PRIVILEGES;

or

CREATE SCHEMA 'mydb' CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; GRANT ALL ON 'mydb'.* TO 'username'@localhost IDENTIFIED BY 'password'; FLUSH PRIVILEGES;

Create user

Create user and give privilege to it

create user 'username'@localhost identified by 'password'; grant all privileges on *.* to username@localhost; 
or 
GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;

Change user’s password

Replace the password with the password that you want to use.

MySQL 5.7.6 and later:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5 and earlier:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

Here is a short list of other common possible permissions that users can enjoy.

  • ALL PRIVILEGES- as we saw previously, this would allow a MySQL user all access to a designated database (or if no database is selected, across the system)
  • CREATE- allows them to create new tables or databases
  • DROP- allows them to them to delete tables or databases
  • DELETE- allows them to delete rows from tables
  • INSERT- allows them to insert rows into tables
  • SELECT- allows them to use the Select command to read through databases
  • UPDATE- allow them to update table rows
  • GRANT OPTION- allows them to grant or remove other users’ privileges

Reference from :

  • http://www.euperia.com/development/mysql/mysql-create-database-with-utf8-character-set-syntax/1064
  • https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql