Skip to content

Session Traversal Utilities for NAT

Session Traversal Utilities for NAT (STUN) is a standardized set of methods, including a network protocol, for traversal of network address translator (NAT) gateways in applications of real-time voice, video, messaging, and other interactive communications.

STUN is a tool used by other protocols, such as Interactive Connectivity Establishment (ICE), the Session Initiation Protocol (SIP), or WebRTC. It provides a tool for hosts to discover the presence of a network address translator, and to discover the mapped, usually public, Internet Protocol (IP) address and port number that the NAT has allocated for the application's User Datagram Protocol (UDP) flows to remote hosts. The protocol requires assistance from a third-party network server (STUN server) located on the opposing (public) side of the NAT, usually the public Internet.

Originally, STUN was an acronym for Simple Traversal of User Datagram Protocol (UDP) through Network Address Translators, but this title was changed in a specification of an updated set of methods published as RFC 5389, retaining the same acronym.

외부 네트워크 주소를 얻는데 사용되는 서버

About

  • 스턴(STUN) 서버는 공용 인터넷 망에 위치하며, 라우터의 NAT 뒤에 있는 피어(Peer)가 공인 IP 주소를 요청할 때 해당 주소를 확인하고 외부 망에서 접근 가능한 IP:PORT 정보를 알려주는 역할을 한다.
  • NAT 네트워크에 존재하는 피어(Peer)는 사설IP 를 가지므로 외부에 있는 WebRTC 피어와 통신할 수 없으므로, STUN 서버를 통해 공인 IP 주소(Public IP)를 알아 내고 P2P로 직접적인 연결을 하는데 방해되는 요소가 라우터 내에 있는지 알아낸다.
  • STUN 서버는 클라이언트가 공용 주소, 이면에 있는 NAT의 유형 및 NAT에 의해 특정 로컬 포트와 연결된 인터넷 측 포트를 찾을 수 있도록 해줍니다. 이 정보는 클라이언트와 VOIP 제공업체 사이의 UDP 통신을 설정하는 데 사용되며, 따라서 통화를 연결하는 데 사용됩니다. STUN 프로토콜은 RFC3489에 정의되어 있습니다.
  • STUN 서버는UDP 포트 3478에 연결되지만 서버는 클라이언트가 대체IP 및 포트 번호에서 테스트를 실행하도록 힌트를 제공합니다(STUN 서버에는 2개의 IP 주소가 있음). RFC에는 포트 및 IP가 임의적이라고 명시되어 있습니다.

Projects

Flow chart

Stun_flow_chart.png

STUN(RFC 5780)을 이용한 NAT Behavior Discovery

지난 시간과 마찬가지로 본 내용을 이해하기 위해서는 아래 블로그글을 반드시 먼저 읽어 보시기 바랍니다.

  1. NAT 장비는 이렇게 만들어야 하는데... (RFC 4787) - 1편: Mapping Behavior
  2. NAT 장비는 이렇게 만들어야 하는데... (RFC 4787) - 2편: Filtering Behavior
  3. STUN(RFC 3489)과 STUN(RFC 5389/5780)의 차이

Troubleshooting

stun:localhost is not connect

Firefox를 사용할 경우 Trickle ICE에서 coturn등을 사용해, stun:localhost로 접속할 경우 정상적으로 접속되지 않는다면 about:config 페이지에서 아래와 같이 수정한 후 테스트 해보자.

media.peerconnection.ice.no_host;true

자세한 사항은 Firefox#WebRTC Privacy 항목 참조.

만약 Edge를 사용할경우 Edge#WebRTC LocalHost IP Setting 항목 참조. 간단히, regedit의 Software\Policies\Microsoft\MicrosoftEdge\Main 경로 참조.

만약 Chrome을 사용할 경우 Chrome:WebRTC#localhost ICE 항목 참조. 간단히, chrome://flags/#enable-webrtc-hide-local-ips-with-mdns 플래그를 Disable로 변경.

WARNING

stun:localhost와 같은 Loopback 주소를 사용해선 안된다. 반드시 External IP (내부망일 경우 공유기 IP, e.g. stun:192.168.70.22)를 사용해야 한다. 그리고 접속할 주소도 http://localhost:9999와 같은 주소가 아닌, External IP (e.g.http://192.168.70.22:9999)를 사용해야 한다.

See also

Favorite site

Tutorials