Anycast
Anycast
The same IP answers from multiple locations. Used in CDNs and DNS.
Anycast
The same IP answers from multiple locations. Used in CDNs and DNS.
Anycast is a network addressing method that simultaneously advertises (announces) a single IP address from multiple physical locations around the world. When a user sends a request to that IP, BGP (Border Gateway Protocol) routing automatically connects them to the network-wise closest server. Unlike Unicast (1:1), Anycast routes to the best 1 out of 1:N.
The core principle of Anycast is BGP routing. When multiple data centers advertise the same IP prefix (e.g., 1.1.1.0/24) to ISPs, each ISP's routers select the most optimal path based on criteria such as AS-path (the number of networks traversed), latency, and policy. As a result, users in Seoul are automatically routed to the Seoul data center, and users in New York to the New York data center.
A representative use case of Anycast is DNS services. Public DNS services such as Cloudflare's 1.1.1.1, Google's 8.8.8.8, and Quad9's 9.9.9.9 are all operated using Anycast. The single IP 1.1.1.1 responds from data centers in more than 300 cities around the world, achieving an average response time of 14ms or less. CDNs (Cloudflare, Akamai) also use Anycast to serve static content from edges close to the user.
Another strength of Anycast is DDoS defense. Even when attack traffic occurs, servers distributed around the world share and handle the traffic of their respective regions, so the load is not concentrated on a single server. If a server in a particular region goes down, BGP automatically reroutes traffic to other regions, ensuring service continuity.
# Anycast DNS 응답 서버 위치 확인
dig +short TXT whoami.cloudflare.com @1.1.1.1
# 결과: 응답한 Cloudflare 데이터센터 정보
# traceroute로 Anycast 경로 확인
traceroute 1.1.1.1
# 한국에서 실행 시 서울/도쿄 POP로 라우팅
# mtr로 실시간 경로 분석 (Linux)
mtr -r -c 10 1.1.1.1
# 여러 지역에서 Anycast 라우팅 테스트
# RIPE Atlas 또는 Cloudflare의 speed.cloudflare.com 활용
# BGP 경로 확인 (Looking Glass)
# https://lg.he.net 에서 1.1.1.0/24 조회
# 각 지역 ISP에서 보는 BGP AS-path 확인 가능
# DNS 쿼리 응답 시간 비교
dig google.com @1.1.1.1 | grep "Query time" # Cloudflare Anycast
dig google.com @168.126.63.1 | grep "Query time" # KT DNS (Unicast)
# Anycast 라우팅 변화 모니터링
watch -n 5 'dig +short TXT whoami.cloudflare.com @1.1.1.1'
import socket
import subprocess
import time
# Anycast DNS 응답 위치 확인
def check_anycast_location(dns_server="1.1.1.1"):
"""Cloudflare Anycast DNS가 응답하는 데이터센터 확인"""
import dns.resolver
resolver = dns.resolver.Resolver()
resolver.nameservers = [dns_server]
# Cloudflare의 whoami 서비스로 응답 위치 확인
answers = resolver.resolve("whoami.cloudflare.com", "TXT")
for rdata in answers:
print(f"응답 위치: {rdata}")
check_anycast_location()
# 여러 Anycast DNS 응답 시간 비교
def compare_anycast_dns():
"""주요 Anycast DNS 서비스 응답 시간 비교"""
dns_servers = {
"Cloudflare": "1.1.1.1",
"Google": "8.8.8.8",
"Quad9": "9.9.9.9",
"OpenDNS": "208.67.222.222"
}
for name, server in dns_servers.items():
start = time.time()
socket.create_connection((server, 53), timeout=2)
latency = (time.time() - start) * 1000
print(f"{name} ({server}): {latency:.2f}ms")
compare_anycast_dns()
# BGP 경로 길이 확인 (RouteViews API 활용 예시)
def check_bgp_path(prefix="1.1.1.0/24"):
"""특정 IP 프리픽스의 BGP 경로 정보 확인"""
import requests
# RIPEstat API 사용
url = f"https://stat.ripe.net/data/routing-status/data.json"
params = {"resource": prefix}
response = requests.get(url, params=params)
data = response.json()
if data.get("data"):
visibility = data["data"].get("visibility", {})
print(f"프리픽스: {prefix}")
print(f"전 세계 가시성: {visibility.get('v4', 0)}개 Peer")
# check_bgp_path("1.1.1.0/24")
# AWS Global Accelerator - Anycast IP 활용
resource "aws_globalaccelerator_accelerator" "example" {
name = "my-anycast-accelerator"
ip_address_type = "IPV4"
enabled = true
attributes {
flow_logs_enabled = true
flow_logs_s3_bucket = aws_s3_bucket.logs.bucket
flow_logs_s3_prefix = "global-accelerator/"
}
tags = {
Name = "Anycast-Accelerator"
}
}
# Anycast IP로 라우팅될 Listener 설정
resource "aws_globalaccelerator_listener" "https" {
accelerator_arn = aws_globalaccelerator_accelerator.example.id
protocol = "TCP"
port_range {
from_port = 443
to_port = 443
}
}
# 엔드포인트 그룹 (각 리전별 서버)
resource "aws_globalaccelerator_endpoint_group" "seoul" {
listener_arn = aws_globalaccelerator_listener.https.id
endpoint_group_region = "ap-northeast-2"
endpoint_configuration {
endpoint_id = aws_lb.seoul.arn
weight = 100
}
health_check_protocol = "HTTPS"
health_check_path = "/health"
}
resource "aws_globalaccelerator_endpoint_group" "tokyo" {
listener_arn = aws_globalaccelerator_listener.https.id
endpoint_group_region = "ap-northeast-1"
endpoint_configuration {
endpoint_id = aws_lb.tokyo.arn
weight = 100
}
}
# 출력: Anycast IP 주소 확인
output "anycast_ips" {
value = aws_globalaccelerator_accelerator.example.ip_sets[0].ip_addresses
}
"Cloudflare is Anycast-based, so it responds from more than 300 POPs around the world with a single IP, without any separate DNS configuration. Users in Korea are automatically routed to the Seoul POP, and users in the US to the closest US POP, which greatly reduces latency."
"Anycast uses BGP routing to advertise the same IP from multiple locations. When you send a request to 1.1.1.1, it is routed to the server with the shortest AS-path, that is, the network-wise closest server. It is widely used for DNS and CDNs, and it is also effective for DDoS defense because traffic is naturally distributed."
"When the Seoul region goes down, thanks to Anycast, BGP automatically reroutes traffic to Tokyo or Hong Kong. Failover happens within tens of seconds, without worrying about DNS TTL. If we use AWS Global Accelerator, our service can also get Anycast IPs."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
Anycast is mainly suited to UDP (DNS) or short TCP connections. If routing changes during a long TCP connection, the connection may be dropped. HTTP/3 (QUIC) and AWS Global Accelerator address this problem.
Anycast routes based on BGP paths, not physical distance. In some cases, traffic from Seoul is routed to a Hong Kong server. It may vary depending on ISP peering conditions.
Building Anycast requires your own AS number, PI (Provider Independent) IP addresses, and BGP peering at each data center. For most services, using Cloudflare or AWS Global Accelerator is the realistic option.
Best suited to short request/response exchanges such as DNS and CDN. If you need long-lived connections, use AWS Global Accelerator or Cloudflare Spectrum. Regularly verify routing paths with traceroute from multiple regions.