DNS etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
DNS etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

29 Mart 2020 Pazar

DNS Record Tipleri

A Record Nedir? - IPv4 İçindir
Açıklaması şöyle.
3.2. Multiple DNS Records
A domain name MUST NOT have multiple records that would cause an authorization check to select more than one record. See Section 4.5 for the selection rules.
Address Record anlamına gelir. IPv4 için kullanılır. Bir alan isminin hangi IP adresinde olduğunu belirtir. Kayıt şuna benzer.
sub1.domain.com A xxx.xxx.xxx.xxx
sub2.domain.com A yyy.yyy.yyy.yyy
Bazen host ismi yerine sadece @işareti konulabilir. Açıklaması şöyle.
@               A free standing @ is used to denote the current origin.
Kendi DNS Sunucuma Başka Bir Adres İçin A Record Koyarsam Ne Olur?
DNS Hiyerarşisi yazısına taşıdım.

AAAA Record Nedir? - IPv6 İçindir
A Record ile aynı işlevi görür. IPv6 için kullanılır. A kaydının 4 katı olmasının açıklaması şöyle.
the name AAAA for IPv6 address records is in reference to an IPv6 address (128 bits) being four times the size of an IPv4 address (32 bits).
CAA Record Nedir?
Açıklaması şöyle.
A CAA record is an optional DNS record that restricts which certificate providers are allowed to issue certificates for a domain.
Açıklaması şöyle.
You can't use a TXT record in place of a CAA record to limit which CAs are allowed to issue certs for your domain.
CName Nedir?
Bir başka record'a alias olarak tanımlanır. Açıklaması şöyle.
A CNAME record is like leaving a recording on an answering machine that tells you to call a different number. For example, you call 555-1111 and the message says, "Call 555-2222." In the same way, a CNAME record for www.example.com can point to www.yourdomain.com. When the DNS client looks up www.example.com and encounters the CNAME record, it restarts the DNS lookup process for www.yourdomain.com...as if it had been trying to look up www.yourdomain.com in the first place.
Örnek
Şu satır doğru. foo.example.com bir alias.
foo.example.com.        3600   IN      CNAME   bar.example.com.
bar.example.com.        3600   IN      A       192.0.2.1
Ancak şöyle olsaydı yanlış olurdu. foo.example.com bir alias ancak A record belli değil.
foo.example.com.        3600   IN      CNAME   bar.example.com.
foo.example.com.        3600   IN      A       192.0.2.1
Örnek
Şu satır yanlış. Çünkü CNAME DNS ismin yerine IP adresi kullanılıyor.
exodus.babeldat.com.    41  IN  CNAME   104.248.81.197.
Açıklaması şöyle
A CNAME must point to an entry that appears on the left: a name, not an IP address
MX Record Nedir?
DNS kayıtlarından bazıları MX ile belirtilir. Bu kayıtlar domain için e-posta sunucusunu verir. MX kayıtlarında sunucular için öncelik tanınabilir. Ancak bu tavsiye edilmiyor. Bir sunucu cevap verinceye kadar önceliği en küçük olan MX sunucusu denenir. Açıklaması şöyle
MX records are used according to priority value in the records.

The record with the lowest priority is used first, then the higher ones until one responds. If there are multiple records with the same priority, one is randomly selected (this is how you generally do load balancing if you have multiple mail servers accepting incoming connections).
...
So a sending server will only use secondary records if the primary server doesn't respond to its connection attempts, not if the primary server rejects the message.
Açıklaması şöyle
An MX record, which defines your mail host, specifies a named server as the destination for mail. The name in turn is resolved by an A or AAAA record. If you change the A record that the MX record refers to, that will change your mail server. If your MX record points to some mail server outside your domain, such as Microsoft's mail servers (as seems to be the case, per your question), then changing your A records will have no effect on it. Note that if you're using Wix's mail servers, closing your account with them will likely lose your email unless you manage to get it hosted somewhere else.
Backup MX Record
Açıklaması şöyle
Please also take a look at how Wikipedia explains the MX record and the backup MX record.

