본문 바로가기
CS(Computer Science)/21) 기초컴퓨터네트워크

기초컴퓨터네트워크 07 (electronic mail - SMTP, POP3, IMAP)

by tonyhan18 2021. 6. 19.
728x90

=== electronic mail - SMTP, POP3, IMAP ===

Electronic Mail

  • 세가지 주요 구성요소

    • user agents
    • mail servers
    • simple mail transfer protocol: SMTP
  • User agent 그냥 사용자들

    • "mail reader"
    • composing, editing, reading mail messages
    • Outlook, Thunderbird, iPhone mail client
    • outgoing, incoming messages stored on server
  • Mail servers

    • mailbox contains incoming messages for user
  • Message queue of outgoing (to be sent) mail messages

  • SMTP protocol between mail servers to send email messages 메일을 보내는데 사용하는 프로토콜

    • client: sending mail server
    • "server": receiving mail serve

Electronic Mail: SMTP [RFC 2821]

  • TCP를 사용해서 이메일을 전송하고 포트번호 25번이다.
  • direct transfer : sending server to receiving server 직접전달하지 다른곳을 거치지 않는다.
  • three phases of transfer : 3단계로 메세지를 전송한다.
    • handshaking (greeting)
    • transfer of messages
    • closure
  • command/response interaction (HTTP와 유사) : 커맨드를 보내면 response하는 형태
    • commands: ASCII text
    • response: status code and phrase
  • messages must be in 7-bit ASCII

나중에 추가 데이터를 첨부하기 위해서 MIME(Multipurpose Internet Mail Extensions)을 사용한다.

Scenario: Alice sends message to Bob

  1. Alice uses UA (user agent) to compose message to bob@someschool.edu
  2. Alice's UA sends message to her mail server; message placed in
    message queue
  3. Client side of SMTP opens TCP connection with Bob's mail server
  4. SMTP client sends Alice's message over TCP connection
  5. Bob's mail server places the message in Bob's mailbox
  6. Bob invokes his UA to read message

Sample SMTP interaction

C(client): crepes.fr
S(server): hamburger.edu

S: 220 hamburger.edu
C: HELO crepes.fr
S: 250 Hello crepes.fr, pleased to meet you
section을 시작하는 부분으로 생각하면 된다.
C: MAIL FROM: alice@crepes.fr
S: 250 alice@crepes.fr... Sender ok
C: RCPT TO: bob@hamburger.edu
S: 250 bob@hamburger.edu ... Recipient ok
C: DATA
데이터를 보내겠다.
S: 354 Enter mail, end with "." on a line by itself
C: Do you like ketchup?
C: How about pickles?
C: .
.이 찍히면 메세지가 끝난다.
S: 250 Message accepted for delivery
C: QUIT
S: 221 hamburger.edu closing connection

Try SMTP interaction for yourself

telnet을 이용해서 직접 SMTP를 다루어 볼 수 있다.

nslookup -q=ms gmail.com : gmail의 서버주소를 알 수 있다.

입력 : telnet [servername] 25
see 220 reply from server : 220이 나오면 정상 작동한 것이다.

입력 : HELO [메일주소]
MAIL FROM: [보내는 주소]
RCPT TO: [받는 주소]
DATA
보낼 내용 적기, 엔터도 가능
QUIT commands : . 찍기
끝내기 : QUIT

SMTP: final words

  • SMTP uses persistent connections : 계속 연결되어 있다.
  • SMTP requires message (header & body) to be 7-bit ASCII(MIME으로 멀티미디어도 보낼 수 있다.)
  • SMTP server uses CRLF.CRLF to determine end of message 다음줄로 넘긴다.
    • CR: carriage return
    • LF: line feed
      한줄에 .만 찍으면 끝난다.
  • HTTP vs. SMTP
    • HTTP: pull(서버로 부터 받아옴), SMTP: push(서버로 보냄)
    • both have ASCII command/response interaction, status codes(404 NOT Found)
    • HTTP: each object encapsulated in its own response message
    • SMTP: multiple objects sent in multipart message

Mail message format


Mail message에도 format이 존재한다.
DATA는 header과 body로 나뉜다.

header lines는 SMTP에서 입력한것과 별개로 데이터속에도 삽입한다. 하지만 user agent에 따라서 나오는 부분도 나오지 않는 부분도 존재한다.

Body부분은 그냥 ASCII로 되어 있다.

Mail access protocols


SMTP는 메일서버에 메일을 전달하고 저장하는것까지만 담당한다.

