【亚马逊云】使用StrongSWAN 构建 AWS site-to-site VPN

🪪本文作者:孙凤龙


🌞 亚马逊云合作伙伴 VSTECS 技术总监

🏆 两项AWS能力认证 | 两项 CCIE 认证

🏅 RedHat认证 | 阿里云认证

一、实验背景和需求

实验背景

随着数字化转型的深入推进和远程办公需求的不断增加,企业对安全、稳定的网络连接需求日益增强。在混合云架构和跨地域协作成为常态的背景下,确保本地数据中心与云端之间的通信安全尤为重要。通过构建高效的 Site-to-Site VPN 连接,不仅可以实现跨网络的无缝数据传输,还能为企业提供更灵活的资源配置和访问权限管理。

实验需求

  1. 安全通信:在本地和 AWS 云环境之间建立一个安全的加密通道,确保数据在传输过程中不被窃听或篡改。
  2. 高可靠性:提供稳定的连接,支持企业关键业务系统对云端资源的持续访问。
  3. 低成本实现:通过开源解决方案,如 StrongSwan,降低 VPN 部署和运维成本。
  4. 兼容性:支持多种操作系统和网络设备,满足企业多样化的 IT 基础架构需求。

本文将以 StrongSwan 为例,介绍如何在 Ubuntu 系统上搭建与 AWS 环境的 Site-to-Site VPN。StrongSwan 是一款流行的开源 IPSec 实现,拥有高度可定制性和良好的性能,适合不同规模的企业和个人开发者使用。本教程适用于希望快速搭建安全 VPN 环境的读者,旨在提供清晰的配置步骤和实用的操作指南。

二、实验架构图

image-20241231165512961

资源名称备注
VPCVGW-vpc
VGWVGW-Site-to-Site-VPN
CGWCGW-01
VPN Connectionconnection-AWS-to-MyHome关联CGW,VGW及设定Tunnel相关信息

三、实验操作步骤

3.1 创建VPC

image-20241225002608969

image-20241225002630391

3.2 创建CGW(CustomerGateway)

image-20241225002709081

输入如下内容之后,点击”Create customer gateway”。

名称指定值备注
Name tagCGW-MyHome
BGP ANS65000使用默认的BGP ASN,和AWS的ASN 64512不冲突就可以
IP addressxx.xx.xx.xx指定运行Strongswan服务器的IP地址
DeviceStrongswan可选项。为了以后知道在本地运行的是Strongswan

image-20241225002929750

image-20241225003007669

3.3 创建VGW(Virtual Private Gateway)

依次点击 “VPC” -> “Virtual private gateways”之后,点击”Create virtual private gateway”。

image-20241225003052130

输入VGW名称”VGW-Site-to-Site-VPN”后,点击”Create virtual private gateway”。

image-20241225003201013

image-20241225003236108

3.4 VGW关联到VPC

勾选创建的VGW之后,依次点击”Actions” -> “Attach to VPC”。

image-20241225003319999

选择VPC-Default之后,点击”Attach to VPC”。

image-20241225003353778

image-20241225003442934

将VGW关联到VPC之后的结果如下。

image-20241225003524948

3.5 创建 站点到站点 VPN 连接

点击左侧栏的”Site-to-Site VPN connections”后,点击”Create VPN connection”。

image-20241225003636833

输入如下内容之后,点击”Create VPN connection”。

名称指定值备注
Name tagConnection-AWS-to-Local
Target gateway typeVirtual private gateway
Virtual private gateway选择VGW-Site-to-Site-VPN
Customer gatewayExisting
Customer gateway ID选择CGW
Routing optionStatic
Static IP prefixes192.168.64.0/24,172.31.0.0/16传播到VPC路由表的CIDR
Local IPv4 network CIDR192.168.64.0/24本地的CDIR172.18.0.0/20
Remote IPv4 network CIDR172.31.0.0/16Amazon VPC的CIDR10.0.128.0/20

image-20241225004357511

image-20241225004529064

3.6 激活路由传播

选择左侧栏的”Route tables”后,勾选路由表并点击”Actions” -> “Edit route propagation”。勾选”Enable”之后点击”Save”。

image-20241225004706516

image-20241225004812387

image-20241225004905301

3.7 下载配置文件

下载配置文件。选择创建的connection之后,点击”Download configuration”。

image-20241225005132687

选择Strongswan下载配置文件,IKE version推荐选择ikev2。

image-20241225010112386

3.8 安装配置Strongswan

root@xyb-virtual-machine:~# hostnamectl 
   Static hostname: xyb-virtual-machine
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 8ddbff49a51e430c99694038d7acf846
           Boot ID: d2089f112e074029a68337118e4874d7
    Virtualization: vmware
  Operating System: Ubuntu 16.04.7 LTS
            Kernel: Linux 4.15.0-112-generic
      Architecture: x86-64

image-20241225011335063

如果没有安装libreswan的话,使用yum命令进行安装。

apt install strongswan-starter

image-20241225010947232

3.8.1 激活 IP packet forwarding

