Recommanded Free YOUTUBE Lecture: <% selectedImage[1] %>

Contents

SRV record

SRV(Service record)는 DNS(Domain Name System)에서 서비스의 위치(호스트네임 과 포트번호)를 저장하기 위해서 사용하는 레코드다. SIP(Session Initiation Protocol)과 XMPP(Extensible Messaging And Presence Protocol)등이 SRV레코드를 사용한다. 그 밖에 NginX와 HAProxy와 같은 프락시 소프트웨어들도 SRV를 사용한다.

레코드 형식

SRV 레코드 형식은 아래와 같다.
_service._proto.name. TTL class SRV priority weight port target.
  • service : http, mysql과 같은 서비스의 대표 이름.
  • proto : 서비스가 사용하는 전송 프로토콜(transport protocol). TCP나 UDP를 주로 사용한다.
  • name : 서비스를 위한 도메인 이름
  • TTL : DNS time to live 필드
  • class : DNS class 필드로 항상 IN이다.
  • priority : 호스트의 우선순위. 낮은 값이 우선순위가 더 높다.
  • weight : priority가 같을 때, 어느 호스트가 더 중요한지를 알려주기 위해서 사용한다. 값이 클 수록 더 중요하다.
  • port : 서비스를 찾기 위한 UDP 혹은 TCP 포트번호
  • target : 서비스를 찾기 위한 호스트 이름
아래는 실제 SRV 예제다.
_http._tcp.example.com.	86400	IN	SRV	0 100 8080 user01.example.com.
tcp 기반의 http 서비스로 user01.example.com 도메인으로 찾을 수 있다는 정보를 담고 있다. SRV는 서비스의 IP 정보를 담고 있지 않다. 그러므로 반드시 호스트 이름(이 경우 user01.example.com)에 대한 A, AAAA 레코드를 설정해야 한다.

고 가용성 서비스 구성

priority 필드를 이용해서 데이터 사용의 우선순위를 설정 할 수 있다. 클라이언트는 가장 낮은 priority를 가지는 SRV 레코드의 서비스의 연결을 시도한다. 만약 연결이 실패하면 높은 값의 레코드로 후퇴 한다. 서비스가 동일한 priority를 가지고 있을 경우 클라이언트는 weight필드의 값을 기준으로 로드밸런싱을 한다. 서비스 설계자는 priorityweight를 이용해서 로드밸런싱과 백업서비스 기능을 구현 할 수 있다.

아래 예제를 보자.
# _service._proto.name.  TTL   class SRV priority weight port target.
_http._tcp.example.com.   86400 IN    SRV 10       60     8080 bigbox.example.com.
_http._tcp.example.com.   86400 IN    SRV 10       20     8080 smallbox1.example.com.
_http._tcp.example.com.   86400 IN    SRV 10       10     8080 smallbox2.example.com.
_http._tcp.example.com.   86400 IN    SRV 10       10     8086 smallbox2.example.com.
_http._tcp.example.com.   86400 IN    SRV 20       0      8080 backupbox.example.com.
4개의 레코드의 priority 는 모두 10이다. 따라서 클라이언트는 weight 값에 따라서 연결할 서비스를 선택을 한다. Weight의 총합이 100이므로 bigbox.example.com을 대략 60%의 확률로 연결을 한다. smallbox1과 smallbox2가 나머지 요청을 20%씩 나눠서 처리한다. 만약 bigbox에 문제가 생긴다면 smallbox1과 smallbox2가 50%씩 나누어서 처리를 할 것이다. bigbox와 smallbox1, smallbox2 모두 서비스를 할 수 없다면, backupbox을 이용하게 된다.

SRV 레코드의 검색

dig(Domain Information Groper)과 nslookup으로 SRV 레코드 정보를 읽을 수 있다.
# dig _http._tcp.example.com SRV @127.0.0.1

; <<>> DiG 9.9.5-11ubuntu1.3-Ubuntu <<>> _http._tcp.example.com SRV @192.168.56.101
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 53013
;; flags: qr aa rd; QUERY: 1, ANSWER: 5, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1680
;; QUESTION SECTION:
;_http._tcp.example.com.		IN	SRV

;; ANSWER SECTION:
_http._tcp.example.com.	86400	IN	SRV	20 0 8080 backupbox.example.com.
_http._tcp.example.com.	86400	IN	SRV	10 10 8080 smallbox2.example.com.
_http._tcp.example.com.	86400	IN	SRV	10 10 8086 smallbox2.example.com.
_http._tcp.example.com.	86400	IN	SRV	10 20 8080 smallbox1.example.com.
_http._tcp.example.com.	86400	IN	SRV	10 60 8080 bigbox.example.com.

;; Query time: 0 msec
;; SERVER: 192.168.56.101#53(192.168.56.101)
;; WHEN: Mon Aug 01 00:26:25 KST 2016
;; MSG SIZE  rcvd: 253

# host -t SRV _http._tcp.example.com 127.0.0.1 
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases: 

_http._tcp.example.com has SRV record 10 10 8080 smallbox2.example.com.
_http._tcp.example.com has SRV record 10 60 8080 bigbox.example.com.
_http._tcp.example.com has SRV record 20 0 8080 backupbox.example.com.
_http._tcp.example.com has SRV record 10 10 8086 smallbox2.example.com.
_http._tcp.example.com has SRV record 10 20 8080 smallbox1.example.com.

# nslookup -query=srv _http._tcp.example.com 127.0.0.1
Server:		127.0.0.1
Address:	127.0.0.1#53

_http._tcp.example.com	service = 10 10 8080 smallbox2.example.com.
_http._tcp.example.com	service = 10 10 8086 smallbox2.example.com.
_http._tcp.example.com	service = 10 20 8080 smallbox1.example.com.
_http._tcp.example.com	service = 10 60 8080 bigbox.example.com.
_http._tcp.example.com	service = 20 0 8080 backupbox.example.com.

SRV를 사용하는 애플리케이션들

  • Powerdns
  • NginX : SRV를 이용해서 reverse proxy server를 만들 수 있다.
  • HAProxy : SRV를 이용해서 reverse proxy server를 만들 수 있다.
  • CalDAV와 CardDAV
  • DANE
  • DNS Service Discovery (DNS-SD)
  • Kerberos
  • LDAP
  • SMTP submission, POP, IMAP
  • XMPP
  • Puppet
  • IMPS
  • Minecraft
  • SIP
  • Teamspeak 3
  • XMPP