메일을 서버로부터 가져오기 위해서는 mail access protocol을 써야 한다.

  • mail access protocol: retrieval from server
    • POP(110): Post Office Protocol [RFC 1939]: authorization(계정인증), download(메일 가져오기)
    • IMAP: Internet Mail Access Protocol [RFC 1730]: POP + features, including manipulation of stored messages on server(폴더에 저장)
    • HTTP: gmail, Hotmail, Yahoo! mail, etc. 그냥 웹을 이용해서 메일을 읽을수도 있다.

POP3 protocol


처음에는 개인정보를 잘 넣어주어야 한다.

인증이 완료되면 list(메일 리스팅 해라) retr(어떤 메세지를 읽겠다) dele(어떤 메세지를 지워라) quit(종료)

telnet [메일서버주소] 110
user [계정]
pass [비밀번호]

POP3 and IMAP

  • more about POP3

    • previous example uses POP3 "download and delete" mode : 다운로드 받고 지우는 모드
      • Bob cannot re-read e-mail if he changes client
    • POP3 "download-and-keep": copies of messages on different clients : 다운로드 받고 저장하는 모드
    • POP3 is stateless across sessions : 어떤 state를 기억하지 않는다.
  • IMAP

    • keeps all messages in one place: at server : state하다.
    • allows user to organize messages in folders : 폴더를 만들어 관리할 수 있다.
    • keeps user state across sessions : 유저가 보고 있는 폴더에서 시작한다.
      • names of folders and mappings between message IDs and folder name

2.4 DNS

DNS: Domain Name System

어떤 서비스에 접속하기 위해서는 IP address와 port 번호를 알아야 한다.

  • people: many identifiers
    • SSN, name, passport number
  • Internet hosts, routers
    • IP address (32 bit) - used for addressing datagrams

보통은 ip번호를 기억해서 host에 접속하지 않는다.

  • IP addresses are difficult to remember
    • e.g. 223.130.195.95

IP 주소와 연동된 Domain name이 존재한다.

  • Domain names are used to indicate an Internet host

  • People use domain names to access a web server

패킷을 보낼때는 domain name이 IP address로 바뀌어야 하는데 이때 사용하는게 DNS이다.

  • In order to send packets to the server, the IP address of the server is needed → a domain name needs to be translated to an IP address

우리가 처음에는 IP 주소를 모르기 때문에 domain name을 물어보는 곳이 DNS이다.

  • At first, your web browser doesn't know the IP address mapped
    to a domain name that you give.
  • The web browser should ask someone for the IP address
  • The domain name system is there for the purpose

DNS 서버이자 데이터베이스이다.

  • A distributed database

    • implemented in hierarchy of many name servers
  • Application-layer protocol

    • hosts and name servers communicate to resolve names
  • 다른 application의 목적을 달성하기 위해 보조적인 역활을 수행하는 application-layer protocol도 존재한다.

  • 엣지에다가 DNS를 설치하고 있다. 코어 라우터는 데이터 전송만하고 엣지에 모든 기능이 담겨있어야 한다는 철학이 담겨있다.

