Tất cả tài liệu

VPN Site-to-Site

    Cấu hình VPN Site-to-Site với strongSwan
    Cấu hình VPN Site-to-Site với strongSwan
    Updated on 05 May 2025

    Bài viết này hướng dẫn build thiết strongSwan để đấu nối VPN_S2S với dịch vụ VPN Site-to-site của FPT Smart Cloud.

    Cần đảm bảo các điều kiện sau:

    • VPNAAS trên trang Portal
    • Ubuntu 20.04 đã được download và cài đặt : strongSwan 5.9.14
    • Public IP, giảm độ phức tạp thì gắn trực tiếp vào VM, không dùng Floating IP
    • 1 VM Pfsense để phục vụ debug (Optional )

    Bước 1: Build strongSwan

    * Lưu ý: Để build strongSwan, chỉ tiến hành chọn cách 1.1 hoặc cách 1.2

    1.1: Build strongSwan 5.9.14 from source (tiến tới làm chủ công nghệ)

    • Trên Horizon ta tiến hành tạo VM từ image với các thông số keypair của user và network provider bất kì.
    • Cài đặt các gói sau:
    apt-get update
    apt-get install vim git wget traceroute ngrep net-tool gcc g++ libgmp-dev build-essential devscripts debhelper dh-make autoconf automake libtool checkinstall nmap curl
    • Download source strongSwan từ link sau:
    wget https://github.com/strongswan/strongswan/releases/download/5.9.14/strongswan-5.9.14.tar.gz
    tar -xzvf strongswan-5.9.14.tar.gz
    cd strongswan-5.9.14/
    • Tiến hành configure và make file cho source code:
    ./configure --prefix=/usr --sysconfdir=/etc
    make
    checkinstall

    1.2: Cài đặt strongSwan từ Repo

    apt-get update
    apt install strongswan strongswan-pki

    Bước 2: Cấu hình cho VPN Site-to-Site

    Truy cập và tạo VPN Site To Site trên trang https://console.fptcloud.com/

    - Tạo IPSec policy: file - Tạo IKE policy: file - Tạo Customer Gateway:

    +Remote private network: dãy Lan Subnet cần peering của Vyos

    +Remote IP public: IP public của Vyos file - Tạo VPN Connection:

    Với thông số "Pre-shared key" cần lưu lại để điền vào Vyos

    file

    Bước 3: Cấu hình cho strongSwan

    - Đăng nhập ssh vào Ubuntu theo key đã tạo ở trên

    - Đăng nhập ssh theo địa chỉ IP VM đã tạo với user là: "ubuntu"

    Cấu hình strongSwan VPN

    Chạy các lệnh sau( thay các tham số vào):

    Kiểm tra phiên bản strongSwan
    swanctl -v

    edit file sau /etc/ipsec.conf với mẫu:

    config setup
            charondebug="all"
            uniqueids=yes
    
    conn myvpn
        type=tunnel
        auto=start
        keyexchange=ikev2
        ike=aes256-sha256-modp2048
        keyingtries=%forever
        lifetime=3600s
        dpddelay=30s
        dpdtimeout=120s
        dpdaction=restart
        esp=aes256-sha256-modp2048
        left=103.145.79.22     //IP của StrongSwan
        leftsubnet=10.10.10.0/24 //Subnet của StrongSwan
        leftauth=psk
        right=203.29.19.45    // IP của đối tác
        rightsubnet=172.29.68.0/24 //Subnet của đối tác
        rightauth=psk
        authby=secret
        auto=start

    Edit file sau /etc/ipsec.secret với mẫu:

    # This file holds shared secrets or RSA private keys for authentication.
    103.145.79.22 203.29.19.45 : PSK "716bd2f1daa73b4121f4ce0ad1404ac9edf402ab990a04d533119d06"   // Pre-shared key
    # RSA private key for this host, authenticating it to any other host
    # which knows the public part.

    Lưu ý:

    • StrongSwan là một chương trình chạy nền trên Ubuntu, cần thêm enable multi-network trên CPU để đạt hiệu năng tốt nhất.

    • StrongSwan là một chương trình chạy nền trên Ubuntu, cần thêm enable firewall và routing để có thể kết nối.

    • Nếu lab trên Openstack của FCI thì phải add Static route trên router với Destination là IP của đối tác và nexthop là IP LAN của StrongSwan.