My linux world » srv-dns

srv-dns


Prerequiste

I assume that you have a Centos installation.

Installation

You can copy/paste this script and use it to configure automatically your server.

  1. #!/bin/bash
  2.  
  3. echo "install bind"
  4. dnf -y install bind bind-libs bind-utils
  5.  
  6. echo "start service named at boot"
  7. systemctl enable named.service
  8.  
  9. echo "get current network interface"
  10. currentDevice=`nmcli d | grep connected | awk '{split($1,a,"\t"); print a[1]}'`
  11.  
  12. echo "add service name (port 53) to firewall"
  13. firewall-cmd --permanent --add-port=53/tcp
  14. firewall-cmd --reload
  15.  
  16. echo "create my-domain.local.fwd"
  17. cat > /var/named/my-domain.local.fwd << "EOF"
  18. $ORIGIN my-domain.local.
  19.  
  20. $TTL 3D
  21.  
  22. @ SOA dns.my-domain.local. root.my-domain.local. (12 4h 1h 1w 1h)
  23.  
  24. @ IN NS dns.my-domain.local.
  25.  
  26. dns.my-domain.local. IN A mylocalIP
  27.  
  28. www IN A mylocalIP
  29.  
  30. EOF
  31.  
  32. mylocalIP=`hostname -I`
  33. sed -i "s/mylocalIP/$mylocalIP/g" /var/named/my-domain.local.fwd
  34.  
  35. echo "create my-domain.local.rev"
  36. cat > /var/named/my-domain.local.rev << "EOF"
  37. $ORIGIN mylocalIP3.mylocalIP2.mylocalIP1.in-addr.arpa.
  38.  
  39. $TTL 3D
  40.  
  41. @ SOA dns.my-domain.local. root.my-domain.local. (12 4h 1h 1w 1h)
  42.  
  43. @ IN NS dns.my-domain.local.
  44.  
  45. mylocalIP4 IN PTR dns.my-domain.local.
  46.  
  47. EOF
  48.  
  49. mylocalIP1=`hostname -I | cut -d: -f2 | cut -d. -f1| awk '{ print $1}'`
  50. mylocalIP2=`hostname -I | cut -d: -f2 | cut -d. -f2| awk '{ print $1}'`
  51. mylocalIP3=`hostname -I | cut -d: -f2 | cut -d. -f3| awk '{ print $1}'`
  52. mylocalIP4=`hostname -I | cut -d: -f2 | cut -d. -f4| awk '{ print $1}'`
  53.  
  54. sed -i "s/mylocalIP1/$mylocalIP1/g" /var/named/my-domain.local.rev
  55. sed -i "s/mylocalIP2/$mylocalIP2/g" /var/named/my-domain.local.rev
  56. sed -i "s/mylocalIP3/$mylocalIP3/g" /var/named/my-domain.local.rev
  57. sed -i "s/mylocalIP4/$mylocalIP4/g" /var/named/my-domain.local.rev
  58.  
  59. echo "Now add zone to named.conf"
  60. cat >> /etc/named.conf << "EOF"
  61. zone "my-domain.local" {
  62. type master;
  63. file "my-domain.local.fwd";
  64. };
  65. zone "mylocalIP3.mylocalIP2.mylocalIP1.in-addr.arpa" {
  66. type master;
  67. file "my-domain.local.rev";
  68. };
  69. EOF
  70.  
  71. sed -i "s/mylocalIP1/$mylocalIP1/g" /etc/named.conf
  72. sed -i "s/mylocalIP2/$mylocalIP2/g" /etc/named.conf
  73. sed -i "s/mylocalIP3/$mylocalIP3/g" /etc/named.conf
  74.  
  75. echo "Now enable query from all network (WARNING you should have a look at this to improve your network security!)"
  76. sed -i "s/\(listen-on port\)/\/\/\1/g" /etc/named.conf
  77. sed -i "s/\(listen-on-v6 port\)/\/\/\1/g" /etc/named.conf
  78. sed -i "s/\(allow-query\)/\/\/\1/g" /etc/named.conf
  79.  
  80.  
  81. echo "start service"
  82. systemctl restart named.service
  83.  

Copyright © 2024 My linux world - by Marc RABAHI
Design by Marc RABAHI and encelades.