DNS: services and structure

  • DNS services

    • hostname to IP address translation
    • host aliasing(서버의 이름이 복잡해서 별명을 붙인다.)
      • canonical, alias names
    • mail server 도 별명이 존재한다.
    • load distribution : domain name과 IP address가 1:1 대응이 아닌경우 트래픽이 몰릴경우 그때그때마다 IP address를 다르게 주어서 분산해줌
      • replicated web servers: many IP addresses correspond to one name
  • DNS를 중앙에 하나만 두지 않는 이유

    • single point of failure : DNS 하나가 망가지면 전체가 작동을 안한다.
    • traffic volume : traffic 양이 굉장히 많음
    • distant centralized database : 거리문제
    • maintenance : 다른 DNS 수리중에도 작동할 수 있게
      → centralized DNS does not scale (결국 그 양이 감당하지 못해서 분산

DNS: a distributed, hierarchical database

Root DNS도 나누고... 끝 부분을 기준으로 DNS를 나누고... 기관마다 또 DNS를 나누고...

DNS: root name servers

local name server에 우선 물어본다. 만약 이 서버에 데이터가 존재하지 않으면 root name server 쪽으로 물어본다.

  • root name server
    • contacts authoritative name server(모르는 주소인 경우 하위 서버들을 반환) if name mapping not known
    • gets mapping
    • returns mapping to local name server

TLD, authoritative servers

  • top-level domain (TLD) servers : TLD 서버를 관리하는 회사들이 존재

    • responsible for com, org, net, edu, aero, jobs, museums, and all top-level country domains, e.g.:uk, fr, ca, jp, kr
    • Network Solutions maintains servers for .com TLD
    • Educause for .edu TLD
  • authoritative DNS servers

    • organization's own DNS server(s), providing authoritative
      hostname to IP mappings for organization's named hosts
    • can be maintained by organization or service provider

Local DNS name server

client가 처음 만나는 DNS 서버

  • does not strictly belong to hierarchy
  • each ISP (residential ISP, company, university) has one
    • also called "default name server"
  • host가 DNS query를 날리면, query는 local DNS server로 간다.
    • 최근에 name-to-address로 바꾼 내역의 캐쉬를 가지고 있다. (but may be out of date)
    • acts as proxy, forwards query into hierarchy

DNS name resolution example

  • host at cis.poly.edu 에 접속하려고 한다.
    IP address for gaia.cs.umass.edu 를 원한다.

처음 local에서 root로 root가 모르니 TLD로 TLD에서 받은 DNS로 가서 ip address를 구해온다.

  • 위의 방식을 iterated query 방식이라고 부른다
    • contacted server replies with name server to contact
    • "I don't know this name, but ask this server"

또는 위와 같이 root가 직접 TLD에 물어보고 TLD가 authoritative DNS에 물어보는 구조이다.

  • recursive query
    • puts burden of name resolution on contacted name server
    • heavy load at upper levels of hierarchy

이건 서버에 따라서 선택하는 방식이 다르다.

DNS: caching, updating records

새로운 mapping을 알게되면 caching을 하게 된다.

  • once (any) name server learns mapping, it caches mapping

    • cache entries timeout (disappear) after some time (TTL) : Time to Live 라고 해서 일정시간이 지나면 지워버린다. 왜냐하면 바뀔 수 있기 때문이다.
    • TLD servers typically cached in local name servers : local name server가 처음에는 root에 접속하고 TLD로 가지만 TLD는 캐쉬에 저장해 놓고 바로 TLD server로 가서 root의 traffic이 줄어든다.
      • thus root name servers not often visited
  • cached entries may be out-of-date (best effort name-to-address translation) : 캐쉬가 가지고 있는 문제가 구 데이터를 가지고 있는 경우이다.

    • if name host changes IP address, may not be known Internet-wide until all TTLs expire : TTL이 만료될때까지 인터넷 접속이 안될 수 있기 때문에 가끔은 캐쉬를 지우는 것이다.
  • update/notify mechanisms proposed as IETF standard

    • RFC 2136

DNS records

DNS는 RR format으로 데이터를 저장한다.

type에 따라서 name과 value가 달라진다.

  • type=A
    • name: hostname
    • value: IP address
  • type=NS
    • name: domain (e.g. foo.com)
    • value: hostname of authoritative name server for this domain
  • type=CNAME
    • name: alias name for some "canonical" (the real) name
    • value: canonical name
  • type=MX
    • value: name of mailserver associated with name : mailserver name을 저장한다.

nslookup [url]
위 방법으로 name과 ip address를 볼 수 있다.

nslookup -q=ns [url]
authoritative name server 을 확인할 수 있다.

nslookup -type=mx [이메일url]
메일 서버들을 확인할 수 있다.

DNS protocol, messages

  • query and reply messages, both with same message format

  • message header

    • identification : 쿼리마다 번호가 있다.
    • 16-bit number for query
    • reply to query uses same number
  • flags : 옵션값이 들어가 있다.

    • query or reply
    • recursion desired
    • recursion available
    • reply is authoritative

헤더의 questions 등등은 각각 몇개가 있는지 알려주는 갑이 저장되어 있다.

  • questions : 어떤 query
  • answers : response
  • authority : authoritative server 에 대한 정보
  • additional info : 도움이 될 법한 추가적인 정보

필드를 외울 필요는 없다.

Inserting records into DNS

DNS에 추가하는 방법

  • example: new startup "Network Utopia" 라는 회사가 추가
  • register name networkutopia.com at DNS registrar (e.g. Network Solutions)
    • provide names, IP addresses of authoritative name server (primary and secondary) : authoritative IP address, name을 저장
    • registrar inserts two RRs into .com TLD server
      • networkutopia.com, dns1.networkutopia.com, NS (NS 타입 저장)
      • dns1.networkutopia.com, 212.212.212.1, A (A 타입 저장)

메일서버도 존재한다면 함께 저장

  • create authoritative server type A record for www.networkutopia.com; type
    MX record for networkutopia.com
728x90