A senders mail server will deliver to a backup MX whenever a primary MX can't be reached. The backup MX will accept the mail and hold it in the their queue until the messages either expire or until they can be delivered the primary MX.
This removes the burden of queueing undelivered messages away from the sender and makes the queue managed by the recipient.
Nowadays backup MX records are most likely only necessary for planned maintenance and outages, but in the past it was much more common for systems to be online only intermittently. Domains would often make an agreement with the operators of a mail server with much better connectivity to use their server as the backup (when they couldn't operate their own) or their ISP would provide that as a service. Mail would be queued on the backup MX server (for much longer than most senders did) and whenever the primary MX server came online, delivery of all queued messages would be triggered (with the ETRN command). That would allow sites to run their own on-premise mail server, without being online 24x7 (on an expensive dial up connection).
Örnek
Şöyle yaparız
MX 10 serverA
MX 20 serverB
Örnek
Eğer domain için e-posta sunucusu yoksa kayıt şöyledir.
nomail.example.com. 86400 IN MX 0 "."
E-posta gönderirken kendi MX sunucumuza göndermemiz gerekir. MX olmayan bir sunucu röle yapmayı kabul etmez.

Örnek
E-posta almamak için şöyle yaparız
domain.example. IN MX 0 .
domain.example. IN TXT "v=spf1 -all"
_dmarc.domain.example. IN TXT "v=DMARC1; p=reject; aspf=s; adkim=s;"
Açıklaması şöyle
This indicates that inbound mail is not accepted (null MX), and that any mail sent from the domain should be rejected (SPF policy that lists no allowed senders + DMARC policy enforces From-header alignment).

Not : Bilgisayar isimleri artık rakam ile başlayabiliyor. Hatta sadece rakamlardan bile oluşabilir. Mesela http://9292.nl/ geçerli bir bilgisayar adıdır.

TXT Record Nedir?
TXT Record ile Sender Policy Framework gerçekleştirilir

Sender Policy Framework (SPF) Kavramı
Açıklaması şöyle
- SPF checks the mail arrived at your server directly from particular agreed authorised mail server(s) or mail relays.
Sender Policy Framework (SPF Record) - Türkçesi Gönderen Politika Çerçevesi imiş - TXT türünden bir kayıt (record) sayılıyor. Kendi e-posta sunucumuzdan bir e-posta gönderince, alan sunucu önce bu postanın spam olup olmadığını kontrol eder. Bu iş için bizim IP adresimizin ve e-posta sunucumuzun DNS'te SPF kaydı olup olmadığını kontrol eder. Eğer kayıt yoksa, e-posta reddedilir

Örnek
Kendi sunucumuz ve bizim adımıza e-posta göndermesini istediğimiz 3. ortaklar için SPF kaydı şöyle oluşturulur. Domain adımız contoso.com olsun. Burada txt kaydından sonra 'v=spf1 ..' şeklinde bir metin daha var.
thirdparty1.spf.contoso.com txt 'v=spf1 ... -all' # list their mail senders
thirdparty2.spf.contoso.com txt 'v=spf1 ... -all' # list their mail senders
spf.contoso.com txt 'v=spf1 ... -all'             # list your mail senders
contoso.com txt 'v=spf1 include:spf.contoso.com 
 include:thirdpart1.spf.contoso.com include:thirdparty2.spf.contoso.com -all'
Örnek
Bazen bu metin şöyle yazılıyor. Yani hem +a hem de +mx belirtiliyor. +a kısmının fazla olup olmadığı tartışılıyor
@              10800 IN TXT     "v=spf1 +a +mx -all"
DomainKeys Identified Mail (DKIM) Kavramı
Açıklaması şöyle
- DKIM checks that the mail was initially sent from a server with the correct key at some point and nobody played with the message body.. 
Açıklaması şöyle
DKIM protects the integrity and authenticity of email headers and body. Furthermore, DKIM can only validate an existing signature, but does not have a method to tell whether a message without a signature should be accepted or not.

27 Mart 2020 Cuma

DNS Hiyerarşisi

Giriş
DNS 1983 yılında tasarlanmış. Açıklaması şöyle.
Ultimately, the DNS system we still use today would be proposed in 1983.
Bu sistemde Parent DNS ve Root DNS kavramları var. Açıklaması şöyle.
DNS is a hierachy. DNS servers know either how to find a parent DNS server or how to find a list of the "root" servers.

If they find a parent DNS server they just ask it, and it asks its parent until it gets an authorative answer.

In most cases however, nameservers know the root nameservers, which in turn point them to the appropriate servers for the domain. (Or in some cases the appropriate server for the first part of the domain. This process is repeated until the domain name is resolved).
Root DNS Sunucuları
Bunlardan 13 tane var. Açıklaması şöyle
When we say DNS is hierarchical, what we mean is there is a set of root DNS servers which are responsible for, for example, turning .com into the .com nameservers, who will in turn answer how to get to google.com. The root DNS zone of the internet is composed of thirteen DNS server clusters. There are only 13 server clusters, because that’s all we can fit in a single UDP packet. Historically, DNS has operated through UDP packets, meaning the response to a request can never be more than 512 bytes.
Root DNS sunucularına fiziksel erişim kısıtlı. Açıklaması şöyle.
Root DNS servers operate in safes, inside locked cages. A clock sits on the safe to ensure the camera feed hasn’t been looped. Particularly given how slow DNSSEC implementation has been, an attack on one of those servers could allow an attacker to redirect all of the Internet traffic for a portion of Internet users. This, of course, makes for the most fantastic heist movie to have never been made.

Unsurprisingly, the nameservers for top-level TLDs don’t actually change all that often. 98% of the requests root DNS servers receive are in error, most often because of broken and toy clients which don’t properly cache their results. This became such a problem that several root DNS operators had to spin up special servers just to return ‘go away’ to all the people asking for reverse DNS lookups on their local IP addresses.

The TLD nameservers are administered by different companies and governments all around the world (Verisign manages .com). When you purchase a .com domain, about $0.18 goes to the ICANN, and $7.85 goes to Verisign.
DNS ve Cache'leme
Açıklaması şöyle
In reality a nameserver won't generally make all of these queries, because it will remember parts of it. IE the first time someone looks up any .com domain name, the DNS server they are using it will remember the nameservers (for 172800 seconds in this case), so it won't need to do another lookup. Similarly for all the more specific parts of the lookup.
Name Server'a Yeni Kayıt Ekleme
Açıklaması şöyle. Bir API aracılığıyla oluyor.
So if someone is registering example.com via Godaddy (or any registrar), Godaddy needs to (programmatically) get the nameservers for example.com entered into the ".com" nameserver. Similarly, if they are in AU, they need to enter the information into the ".com.au" space if they want to register "example.com.au" - and this would require an agreement with the people controlling the nameservers for ".com.au" space - which is why not all registrars can register all domains, and why getting new top level domains is such a process - they need to pay big money to register the TLD with the root nameservers.
Kendi DNS Sunucuma Başka Bir Adres İçin A Record Koyarsam Ne Olur?
Hiçbir şey olmaz. Çünkü kendi telefon rehberimi düzenlemekle aynı şeydir. Kimse benim DNS sunucumu sorgulamadığı için her şey normal çalışmaya devam eder. Sorgulama için izlenen adımlar şöyle. Benim sunucum recursive resolver veya root name server veya authoritative server olmadığı için kimse benim sunucuma soru sormaz.
1. You as the DNS client (or stub resolver) query your recursive resolver for www.example.com.
2. Your recursive resolver queries the </blockquote> for www.example.com.
3. The root name server refers your recursive resolver to the .com Top-Level Domain (TLD) authoritative server.
4. Your recursive resolver queries the .com TLD authoritative server for www.example.com.
5. The .com TLD authoritative server refers your recursive server to the authoritative servers for example.com.
6. Your recursive resolver queries the authoritative servers for www.example.com, and receives 1.2.3.4 as the answer.
6. Your recursive resolver caches the answer for the duration of the time-to-live (TTL) specified on the record, and returns it to you.
ISP Tarafından DNS Sorgusu Yönlendirme
Açıklaması şöyle. Burada biz bir başka DNS sunucusunu kullandığımızı sansak bile ISP'nin DNS'ine gideriz.
It is still possible and not uncommon though that your DNS query does not actually end at the DNS server you want to use but will still be handled by the ISP's DNS server. This can be done with a cheap redirection of all packets destined for port 53 to the ISP's DNS server. Enforcing the use of the ISP's DNS server is usually done if the ISP is ordered to block access to specific domains. But even without redirecting the ISP might be able to see what domains you query: DNS queries are by default not encrypted and thus visible to Deep Packet Inspection. When using DNS over HTTPS (DoH) or DNS over TLS (DoT) the ISP will no longer be able to intercept these DNS requests though, nor will it be able to see the content of the DNS queries. It can still determine the domains you visit from DPI on the web traffic itself though in most cases.
Deep Packet Inspection
Açıklaması şöyle.
Some ISP might also snoop at the traffic with Deep Packet Inspection (DPI) and might also block or delay traffic based on this. Some might also enforce an implicit proxy to modify the traffic. This is especially true in countries where the ISP is ordered to block specific sites. It happened also in the past that ISP injected their own advertisements in the traffic. Or mobile ISP where found to "enrich" the traffic to provide information about the client (like the phone number) to the final server in order to provide more targeted advertisements. Traffic modification is mostly impossible when HTTPS is used though, but blocking traffic will even work with HTTPS.
Domain name system security extensions - DNSSEC
Açıklaması şöyle
DNSSEC creates a secure domain name system by adding cryptographic signatures to existing DNS records. These digital signatures are stored in DNS name servers alongside common record types like A, AAAA, MX, CNAME, etc. By checking its associated signature, you can verify that a requested DNS record comes from its authoritative name server and wasn’t altered en-route, opposed to a fake record injected in a man-in-the-middle attack.

To facilitate signature validation, DNSSEC adds a few new DNS record types:

- RRSIG - Contains a cryptographic signature
- DNSKEY - Contains a public signing key
- DS - Contains the hash of a DNSKEY record
- NSEC and NSEC3 - For explicit denial-of-existence of a DNS record
- CDNSKEY and CDS - For a child zone requesting updates to DS record(s) in the parent zone.
Gerçek DNS sunucusu ile delegate eden DNS sunucusu aynı şifreleme algoritmasını kullanmalıdır.

Eğer sorgulayan DNSSEC seçeneğini kullanmazsa normal bir cevap alır. Açıklaması şöyle
DNSSEC is an extension of DNS in the sense that for a non validating resolver, answers are not different, even if the domain is DNSSEC enabled. So all return codes work in the same way.
Örnek
Şöyle yaparız. icann.org aslında DNSSEC kullanır ancak dig komutunda DNSSEC cevap istenmediği için NXDOMAIN cevabı veriyor. Eğer dig ile DNSSEC sonuçlarını da görmek istersek +dnssec seçeneği kullanılır
$ dig NS icann.org +short
b.icann-servers.net.
c.icann-servers.net.
ns.icann.org.
a.icann-servers.net.

$ dig @a.icann-servers.net does-not-exist-foobar.icann.org

; <<>> DiG 9.18.4 <<>> @a.icann-servers.net does-not-exist-foobar.icann.org
; (1 server found)
;; global options: +cmd
;; Sending:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38891
;; flags: rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
; COOKIE: 98228e9e0c5ef4e6
;; QUESTION SECTION:
;does-not-exist-foobar.icann.org. IN A

;; QUERY SIZE: 72

;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 38891
                                       ^^^^^^^^




16 Ocak 2020 Perşembe

DNS Metodları

Not:
Bazı IP-String veya String-IP dönüşümleri için DNS sunucusu gerekmez. Bu tür dönüşümler için IP-String Dönüşüm Metodları başlıklı yazıya göz atabilirsiniz.

DNS Nedir?
DNS verilen bilgisayar ismini IP adresine çevirir. DNS sunucularına IP adresleri ile erişiriz. Örneğin google dns sunucusunu IP adresi 8.8.8.8'dir.  Her DNS sunucusu bir zone ile ilgilidir. Master DNS, Slave DNS, Caching DNS gibi farklı çeşitleri olabilir.

DNS sunucuları genelde 53 numaralı port üzerinden UDP kullanır. Nadiren TCP kullanıldığı da olur. Açıklaması şöyle.
Normal DNS queries use UDP port 53, but longer queries (> 512 octets) will receive a 'truncated' reply, that results in a TCP 53 conversation to facilitate sending/receiving the entire query.
DNS sorgusunda her pakette tek bir soru olmalıdır. Aynı pakette A ve MX kaydı sorgulanamaz.

DNS isimleri büyük küçük harfe duyarlı değildir. Teknik dokümanlarda genelde küçük harf kullanılır.

DNS Kullanmak İstemezsek
Açıklaması şöyle
If one explicitly uses the IP address no DNS lookup is needed to access the server. Note though that most servers will not work if just accessed by IP address. It is pretty common that multiple domains are served on the same IP address. Thus the server also needs the domain name to find out which certificates to provide for HTTPS and which content to serve. If one just puts the IP address in the browser, the browser does not know which domain is meant and thus cannot provide this crucial information to the server.
DNS Over HTTP - DoH
2017 senesinde ortaya çıkan yeni bir öneri. Açıklaması şöyle
DNS over HTTPS (DoH) intends to solve the privacy concerns there are with unencrypted DNS
Firefox bir şekilde DoH destekliyor

DNS Over TLS - DoT
Bazıları DoT yönteminin DoH yöntemine göre daha avantajlı olduğunu söylüyor ancak sebebini anlamadım. Soru şöyle. DoT sorguları şifreli olarak TCP üzerinden 853 numaralı porta gönderir.
I've heard the argument against DNS-over-HTTPS that it is supposed to be a security nightmare for network defenders because it enables encrypted DNS over port 443, compared to DNS-over-TLS which goes through port 853.
DNS Sunucuları Arasında Senkronizasyon
Açıklaması şöyle
DNS also uses zone transfers (query type AXFR) to update other DNS servers with new records.
...
So your security audit should pay close attention to query type AXFR, and your DNS systems should only accept AXFR exchanges from specific IP addresses.
Açıklaması şöyle
Zone transfers always use TCP, due to zone transfers taking up >512 bytes by their very nature. (it would be a waste of bandwidth to begin with UDP at all)
Authoritative Name Server
whois komutu yazısına taşıdım.

TTL
TTL'in çok hızlı değiştirilmesi yöntemi malware (zararlı yazılım) tarafından kullanılıyor. Açıklaması şöyle. Flux akış demek.
This is called Fast Flux DNS Records. And it's usually how malware authors hide their infrastructure servers.
Hosts Dosyası
Windows'ta bazı IP'lerin DNS kullanılmadan çözümlenmesi istenirse c:\windows\system32\drivers\etc\hosts dosyası düzenlenebilir. Dosya şuna benzer
# 127.0.0.1       localhost
# ::1             localhost

Linux'ta ise /etc/hosts dosyası düzenlenebilir. Dosya şuna benzer
# ip           hostname
172.16.0.100   berry
DNS Header
Kod olarak şöyledir.
// DNS layer header's structure
struct dnsheader {
  unsigned short int query_id;
  unsigned short int flags;
  unsigned short int QDCOUNT;
  unsigned short int ANCOUNT;
  unsigned short int NSCOUNT;
  unsigned short int ARCOUNT;
};
dig komutu
dig komutu yazısına taşıdım.

A Record Nedir?
DNS Record Tipleri yazısına taşıdım.

AAAA Record Nedir?
DNS Record Tipleri yazısına taşıdım.

CName Nedir?
DNS Record Tipleri yazısına taşıdım.

MX Record Nedir?
DNS Record Tipleri yazısına taşıdım.

TXT Record Nedir?
DNS Record Tipleri yazısına taşıdım.

Ters DNS Nedir?
Ters DNS (Reverse DNS) verilen IP adresini sunucu ismine çevirir. Özellikle e-posta sunucuları tarafından kullanılır. Gönderilen e-postaların içine e-posta sunucusu kendi IP adresini ekler. Alıcı taraf IP adresini ters DNS sunucusunda sorgulayarak IP adresi ile e-posta adresini eşleştirmeye çalışır. İşlem başarılıysa e-postayı içeri alır, değilse dikkate almaz. Ters DNS, DNS standardının bir parçasıdır.

Ters DNS normal IP adresleri için çalışmayabilir. Ters DNS için getnameinfo() metodu kullanılır.

Örnek
Şöyle yaparız. Belirtilen string şeklindeki IP için tüm adresler bulunur. Daha sonra ilk adres için getnameinfo() çağrısı yapılır.
struct addrinfo *ai;
struct addrinfo hints = {
    .ai_flags = AI_NUMERICHOST,
    .ai_family = AF_UNSPEC,
};

int res = getaddrinfo(argv[1], NULL, &hints, &ai);
if (res) {
    fprintf(stderr, "%s: %s\n", argv[1], gai_strerror(res));
    return 1;
}

char node[NI_MAXHOST];
res = getnameinfo(ai->ai_addr, ai->ai_addrlen, node, sizeof node, NULL, 0, NI_NAMEREQD);
freeaddrinfo(ai);

if (res) {
    fprintf(stderr, "%s: %s\n", argv[1], gai_strerror(res));
    exit(1);
}
Ubuntu
DNS ayarlarını değiştirdikten sonra
sudo service network-manager restart yapmak gerekir.

Metin Domain İsmi veya Metin IP ile Bulma 
Bazı metodlar sadece IP donüşüm (address translation) yaparken, bazıları isim çözümlemesi (name lookup) yapar.

gethostbyaddr
gethostbyaddr yazısına taşıdım.

getaddrinfo - posix
getaddrinfo metodu yazısına taşıdım.

Java
InetAddress Sınıfı yazısına taşıdım.


C#
DNS Sınıfı yazısına taşıdım.

Sadece Metin Domain İsmi ile Bulma
Aşağıdaki metodların tamamı artık kullanılmamalıdır. Sadece eski kodlarda karşımıza çıkabildikleri için not aldım.

gethostbyname - superseded by getaddrinfo
gethostbyname yazısına taşıdım.

gethostbyname_r - superseded by getaddrinfo
gethostbyname statik bellek alanı kullandığı için kullanımı tavsiye edilmiyor. Bunun yerine gethostbyname_r kullanılabilir. Aşağıdaki örnekte hata kontrolü yok: Metoda geçilen hostbuf ve result parametrelerinin farkını ben de tam anlamadım.

string hostname = "myhost";
struct hostent hostbuf;
struct hostent *result;
int herr;

int tmplen = 1024;
char *tmp = malloc (tmplen);//tamponun büyüklüğünün yeterli olup olmadığını kontrol etmiyoruz
int hres = gethostbyname_r (hostname.c_str(),&hostbuf,tmp,tmplen,&result, &herr);

if (ret == 0 && result != NULL) //Hata yoksa
{

    char** pAddr = result->h_addr_list;
    while(*pAddr)
    {
        //(*pAddr)[0],(*pAddr)[1] ile ip adresini al
        ++pAddr;
    }
}
free(tmp);
   

Kendi Sunucumuzun İsmini Bulma
gethostname
Bu metod ile kendi sunucumuzun ismini bulabiliriz. Örnek:

Yukarıdaki örnekte 80 karakterlik yer ayrılmış. Ancak HOST_NAME_MAX macrosu kadar yer ayırmak yeterli. Böylece farklı platformlarda bile çalışan bir kod yazmış oluruz.

Java
InetAddress.getHostName() metodu ile yapılır.

C#
Environment.MachineName ile bulunabilir.

Kendi Sunucumuzun IP Adresini Bulma
Bir sunucunun birden fazla IP adresi olabilir!
C#
DNS sınıfı yazısına taşıdım.