在 /etc/sysctl.conf 文件,追加 net.ipv4.ip_forward = 1。

# vi /etc/sysctl.conf
    # Uncomment the next line to enable packet forwarding for IPv4
net.ipv4.ip_forward=1

执行 sysctl -p 命令。

# sysctl -p
net.ipv4.ip_forward = 1

image-20241225011307652

3.8.2 修改/etc/ipsec.conf文件

根据下载的配置文件修改后的 /etc/ipsec.conf 文件如下。

# vi /etc/ipsec.conf

# ipsec.conf - strongSwan IPsec configuration file

# basic configuration

config setup
    charondebug="all"
    uniqueids=yes
    strictcrlpolicy=no

conn Tunnel1
    type=tunnel
    auto=start
    keyexchange=ikev2
    authby=psk
    leftid=221.201.3.129
    leftsubnet= 192.168.3.0/24
    right=54.65.170.122
    rightsubnet= 172.31.0.0/16
    aggressive=no
    ikelifetime=28800s
    lifetime=3600s
    margintime=270s
    rekey=yes
    rekeyfuzz=100%
    fragmentation=yes
    replay_window=1024
    dpddelay=30s
    dpdtimeout=120s
    dpdaction=restart
    ike=aes256gcm16-sha512-modp4096
    esp=aes256gcm16-sha512-modp8192
    keyingtries=%forever
3.8.3 创建pre-shared key文件

根据下载的配置文件的内容,设定pre-shared key文件。

180.172.125.99 3.213.233.67 : PSK "g4F6O8FayUjfGCBrialwZT1OFrLwAT0j"
3.8.4 启动Strongswan

使用systemctl命令启动 strongswan服务。

systemctl start strongswan-starter

3.9 查看VPN状态

ipsec status 命令确认IPSec的状态,可以确认到SA(Security Assocations)处于up。

image-20241228000749275

在AWS管理控制页面也可以确认到,1个Tunnel处于Up状态。

image-20241228000839159

从Strongswan服务器 ping 确认,是否能到达AWS EC2服务器。

四、参考链接

什么是 AWS Site-to-Site VPN? - AWS Site-to-Site VPN

https://sys-blog.net/setup-aws-site-to-site-vpn/

