กรุณาปิด โปรแกรมบล๊อกโฆษณา เพราะเราอยู่ได้ด้วยโฆษณาที่ท่านเห็น
Please close the adblock program. Because we can live with the ads you see


thxf.org

บทความ มาทำ dns server ใช้กัน

เริ่มต้นเลยนะครับ
บทความโดยคุณ iCez

เตรียมอุปกรณ์กันก่อน

- หาเครื่องที่จะเอามาทำ dns server
เงื่อนไข spec ไม่ต้องแรงมากก็ได้ (atom ram 2gb ก็เอาอยู่ครับ)
แต่ขอนิ่งๆ... เพราะถ้าล่มนั่นหมายความว่าเว็บลูกค้าคุณล่มหมด
แนะนำให้หาอย่างน้อยๆ 2 เครื่องแยกกันเป็นเอกเทศ แยก isp ได้ด้วยจะดีมากครับ
ส่วน software ต้องไม่มี dns service รันอยู่นะครับ ไม่งั้นมันตีกัน

ขอใช้ centos เป็นหลักนะครับ ความถนัดส่วนตัว ใครจะปรับเป็น os อื่นก็ตามสะดวกเลย

ที่เครื่อง DNS Server

ติดตั้ง + load data นิดๆ หน่อยๆ ครับ
*** SSH ตั้ง AllowRootAccess เป็น yes ด้วยนะครับ แล้วตั้งพาสยากๆ หน่อยละกัน
yum install bind caching-nameserver openssh-client
chkconfig named on
wget -O /var/named/named.root http://www.internic.net/zones/named.root
umask 0022
touch /etc/named.slaves
cd
umask 0077
mkdir .ssh
cd .ssh
ssh-keygen
ถึงตอนนี้ กด enter ผ่านให้หมดเลยครับ มันจะขึ้นถามประมาณนี้

[root@dns01 test]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
33:c9:e5:e4:dc:72:50:14:2c:87:9b:c1:47:ea:ca:d9 [email protected]
mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
ก๊อปเนื้อหาในไฟล์ /root/.ssh/id_rsa เก็บไว้ดีๆ แล้วลบทิ้ง

แล้วเปิดไฟล์ /etc/named.conf ขึ้นมา ( ปกติจะไม่มีมาให้นะครับ สร้างใหม่ได้เลย )
options {
allow-recursion {
localnets;
};
directory "/var/named";
auth-nxdomain no;
pid-file "/var/run/named/named.pid";
};

controls {
inet 127.0.0.1 port 953
allow { 127.0.0.1; } keys { "rndckey"; };
};
zone "." IN {
type hint;
file "named.root";
};
include "/etc/rndc.key";
include "/etc/named.slaves";
ถึงตอนนี้ จำไฟล์ /root/.ssh/id_pub ให้ดีๆ นะครับ เดี๋ยวต้องใช้อีก แต่อีกเครื่องนึงนะ

มาที่เครื่องที่ลง DA ไว้นะครับ

เปิดไฟล์ /etc/named.conf

options {
directory "/var/named";
/*
* If there is a firewall between you and nameservers you want
* to talk to, you might need to uncomment the query-source
* directive below. Previous versions of BIND always asked
* questions using port 53, but BIND 8.1 uses an unprivileged
* port by default.
*/
// query-source address * port 53;

allow-recursion { localnets; };
allow-transfer { 123.45.67.89; };
also-notify { 123.45.67.89; };
};
ปกติมันจะไม่มีตัวแดงนะครับ ให้เพิ่มเข้าไป แล้วแก้ IP นั้นเป็นหมายเลข IP ของ dns server ด้วย
แก้เสร็จก็เซฟได้เลยครับ นิดเดียว

แล้วสร้าง folder /root/.ssh ขึ้นมา permission 0700 นะครับ
วิธีสร้างก็ประมาณนี้
mkdir /root/.ssh
chmod 0700 /root/.ssh
ทีนี้... ไปก๊อปไฟล์ id_rsa มาจากเครื่อง dns server ครับ เอามาใส่ใน folder /root/.ssh/ เมื่อกี้
ตั้งชื่อประมาณ
/root/.ssh/private.dns01
/root/.ssh/private.dns02
(เผื่อมีหลายเครื่อง)
แล้วทีนี้ก็... สร้าง folder /root/bin สร้างไฟล์ชื่อ dnssync เนื้อหาตามนี้ครับ

#!/bin/sh
#
SERVERIP=123.45.67.99
for domain in `/bin/grep ^zone /etc/named.conf |/bin/grep "type master" |/bin/awk '{print $2}' |/bin/awk -F\" '{print $2}'`
do
/usr/bin/printf "zone \"${domain}\" { type slave; file \"/var/named/slaves/${domain}.db\"; masters { ${SERVERIP}; }; };\n"
done > /root/slavezone.conf
/usr/bin/scp -i /root/.ssh/private.dns01 /root/slavezone.conf [email protected]:/etc/named.${SERVERIP}.conf > /dev/null
ตัวแดงด้านบน แก้ IP เป็น IP ของเครื่อง DA นะครับ
แล้วแก้ตัวเขียวด้านล่าง อันแรกแก้เป็นชื่อไฟล์ อันหลังแก้เป็น IP ของ DNS Server
ถ้ามีหลาย dns server ให้ copy บรรทัดสุดท้ายที่ขีดเส้นไว้ เป็ฯหลายๆ อันแล้วแก้ key file กับ ip เอา

แล้วสร้างไฟล์ /usr/local/directadmin/scripts/custom/domain_create_post.sh
ใส่ข้อมูลตามนี้

#!/bin/sh
/root/bin/dnssync
หลังจากเสร็จหมด เก็บรายละเอียดตามนี้ครับ

chmod 0700 /root/bin/dnssync /usr/local/directadmin/scripts/custom/domain_create_post.sh
/root/bin/dnssync
/usr/bin/scp -i /root/.ssh/private.dns01 /root/slavezone.conf [email protected]:/etc/named.123.45.67.99.conf
อย่าลืมแก้บรรทัดสุดท้ายนั้นนะครับ
กลับมาที่เครอื่ง DNS Server อีกที

เปิดไฟล์ /etc/named.slaves
แล้วเพิ่ม

include "/etc/named.123.45.67.99.conf";
ลงไปด้วย

เสร้จแล้ว restart bind ครับ
จบสิ้นกระบวนการ ถ้า bind start ไม่ติดลองสั่ง dnssync จากเครื่อง DA ดูอีกที (มันไม่ควรจะทำงานนานเกิน 5 วินะครับ)

ที่มา
 

กระทู้ที่คล้ายกัน

  • บทความ บทความ
วิธีการทํา DirectAdmin mass update DNS server
There can be multiple reasons why you want to update the DNS records of every domain at once. This is only possible to do when you have direct SSH access to the server. If you do not you can ask...
ตอบกลับ
0
จำนวนการดู
1พัน

กรุณาปิด โปรแกรมบล๊อกโฆษณา เพราะเราอยู่ได้ด้วยโฆษณาที่ท่านเห็น
Please close the adblock program. Because we can live with the ads you see
กลับ
ยอดนิยม ด้านล่าง