클라우드 aws gcp wireguard - 100-hours-a-week/16-Hot6-wiki GitHub Wiki
목적
로컬(Mac)에서 GCP 서버(10.0.100.1)와 AWS 서버(10.0.100.8)에 동시에 VPN 접속하고, 두 서버와 자유롭게 통신하고자 함.
기본 네트워크 구조
위치 | IP (WireGuard) | 역할 |
---|---|---|
로컬(Mac) | 10.0.100.3 | 클라이언트 |
GCP 서버 | 10.0.100.1 | 서버1 |
AWS 서버 | 10.0.100.8 | 서버2 |
각 서버 설정 요약
10.0.100.1
)
📍 1. GCP 서버 (wg0.conf
[Interface]
PrivateKey = (GCP 서버 private key)
Address = 10.0.100.1/24
ListenPort = 51820
PostUp = sysctl -w net.ipv4.ip_forward=1
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -o ens4 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT
PostDown = iptables -t nat -D POSTROUTING -o ens4 -j MASQUERADE
[Peer]
PublicKey = (로컬 public key)
AllowedIPs = 10.0.100.3/32
[Peer]
PublicKey = (AWS public key)
AllowedIPs = 10.0.100.8/32
10.0.100.8
)
📍 2. AWS 서버 (wg0.conf
[Interface]
PrivateKey = (AWS 서버 private key)
Address = 10.0.100.8/24
ListenPort = 51820
PostUp = sysctl -w net.ipv4.ip_forward=1; \
iptables -A FORWARD -i wg0 -j ACCEPT; \
iptables -A FORWARD -o wg0 -j ACCEPT; \
iptables -t nat -A POSTROUTING -o ens4 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; \
iptables -D FORWARD -o wg0 -j ACCEPT; \
iptables -t nat -D POSTROUTING -o ens4 -j MASQUERADE
[Peer]
PublicKey = (GCP public key)
AllowedIPs = 10.0.100.1/32
[Peer]
PublicKey = (로컬 public key)
AllowedIPs = 10.0.100.3/32
10.0.100.3
)
📍 3. 로컬(Mac) (wg0.conf
[Interface]
PrivateKey = (로컬 private key)
Address = 10.0.100.3/24
DNS = 8.8.8.8
[Peer]
PublicKey = (GCP 서버 public key)
AllowedIPs = 10.0.100.1/32, 10.1.0.0/16, 10.10.0.0/16, ...등등
Endpoint = <GCP public IP>:51820
PersistentKeepalive = 25
[Peer]
PublicKey = (AWS 서버 public key)
AllowedIPs = 10.0.100.8/32, 10.0.0.0/16
Endpoint = <AWS public IP>:51820
PersistentKeepalive = 25
문제 발생
문제 | 원인 |
---|---|
로컬 → GCP 핑 성공 | 정상 설정됨 (키/AllowedIPs/Endpoint 모두 OK) |
로컬 → AWS 핑 실패 | ❌ 로컬에 등록된 AWS 서버의 public key가 잘못되어 handshake 실패 |
AWS → 로컬 핑 실패 | ❌ wg0.conf 에 로컬의 public key가 없었거나 틀림 |
ping: Destination Host Unreachable |
핸드셰이크조차 되지 않은 상태 (라우팅 테이블에 경로 없음) |
해결 절차
-
AWS 서버에서 새로 키 생성
wg genkey | tee privatekey | wg pubkey > publickey
-
로컬
wg0.conf
에 AWS의 public key 반영[Peer] PublicKey = (정확한 publickey 입력) AllowedIPs = 10.0.100.8/32, 10.0.0.0/16
-
서버 측
wg0.conf
에도 로컬 public key 등록 -
각 서버와 로컬에서
sudo wg-quick down wg0 && sudo wg-quick up wg0
재시작 -
핑 재시도
ping 10.0.100.8 # → 반드시 성공해야 함