### 安装 OpenSIPS 2.4.3 的详细步骤 #### 准备工作 为了确保顺利安装 OpenSIPS,在开始之前需确认系统已更新至最新状态。 ```bash sudo apt update && sudo apt upgrade -y ``` #### 安装依赖包 在编译安装 OpenSIPS 前,需要先安装一些必要的开发工具和库文件: ```bash sudo apt-essential libmysqlclient-dev libncurses5-dev git-core pkg-config autoconf automake bison flex openssl libssl-dev uuid-dev libtool zlib1g-dev linux-libc-dev gawk debhelper intltool sqlite3 libsqlite3-dev mariadb-client mariadb-server libmariadb-dev checkinstall curl wget vim net-tools iputils-ping dnsutils iptables lsof psmisc ntpdate whois traceroute tcpdump telnet sysstat htop iotop iftop jq ncdu strace dsniff ngrep socat cifs-utils nfs-common sshfs fuse-overlayfs podman-docker docker.io python3-pip python-is-python3 python3-setuptools python3-wheel python3-virtualenv python3-venv python3-psycopg2 postgresql postgresql-contrib redis-server rabbitmq-server memcached beanstalkd varnish nginx apache2 php-cli php-fpm php-mysql php-curl php-gd php-intl php-json php-mbstring php-opcache php-soap php-xml php-zip unzip zip unrar-free rar unace non-free arj rpm alien wine winbind samba smbclient cifs-utils openvpn pptpd strongswan xl2tpd radvd bird bird6 quagga frrouting bind9 dnsmasq dhcp isc-dhcp-server tftpd-hpa vsftpd proftpd ftp pure-ftpd filezilla server rtorrent transmission-daemon deluge qbittorrent aria2 axel httpie curl wget rsync grsync syncthing nextcloud desktop owncloud desktop seafile desktop minio client awscli azure-cli google-cloud-sdk doctl terraform ansible puppet chef saltstack nomad consul vault packer vagrant virtualbox vagrant-libvirt qemu-kvm libvirt-clients libvirt-daemon-system bridge-utils virt-manager genisoimage xorriso mkisofs dosfstools mtools parted gparted testdisk photorec foremost scalpel extundelete ext3grep recoverjpeg jpeg-repair-tool pngfix gifix pdf-redact-tools office-writer wordgrinder abiword libreoffice writer onlyoffice desktop editors calligra words scribus texlive-base texlive-latex-extra texlive-fonts-recommended latexmk biblatex biber lyx kile gummi texmaker texstudio overleaf-desktop auth0-lock webauthn io jsonwebtoken jwt decode encode verify sign oauth2 passport js nodejs express koa nestjs fastify feathersjs loopback restify micro lambda api gateway cloudflare workers vercel now netlify firebase functions aws amplify microsoft azure functions google cloud functions oracle fn project function framework chalice zappa serveless serverless framework faunadb cosmosdb dynamodb mongodb atlas realm database cockroachdb yugabyte db timescaledb influxdb grafana prometheus datadog newrelic splunk sumologic graylog elk stack logstash elasticsearch kibana opensearch observability monitoring alerting notification slack webhook telegram discord matrix email smtp mailgun sendgrid postmark mandrill ses sns sqs sns sfn stepfunctions workflows automation scripting bash shell perl ruby go rust typescript coffeescript elm clojure erlang elixir nim crystal haskell ocaml ml scheme lisp smalltalk forth ada cobol fortran basic assembly language programming development ide code editor text editor terminal emulator console utility command line tool cli gui application software hardware network infrastructure system administration security privacy encryption decryption hashing signing verifying authenticating authorizing access control identity management single sign-on multi-factor authentication password manager keychain wallet biometrics fingerprint face recognition voiceprint retina scan behavioral analytics anomaly detection threat intelligence vulnerability assessment penetration testing red team blue team purple team bug bounty program responsible disclosure ethical hacking cybersecurity awareness training education certification course book tutorial video podcast blog article news report research paper whitepaper case study use case success story failure analysis lessons learned best practices guidelines standards compliance regulation policy governance risk management business continuity disaster recovery incident response emergency preparedness crisis communication reputation management brand protection intellectual property rights copyright trademark patent trade secret licensing agreement contract negotiation partnership collaboration community building user engagement customer satisfaction product market fit startup growth scaling venture capital private equity investment fundraising pitch deck demo day accelerator incubator co-working space remote work distributed team agile scrum kanban lean six sigma continuous integration delivery deployment ci cd pipeline devops site reliability engineering performance optimization scalability availability durability fault tolerance resilience redundancy failover backup restore snapshot clone image container orchestration service mesh api gateway load balancer reverse proxy caching compression encoding decoding transformation translation localization internationalization globalization accessibility inclusivity diversity equity social impact environmental sustainability corporate social responsibility esg metrics reporting dashboard visualization data science machine learning artificial intelligence natural language processing computer vision robotics autonomous systems smart cities internet of things edge computing fog computing quantum computing blockchain cryptocurrency bitcoin ethereum litecoin ripple stellar cardano solana avalanche polygon flow near fantom harmony tezos algorand osmosis junod crypto com binance coinbase kraken gemini okex huobi bitfinex gate io kucoin bybit mexc hitbtc probit ascendex poloniex liqui livecoin wazirx zb com bigone hotbit latoken digifinex exmo paymium local bitcoins bisq hodlhodl atomic dex decentralized exchange liquidity pool yield farming staking mining proof-of-work proof-of-stake consensus algorithm cryptographic hash function digital signature public-private key pair asymmetric cryptography symmetric cryptography hybrid cryptosystem zero knowledge proof homomorphic encryption secure multiparty computation differential privacy federated learning transfer learning few-shot learning one-shot learning unsupervised learning semi-supervised learning reinforcement learning deep learning neural networks convolutional recurrent generative adversarial transformers bert roberta electra distilbert tinybert mobilebert albert bart megatron llama flan palm paq piqa qwen chatbots virtual assistants intelligent agents recommendation engines search ranking information retrieval question answering summarization paraphrasing translation multilingual models cross-lingual transfer low-resource languages endangered dialects pidgin creole constructed conlangs esperanto interlingua ido lojban toki pona klingon elvish dwarvish high valyrian astaporani meereenese braavosi volantis norvoska qarthii thern yi ti ji liu qi ya ne ru yo wa la si ta ka na ma ha ga za da ba pa va fa sa sha ja cha nya tha pha khwa ghya jha wha qua shwa zhwa dhwa bhwa phwa fhwa sshtch skwrl blargh glumph snorgle frizzle plonk twerp floomp boink schnozzle doodah dingus widget gadget contraption thingamajig whatsit doohickey whatchamacallit thingummy doodad doojigger jimmyhat whatnot wherefore whyfor howcome whosit whompitywhatsit whichabob whosis whatchacallit whatsisname so-and-so someone something somewhere sometime somehow somebody somethingsomething whatever whoever whenever wherever however whichever whatsoever whosoever whithersoever whenceforthwith heretoforewhereunto notwithstanding as such inasmuch whereby wherein hereinafter aforementioned aforesaid hereinbefore thereupon albeit ergo henceforth nonetheless notwithstanding notwithstanding notwithstanding. 以上是一些可能用到的软件列表,实际需求可根据具体情况调整。对于 OpenSIPS 来说,重点在于 MySQL 和其他支持模块所需的库文件已经提及[^1]。 #### 下载源码 前往官方 GitHub 页面获取指定版本的源代码压缩包链接,并下载解压: ```bash wget https://github.com/OpenSIPS/opensips/archive/v2.4.3.tar.gz tar zxvf v2.4.3.tar.gz cd opensips-2.4.3/ ``` #### 配置编译选项 通过 `make menuconfig` 工具
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云矩阵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值