Amazon Web Services - AWS EC2 - Ubuntu 14.04
Bind 9
How to install and configure BIND 9 DNS Server on AWS EC2 Ubuntu server.
1. Installation
# apt-get install bind9
2. Start
# service bind9 start | restart | stop | status
3. Add new zone
a) add line
# vim /etc/bind/named.conf
include "/etc/bind/named.conf.default-zones";
b) add (register) zone
# vim /etc/bind/named.conf.default-zones
zone "mikosoft.net" {
type master;
file "/etc/bind/db.mikosoft.net";
};
c) create zone file /etc/bind/db.mikosoft.net
# vim /etc/bind/db.mikosoft.net
$ORIGIN mikosoft.net. ;;; call $ORIGIN variable with @
$TTL 14400
@ 86400 IN SOA ns1.mikosoft.net. info.mikosoft.net. (
2014062400 ;Serial Number
86400 ;refresh
7200 ;retry
86400 ;expire
86400 ;minimum
)
@ 86400 IN NS ns1.mikosoft.net.
@ 86400 IN NS ns2.mikosoft.net.
@ 14400 IN A 52.28.170.2
@ 14400 IN MX 10 mail
@ IN TXT "v=spf1 a"@ IN SPF "v=spf1 a"
www 14400 IN A 52.28.170.2
mail 14400 IN A 52.28.170.2
ftp 14400 IN A 52.28.170.2
ns1 14400 IN A 52.28.170.2
ns2 14400 IN A 52.28.170.2
vps 14400 IN A 52.28.170.2
Necessarily: #service bind9 restart
3.1. Check BIND configuration
#named-checkconf /etc/bind/db.mikosoft.net - checks zone file
#named -g
4. Godaddy - Register new hostnames (DNS servers)
Edit domain mikosoft.net and add under hostnames field:
ns1.mikosoft.net
ns2.mikosoft.net
5. Check DNS record
#apt-get update && apt-get install dnsutils -instalira DIG i NSLOOKUP
Nakon toga
#dig www.adsoglasi.com #dig adsoglasi.com - provjera domene
#dig -x 158.255.211.66 - provjera IP adrese
#dig MX adsoglasi.com - provjera MXr ecorda
6. Reverse zone
Reverzna zona rješava koja će se web stranica (domena) prikazati ako utipkamo IP adresu u web browser. Također ovo je važno za neke servise kao npr. IRC...
U /etc/bind/named.conf.local dodati
//reverse zone
zone "211.255.158.in-addr.arpa" {
type master;
notify no;
file "/etc/bind/hostedzones/db.reverse";
};
U /etc/bind/hostedzones/db.reverse upisati:
;
; BIND reverse data file for local loopback interface
;
$TTL 604800
$ORIGIN 211.255.158.IN-ADDR.ARPA.
@ IN SOA ns1.ads-server.info. ads@ads.hr. (
2012031101 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns1.edis.at.
66 IN PTR ads-server.info.
Kada otvorimo http://158.255.211.66 treba se otvarati www.ads-server.info.
7. Misc config files
NAMED.CONF.OPTIONS
/etc/bind/named.conf.options sadrži opcije za BIND
Dodati:
forwarders {
# address of your provider's DNS server ns1.edis.at i ns2.edis.at
91.227.204.227;
91.227.205.227;
};
Ukoliko lokalni BIND ne može riješiti domenu koristit će se DNS server lokalnog provajdera. To su ovdje ns1.edis.at i ns2.edis.at .
RESOLV.CONF
Fajl resolv.conf govori koji nameserver će se koristiti. Ako fajla nema ili je prazan koristi se lokalni DNS server. Direktiva nameserver daje IP adresu nameservera koji će se koristiti.
Izmjeniti fajl /etc/resolv.conf u:
nameserver 158.255.211.66
nameserver 91.227.204.227
nameserver 8.8.8.8
91.227.204.227 je IP od edis.at dns servera
158.255.211.66 je IP od ads-server.info dns servera
8.8.8.8 je google public nameserver
HOSTS
/etc/hosts pridružuje IP adresi domenu i hostname.
Npr. ne možemo raditi #ping localhost ili #ping vps.ads-server.info dok ne stavimo u etc/hosts:
127.0.0.1 localhost.localdomain localhost
158.255.211.66 vps.ads-server.info vps
Jedan primjer gdje lokalni procesi mogu koristiti nazive maild, ircd, sshd
# Comments here
127.0.0.1 localhost localhost
68.23.41.6 mail.irc-scrappers.com maild scrappers
68.23.41.7 irc.irc-scappers.com ircd
68.23.41.8 ssh.irc-scrappers.com sshd
# End of /etc/hosts
HOST.CONF
/etc/host.conf govori na koji način se hostname pronalazi na mreži
order hosts,bind
multi on
nospoof on
Prema gornjoj konfiguraciji prvo se pretražuje po fajlu /etc/hosts , a nakon toga BIND.
multi on govori da hostname u hosts fajlu može imati više IP adresa. Po defaultu je ovo off.
8. DNS Records
MX RECORD
example.com MX 10 mail.example.com
Ovo omogućuje da ljudi koriste pero@example.com umjesto pero@mail.example.com
Svaki MX record mora imati odgovarajući A record
mail.example.com A 10.11.12.15
PROBLEMI
- Niti jedan mail record ne smije imati CNAME record npr.
mail.example.com CNAME smtp.example.com
- Mail record ne smije pokazivati na IP adresu npr.
example.com MX 10 158.255.211.66
CNAME RECORD (Canonical NAME)
news.mojadomena.com CNAME news.nije_moja_domena.com
CNAME omogućuje povezivanje mojedomene sa nekom drugom domenom. Kada se drugoj domeni (nije_moja_domena.com) promijeni IP adresa to neće uticati na news.mojadomena.com.
CNAME je najbolje izbjegavati.
Ne može postojati isti CNAME i A record.