登录到on-premise侧的实例(上面填写的public IP对应的那台)。安装libreswan:
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
进行安装:
sudo dnf --enablerepo=fedora install libreswan -y
安装完成后执行:
cat <<EoF >> /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.default.accept_source_route = 0
EoF
从VPN Connections里下载配置:
选择Openswan平台:
下载为一个txt文件,找到以下部分复制下来:
conn Tunnel1
authby=secret
auto=start
left=%defaultroute
leftid=18.236.88.223
right=34.223.135.144
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
在on-premise实例上创建一个aws.conf
:
touch /etc/ipsec.d/aws.conf
将上面的内容进行替换:
auth=esp
一行phase2alg=aes_gcm
、ike=aes256-sha1
on-premise
网段,rightsubnet配置为aws侧网段conn Tunnel1
authby=secret
auto=start
left=%defaultroute
leftid=18.236.88.223
right=34.223.135.144
type=tunnel
ikelifetime=8h
keylife=1h
phase2alg=aes_gcm
ike=aes256-sha1
keyingtries=%forever
keyexchange=ike
leftsubnet=172.31.0.0/16
rightsubnet=10.0.0.0/16
dpddelay=10
dpdtimeout=30
dpdaction=restart_by_peer
将上面的内容粘帖进/etc/ipsec.d/aws.conf
。
在下载的txt中找到以下部分并复制下来:
创建一个aws.secrets
文件,并粘帖进上面的内容:
/etc/ipsec.d/aws.secrets
启动ipsec.service
:
sudo systemctl start ipsec.service
sudo systemctl status ipsec.service
看到了创建完成了VPN Tunnel。检查AWS控制台,同样发现有一个Tunnel状态也正常了:
这里我们看到只Up了一个Tunnel,为什么Tunnel2没有Up呢?如果将这个txt往下拉,还会看到有Tunnel2的配置,这是因为我们只配置了Tunnel1,所以只活跃了一个。
最后我们进行on-premise侧实例与AWS侧实例的ping测试。但首先要更改下AWS侧VPC(10.0.0.0/16
)的路由表,添加一条路由:
0.0.0.0/0
=> VGW
添加0.0.0.0/0
=> VGW
的路由:
添加完成后,在On-premise实例ping AWS侧的实例,可以ping通: