Skip to content

๐Ÿ”ฎ Learn how to configure AWS Site to Site VPN connection with Libreswan and Terraform!

Notifications You must be signed in to change notification settings

mushroom1324/aws-s2s-vpn-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AWS์—์„œ ํ•˜์ด๋ธŒ๋ฆฌ๋“œ ๋„คํŠธ์›Œํฌ๋ฅผ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด Site-to-Site VPN connection ๊ตฌ์„ฑ์„ ํ•ด์•ผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Site to Site VPN์€ VPC์™€ ์˜จํ”„๋ ˆ๋ฏธ์Šค ๊ฐ„์˜ ์—ฐ๊ฒฐ์„ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๊ณ , IPsec VPN ์—ฐ๊ฒฐ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

IPsec ์—ฐ๊ฒฐ์„ ํ•˜๋Š” ์ด์œ 

VPC์™€ ์˜จํ”„๋ ˆ๋ฏธ์Šค ๊ฐ„ ์ „์†ก์— ์žˆ์–ด์„œ Direct Connect๊ฐ™์€ dedicated connection์„ ๊ตฌ์„ฑํ•˜์ง€ ์•Š๋Š” ์ด์ƒ ํ•„์—ฐ์ ์œผ๋กœ Internet์„ ๊ฑฐ์ณ ํ†ต์‹ ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๊ธฐ์— ๋ฐ์ดํ„ฐ๋ฅผ ์•”ํ˜ธํ™”ํ•˜์—ฌ ๋„คํŠธ์›Œํฌ๋ฅผ ํ†ตํ•ด ์ „์†ก๋˜๋Š” ๋™์•ˆ ๋ฐ์ดํ„ฐ๊ฐ€ ๋„์ฒญ๋˜๊ฑฐ๋‚˜ ํƒˆ์ทจ๋˜์ง€ ์•Š๋„๋ก ๋ณดํ˜ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. IPsec์€ ๋ฐ์ดํ„ฐ ์•”ํ˜ธํ™”๋ฅผ ์ง€์›ํ•˜์—ฌ ์•ˆ์ „ํ•œ ๋ฐ์ดํ„ฐ ํ†ต์‹ ์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๋„์™€์ค๋‹ˆ๋‹ค.

์™œ Site-to-Site VPN์ด์–ด์•ผ ํ•˜๋Š”๊ฐ€

Site-to-Site VPN์€ AWS์—์„œ ์ œ๊ณตํ•˜๋Š” ๊ด€๋ฆฌํ˜• VPN ์„œ๋น„์Šค์ž…๋‹ˆ๋‹ค. High Availability๋ฅผ ์œ„ํ•ด ๋‘ ๊ฐœ์˜ ํ„ฐ๋„์„ ์ œ๊ณตํ•˜์—ฌ, ํ•˜๋‚˜์˜ ํ„ฐ๋„์ด ๋‹ค์šด๋˜์–ด๋„ ๋‹ค๋ฅธ ํ•˜๋‚˜์˜ ํ„ฐ๋„๋กœ ํŠธ๋ž˜ํ”ฝ์„ ์—ฐ๊ฒฐํ•  ์ˆ˜ ์žˆ๋„๋ก ๋„์™€์ค๋‹ˆ๋‹ค. ๋˜ํ•œ Site-to-Site VPN์„ ์‚ฌ์šฉํ•˜๋ฉด CloudWatch๋ฅผ ํ†ตํ•ด ๋ชจ๋‹ˆํ„ฐ๋ง์ด ๊ฐ€๋Šฅํ•˜์—ฌ ๋‹ค์–‘ํ•œ ์‹œ๋‚˜๋ฆฌ์˜ค์—์„œ ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ…์„ ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์ ๋„ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ๊ด€๋ฆฌํ˜• ์„œ๋น„์Šค์ด๊ธฐ ๋•Œ๋ฌธ์— ๋งค๋‰ด์–ผํ•œ IPsec ๊ตฌ์„ฑ๋ณด๋‹ค ํ›จ์”ฌ ๊ฐ„ํŽธํ•˜๋‹ค๋Š” ์ ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

Site-to-Site VPN ์‹ค์Šต ํ™˜๊ฒฝ ๊ตฌ์ถ•

s2s1

AWS Network - Customer Network์˜ Site-to-Site VPN ์—ฐ๊ฒฐ์„ ๊ตฌ์„ฑํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ์„ ์œ„ํ•ด์„  ์‹ค์ œ Customer Network๊ฐ€ ํ•„์š”ํ•˜์ง€๋งŒ, ์ €ํฌ๋Š” ๋„์ฟ„ ๋ฆฌ์ „์— ์žˆ๋Š” EC2 ์ธ์Šคํ„ด์Šค๋กœ Customer Network๋ฅผ ํ‰๋‚ด๋‚ด์–ด ๊ตฌ์„ฑํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ์  ํ™˜๊ฒฝ ๊ตฌ์„ฑ์˜ ๊ฒฝ์šฐ ํ…Œ๋ผํผ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ๊ณต๊ฐœํ•ด ๋‘์—ˆ์œผ๋ฏ€๋กœ ์ด๋ฅผ ํ†ตํ•ด ์†์‰ฝ๊ฒŒ ๊ตฌ์„ฑ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

Routing Table

AWS Network์˜ Routing Table์—์„  ์ž์‹ ์˜ CIDR ๋ฒ”์œ„์ธ 10.0.0.0/16์˜ ๊ฒฝ์šฐ Local์„ ํ–ฅํ•˜๋„๋ก ํ•˜๊ณ , Customer Network์˜ CIDR ๋ฒ”์œ„์ธ 192.168.0.0/16์€ Vritual Private Gateway๋ฅผ ํ–ฅํ•˜๋„๋ก ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.

Customer Network์˜ Routing Table์—์„  ์ž์‹ ์˜ CIDR ๋ฒ”์œ„์ธ 192.168.0.0/16์˜ ๊ฒฝ์šฐ Local์„ ํ–ฅํ•˜๋„๋ก ํ•˜๊ณ , ๊ทธ ์™ธ์˜ ๋ชจ๋“  ๋ฒ”์œ„ 0.0.0.0/0์— ๋Œ€ํ•ด์„  Internet Gateway๋ฅผ ํ–ฅํ•˜๋„๋ก ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. Customer Network์˜ EC2-VPN์€ ์˜จํ”„๋ ˆ๋ฏธ์Šค ํ™˜๊ฒฝ์˜ ์—”๋“œํฌ์ธํŠธ์ธ Customer Router๋ฅผ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค. ์ด๋Š” ์ธํ„ฐ๋„ท์„ ๊ฑฐ์น˜๋„๋ก ๋ผ์šฐํŒ…์„ ๊ตฌ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Security Group

EC2-A์—์„œ๋Š” 192.168.0.0/16์˜ ICMP ํ”„๋กœํ† ์ฝœ์„ ํ—ˆ์šฉํ•˜์—ฌ, Ping ํ…Œ์ŠคํŠธ๋ฅผ ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.

ํ…Œ๋ผํผ์œผ๋กœ ๋ฆฌ์†Œ์Šค ๊ตฌ์„ฑํ•˜๊ธฐ

๋ ˆํฌ์ง€ํ† ๋ฆฌ ์†Œ์Šค ํŒŒ์ผ์„ ์ด์šฉํ•˜์—ฌ ๊ฐ„๋‹จํžˆ ์‹ค์Šต ํ™˜๊ฒฝ์„ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ทธ ์ „์— aws configure ๋ช…๋ น์–ด๋กœ ๋ฆฌ์†Œ์Šค๋ฅผ ์ƒ์„ฑํ•  ํ™˜๊ฒฝ์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กœํ•„ ์„ค์ •๊ณผ ๊ด€๋ จํ•œ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ๋Š” ๋‹ค์Œ ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”.

aws configure --profile s2s

profile ์˜ต์…˜์„ ์ง€์ •ํ•˜์—ฌ s2s ํ”„๋กœํ•„์— ์—‘์„ธ์Šค ํ‚ค ๊ฐ’์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กœํ•„ ์ง€์ • ํ›„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค:

terraform init
terraform apply
s2s2

์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์˜€๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ฒฐ๊ณผ๋ฅผ ๊ธฐ๋Œ€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ…Œ๋ผํผ์œผ๋กœ ํ™˜๊ฒฝ ๊ตฌ์„ฑ์„ ํ•˜๊ณ  ์‹ถ์ง€ ์•Š๊ณ , ์ง์ ‘ ๋ฆฌ์†Œ์Šค๋ฅผ ๋งŒ๋“ค๊ณ  ์‹ถ๋‹ค๋ฉด ๊ทธ๋ ‡๊ฒŒ ํ•˜์…”๋„ ์ข‹์Šต๋‹ˆ๋‹ค. ์ƒ๋‹จ ์ด๋ฏธ์ง€๋ฅผ ํ† ๋Œ€๋กœ ๋ฆฌ์†Œ์Šค๋ฅผ ์ƒ์„ฑํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

Site-to-Site VPN ์—ฐ๊ฒฐ ๋ฆฌ์†Œ์Šค๋ฅผ ์ •์˜ํ•˜๋Š” ๋ธ”๋Ÿญ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค:

# Site to Site VPN Connection
resource "aws_vpn_connection" "aws_vpn_connection" {
  provider            = aws.seoul
  vpn_gateway_id      = aws_vpn_gateway.aws_vpn_gateway.id
  customer_gateway_id = aws_customer_gateway.aws_customer_gateway.id
  type                = "ipsec.1"
  static_routes_only  = true

  local_ipv4_network_cidr  = aws_vpc.customer_vpc.cidr_block
  remote_ipv4_network_cidr = aws_vpc.aws_vpc.cidr_block

  tags = {
    Name = "${var.project_name}-${var.environment_aws}-vpn"
  }
}

# VPN Connection Route
resource "aws_vpn_connection_route" "aws_vpn_connection_route" {
  provider               = aws.seoul
  destination_cidr_block = aws_vpc.customer_vpc.cidr_block
  vpn_connection_id      = aws_vpn_connection.aws_vpn_connection.id
}

์—ฌ๊ธฐ์„œ static_routes_only ๋ฅผ false๋กœ ์ง€์ •ํ•˜๋ฉด BGP๋ฅผ ์ด์šฉํ•œ dynamic routing์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ตฌ์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, Customer Gateway์—์„œ BGP๋ฅผ ์ง€์›ํ•ด์•ผ ํ•˜๋ฏ€๋กœ, ํ•ด๋‹น ์‹ค์Šต์—์„  static_routes_only๋ฅผ true ๋กœ ์„ค์ •ํ–ˆ์Šต๋‹ˆ๋‹ค.

local_ipv4_network_cidr ์„ aws_vpc์˜ cidr๋กœ ์˜คํ•ดํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด์— ์ฃผ์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Site to Site VPN ์„ค์ • ํ›„, AWS ์ฝ˜์†”์„ ํ†ตํ•ด Customer VPC์˜ EC2์— ์‚ฌ์šฉํ•  VPN Configuration File์„ ๋‹ค์šด๋กœ๋“œํ•ฉ๋‹ˆ๋‹ค. ์ด ๋•Œ Vendor๋ฅผ Openswan์œผ๋กœ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค. (Libreswan์€ Openswan์˜ ํฌํฌ์ž…๋‹ˆ๋‹ค)

s2s3 s2s4

Configuration File ์˜ˆ์‹œ

์ด์ œ EC2์—์„œ Libreswan์„ ๊ตฌ์„ฑํ•ฉ์‹œ๋‹ค. AWS ๋งค๋‹ˆ์ง€๋จผํŠธ ์ฝ˜์†”์—์„œ Tokyo ๋ฆฌ์ „์˜ EC2(Customer EC2)๋กœ Instance Connect๋ฅผ ํ†ตํ•ด ์ ‘์†ํ•ฉ๋‹ˆ๋‹ค.

s2s5

Amazon Linux 2023๋ถ€ํ„ฐ๋Š” Openswan์„ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ง€์›ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์—, ์ถ”๊ฐ€์ ์ธ ์„ค์ •์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋จผ์ € ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  Libreswan์„ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ EC2์— ์ ‘์†ํ–ˆ๋‹ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด repo ํŒŒ์ผ์„ ์ƒ์„ฑํ•ด์ค๋‹ˆ๋‹ค.

sudo vi /etc/yum.repos.d/fedora.repo

๊ทธ ํ›„ ํŒŒ์ผ์—์„œ ๋‹ค์Œ์˜ ๋‚ด์šฉ์„ ๋ถ™์—ฌ๋„ฃ์Šต๋‹ˆ๋‹ค:

[fedora]
name=Fedora 36 - $basearch
#baseurl=http://download.example/pub/fedora/linux/releases/36/Everything/$basearch/os/
metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-36&arch=$basearch
enabled=0
countme=1
metadata_expire=7d
repo_gpgcheck=0
type=rpm
gpgcheck=1
gpgkey=https://getfedora.org/static/fedora.gpg
skip_if_unavailable=False

๋ถ™์—ฌ๋„ฃ์—ˆ๋‹ค๋ฉด ์ €์žฅ ํ›„ ๋‚˜์˜ต๋‹ˆ๋‹ค. (!wq ๋ช…๋ น์–ด๋‚˜ ZZ ๋ฅผ ํ†ตํ•ด ์ €์žฅ ํ›„ ์ข…๋ฃŒ๋ฅผ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค)

์ €์žฅํ–ˆ๋‹ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด Libreswan์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

sudo dnf --enablerepo=fedora install libreswan -y
s2s6

์„ค์น˜๊ฐ€ ์™„๋ฃŒ๋œ ๋ชจ์Šต

Libreswan์˜ ์„ค์น˜๋ฅผ ๋งˆ์ณค๋‹ค๋ฉด, systemctl configuration file์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

sudo vi /etc/sysctl.conf

ํ•ด๋‹น ํŒŒ์ผ ํ•˜๋‹จ์— ๋‹ค์Œ์˜ ๋ช…๋ น์–ด๋ฅผ ์ถ”๊ฐ€ํ•˜๊ณ  ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์ €์žฅํ•˜๊ณ  ๋‚˜์˜ต๋‹ˆ๋‹ค.

 net.ipv4.ip_forward = 1
 net.ipv4.conf.default.rp_filter = 0
 net.ipv4.conf.default.accept_source_route = 0

๊ทธ ํ›„ ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋ณ€๊ฒฝ์‚ฌํ•ญ์„ ๋ฐ˜์˜ํ•ฉ๋‹ˆ๋‹ค.

sudo sysctl -p

๋‹ค์Œ์œผ๋กœ, /etc/ipsec.conf ํŒŒ์ผ์„ ์—ด์–ด include /etc/ipsec.d/*.conf ์—”ํŠธ๋ฆฌ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

sudo vi /etc/ipsec.conf
s2s7

๋งˆ์ง€๋ง‰์ค„์— ์ œ๋Œ€๋กœ ์„ค์ •๋˜์–ด ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜์˜€์œผ๋ฏ€๋กœ ์ถ”๊ฐ€์  ์ž‘์—…์ด ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋งŒ์•ฝ #๋กœ ์ฃผ์„ ์ฒ˜๋ฆฌ๋˜์–ด ์žˆ๋‹ค๋ฉด ์ฃผ์„์„ ํ•ด์ œํ•ฉ๋‹ˆ๋‹ค.

์ด์ œ ๋ฏธ๋ฆฌ ๋‹ค์šด๋ฐ›์•˜๋˜ VPN Configuration File์˜ ์Šคํ…์„ ๋”ฐ๋ผ๊ฐ‘๋‹ˆ๋‹ค. 4๋ฒˆ๋ถ€ํ„ฐ ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

  1. Create a new file at /etc/ipsec.d/aws.conf if doesn't already exist:
sudo vi /etc/ipsec.d/aws.conf

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋‚ด์šฉ์„ ๋ถ™์—ฌ๋„ฃ์Šต๋‹ˆ๋‹ค. (๋ณธ์ธ์˜ configuration file ์•ˆ์˜ ๋‚ด์šฉ์„ ์ง‘์–ด๋„ฃ์Šต๋‹ˆ๋‹ค)

conn Tunnel1
	authby=secret
	auto=start
	left=%defaultroute
	leftid=18.176.25.8
	right=3.37.114.133
	type=tunnel
	ikelifetime=8h
	keylife=1h
	phase2alg=aes128-sha1;modp1024
	ike=aes128-sha1;modp1024
	auth=esp
	keyingtries=%forever
	keyexchange=ike
	leftsubnet=<LOCAL NETWORK>
	rightsubnet=<REMOTE NETWORK>
	dpddelay=10
	dpdtimeout=30
	dpdaction=restart_by_peer

๋ช‡๊ฐ€์ง€ ๋ฐ”๊ฟ”์•ผ ํ•  ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

  1. auth=esp ๋ผ์ธ์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค. ์ด๊ฑด Libreswan์—์„œ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  2. phase2alg ์„ aes_gcm ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.
  3. ike ์„ aes256-sha1 ๊ฐ’์œผ๋กœ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.
  4. LOCAL NETWORK๋Š” Customer Network์˜ CIDR ๊ฐ’์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. (192.168.0.0/16)
  5. REMOTE NETWORK๋Š” AWS Network์˜ CIDR ๊ฐ’์„ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค. (10.0.0.0/16)
conn Tunnel1
	authby=secret
	auto=start
	left=%defaultroute
	leftid=18.176.25.8
	right=3.37.114.133
	type=tunnel
	ikelifetime=8h
	keylife=1h
	phase2alg=aes_gcm
	ike=aes256-sha1
	keyingtries=%forever
	keyexchange=ike
	leftsubnet=192.168.0.0/16
	rightsubnet=10.0.0.0/16
	dpddelay=10
	dpdtimeout=30
	dpdaction=restart_by_peer

๋ชจ๋‘ ๋ณ€๊ฒฝํ•˜์˜€๋‹ค๋ฉด ์ €์žฅ ํ›„ ๋‚˜์˜ต๋‹ˆ๋‹ค.

  1. Create a new file at /etc/ipsec.d/aws.secrets if it doesn't already exist:
sudo vi /etc/ipsec.d/aws.secrets

ํŒŒ์ผ ์•ˆ์— ์—”ํŠธ๋ฆฌ๋ฅผ ์ง‘์–ด๋„ฃ์Šต๋‹ˆ๋‹ค. (๋ณธ์ธ์˜ configuration file ์•ˆ์˜ ๋‚ด์šฉ์„ ์ง‘์–ด๋„ฃ์Šต๋‹ˆ๋‹ค)

18.176.25.8 3.37.114.133: PSK "Ns2Of1Wv24955RX7jjFyhzpsXfN4MsKw"

์—ฌ๊ธฐ๊นŒ์ง€ ๋งˆ์ณค๋‹ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ipsec ์„œ๋น„์Šค๋ฅผ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค!

sudo systemctl start ipsec.service

๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด status๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sudo systemctl status ipsec.service
s2s8

ํ„ฐ๋„์ด ์ƒ์„ฑ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋กœ๊ทธ๊ฐ€ ์ถœ๋ ฅ๋œ๋‹ค๋ฉด ipsec ํ„ฐ๋„์ด ์ •์ƒ์ ์œผ๋กœ ์—ฐ๊ฒฐ๋˜์—ˆ์Œ์„ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

s2s9

AWS ๋งค๋‹ˆ์ง€๋จผํŠธ ์ฝ˜์†”์—์„œ๋„ ํ„ฐ๋„์ด UP์ธ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๋งˆ์ง€๋ง‰์œผ๋กœ Tokyo ๋ฆฌ์ „์˜ Customer Network ์ƒ์— ์žˆ๋Š” EC2์—์„œ AWS Network์˜ private ip๋กœ ์ ‘์†์ด ๊ฐ€๋Šฅํ•œ์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

ping <private-ip>
s2s10

ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ…

ํ„ฐ๋„์ด UP ์ƒํƒœ๋กœ ๋ฐ”๋€Œ์ง€ ์•Š๋Š” ๊ฒฝ์šฐ, sudo systemctl status ipsec.service ๋ฅผ ํ†ตํ•ด ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

  1. IKE_AUTH response rejected Child SA with TS_UNACCEPTABLE, no connection named "Tunnel1โ€

    • ์ด ๊ฒฝ์šฐ aws.conf ํŒŒ์ผ์— ์ž…๋ ฅํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์„ ํƒ์— ๋ฌธ์ œ๊ฐ€ ์žˆ์„ ํ™•๋ฅ ์ด ๋†’์Šต๋‹ˆ๋‹ค. ์˜ฌ๋ฐ”๋ฅธ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์กฐํ•ฉ์„ ์‚ฌ์šฉํ•˜์˜€๋Š”์ง€ ๊ฒ€ํ† ํ•˜๊ณ  sudo systemctl restart ipsec.service ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋‹ค์‹œ ์‹คํ–‰ํ•ด๋ณด์„ธ์š”.
    • journalctl -xe | grep pluto ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋” ์ž์„ธํ•œ ๋กœ๊ทธ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    s2s11
    • ์ €์˜ ๊ฒฝ์šฐ์—๋„ ํ•ด๋‹น ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด โ€˜modp1024โ€™๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ํŒŒ์•…ํ–ˆ์Šต๋‹ˆ๋‹ค.
  2. (๋ฆฌ์†Œ์Šค๋ฅผ ์ง์ ‘ ๊ตฌ์„ฑํ•˜์‹  ๊ฒฝ์šฐ) ํ„ฐ๋„์ด UP์ด์ง€๋งŒ Ping์ด ์‹คํŒจํ•˜๋Š” ๊ฒฝ์šฐ

    • AWS Network์˜ EC2์— ํ• ๋‹น๋˜์–ด ์žˆ๋Š” Security Group์ด Customer Network VPC์˜ CIDR์— ๋Œ€ํ•ด ICMP IPv4 All traffic๋ฅผ ํ—ˆ์šฉํ•˜๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
    • AWS Network์˜ Routing Table์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. Customer Network VPC์˜ CIDR ๋ฒ”์œ„๋Š” Virtual Private Gateway๋ฅผ ํ–ฅํ•˜๋„๋ก ์„ค์ •๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    • Customer Network์˜ Routing Table์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค. 0.0.0.0/0 ๋ฒ”์œ„์— ๋Œ€ํ•ด Internet Gateway๋ฅผ ํ–ฅํ•˜๋„๋ก ์„ค์ •๋˜์–ด ์žˆ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
    • VPC Flow log๋ฅผ ํ™œ์„ฑํ™” ํ•˜์—ฌ ๋”์šฑ ์ž์„ธํ•œ ํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ…์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

AWS Site to Site VPN - Libreswan ์—ฐ๊ฒฐ ์‹ค์Šต์„ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค. ์‹ค์Šต์„ ์™„๋ฃŒํ•˜์…จ๋‹ค๋ฉด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ๋ฆฌ์†Œ์Šค๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค:

terraform destroy

About

๐Ÿ”ฎ Learn how to configure AWS Site to Site VPN connection with Libreswan and Terraform!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages