I Tried IPv4 Communication from an IPv6-only EC2 Instance Using Cloudflare WARP

I Tried IPv4 Communication from an IPv6-only EC2 Instance Using Cloudflare WARP

Tested on an EC2 instance (Amazon Linux 2023) in a VPC limited to IPv6-only internet access via an Egress-Only Gateway. Cloudflare WARP's IPv4-over-IPv6 tunnel gave zero-fixed-cost IPv4 connectivity, and SSM worked too.
2026.01.10

This page has been translated by machine translation. View original

Starting February 1, 2024, AWS began charging for Public IPv4 addresses. The rate is $0.005/hour, which works out to about $3.6/address per month (30 days), a cost comparable to the monthly price of a t4g.nano (about $3.94).

On the other hand, as of January 2025, some AWS services, such as SSM (Systems Manager), are still offered over IPv4 only. To use these services from an EC2 instance without an IPv4 public address, you needed a NAT Gateway, VPC endpoints, or similar.

I had an opportunity to verify whether IPv4 communication is possible via a Cloudflare WARP tunnel (IPv4 over IPv6) even when omitting both the IPv4 public IP and the NAT Gateway, so I'll introduce it here.

Architecture Overview

The components of the environment built this time are as follows.

  • VPC: IPv4/IPv6 dual stack (however, IPv4 is private only, and the IGW is also omitted)
  • Egress-Only Internet Gateway: For IPv6 outbound traffic only
  • S3 Gateway Endpoint: Used as the S3 connection path for fetching packages from the official Amazon Linux 2023 repository and for temporarily storing the WARP RPM
  • EC2 Instance Connect Endpoint: Used as the SSH connection path from outside in an Egress-Only Gateway environment
  • Cloudflare WARP: Enables IPv4 over IPv6

Why Does This Configuration Work?

How Cloudflare WARP Works

Cloudflare WARP is a WireGuard-based VPN tunnel. It connects to Cloudflare over IPv6, and Cloudflare performs the conversion to IPv4, thereby achieving IPv4 over IPv6.

Environment Setup

Building the VPC (vpc-template.yaml)

I built a VPC with CloudFormation that includes the following resources.

  • VPC (IPv4/IPv6 dual stack)
  • 2 private subnets
  • Egress-Only Internet Gateway
  • S3 Gateway Endpoint
  • EC2 Instance Connect Endpoint
Full template
AWSTemplateFormatVersion: '2010-09-09'
Description: 'IPv6-only VPC Test - Complete private VPC with IPv6 connectivity'

Parameters:
  ProjectName:
    Type: String
    Default: 'ipv6-vpc-test'
    Description: 'IPv6-only VPC Test - Project name prefix for AWS resources'

Resources:
  # VPC
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: '192.168.0.0/18'
      EnableDnsHostnames: true
      EnableDnsSupport: true
      Tags:
        - Key: Name
          Value: !Ref ProjectName

  # IPv6 CIDR Block
  IPv6CidrBlock:
    Type: AWS::EC2::VPCCidrBlock
    Properties:
      VpcId: !Ref VPC
      AmazonProvidedIpv6CidrBlock: true

  # Private Subnets
  PrivateSubnet1:
    Type: AWS::EC2::Subnet
    DependsOn: IPv6CidrBlock
    Properties:
      VpcId: !Ref VPC
      CidrBlock: '192.168.0.0/20'
      AvailabilityZone: !Select [0, !GetAZs '']
      Ipv6CidrBlock: !Select [0, !Cidr [!Select [0, !GetAtt VPC.Ipv6CidrBlocks], 2, 64]]
      AssignIpv6AddressOnCreation: true
      Tags:
        - Key: Name
          Value: !Sub '${ProjectName}-private-subnet-1a'

  PrivateSubnet2:
    Type: AWS::EC2::Subnet
    DependsOn: IPv6CidrBlock
    Properties:
      VpcId: !Ref VPC
      CidrBlock: '192.168.16.0/20'
      AvailabilityZone: !Select [1, !GetAZs '']
      Ipv6CidrBlock: !Select [1, !Cidr [!Select [0, !GetAtt VPC.Ipv6CidrBlocks], 2, 64]]
      AssignIpv6AddressOnCreation: true
      Tags:
        - Key: Name
          Value: !Sub '${ProjectName}-private-subnet-1c'

  # Egress-Only Internet Gateway (IPv6)
  EgressOnlyInternetGateway:
    Type: AWS::EC2::EgressOnlyInternetGateway
    Properties:
      VpcId: !Ref VPC

  # Private Route Table
  PrivateRouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
      Tags:
        - Key: Name
          Value: !Sub '${ProjectName}-private-rt'

  # IPv6 Route (via Egress-Only IGW)
  PrivateRouteIPv6:
    Type: AWS::EC2::Route
    Properties:
      RouteTableId: !Ref PrivateRouteTable
      DestinationIpv6CidrBlock: '::/0'
      EgressOnlyInternetGatewayId: !Ref EgressOnlyInternetGateway

  # Subnet Associations
  PrivateSubnet1Association:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref PrivateSubnet1
      RouteTableId: !Ref PrivateRouteTable

  PrivateSubnet2Association:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      SubnetId: !Ref PrivateSubnet2
      RouteTableId: !Ref PrivateRouteTable

  # VPC Endpoint - S3
  S3Endpoint:
    Type: AWS::EC2::VPCEndpoint
    Properties:
      VpcId: !Ref VPC
      ServiceName: !Sub 'com.amazonaws.${AWS::Region}.s3'
      VpcEndpointType: Gateway
      RouteTableIds:
        - !Ref PrivateRouteTable

  # EC2 Instance Connect Endpoint
  EC2InstanceConnectEndpoint:
    Type: AWS::EC2::InstanceConnectEndpoint
    Properties:
      SubnetId: !Ref PrivateSubnet1
      SecurityGroupIds:
        - !Ref EC2InstanceConnectSecurityGroup
      Tags:
        - Key: Name
          Value: !Sub '${ProjectName}-eice'

  # Security Group for EC2 Instance Connect Endpoint
  EC2InstanceConnectSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Security group for EC2 Instance Connect Endpoint
      VpcId: !Ref VPC
      SecurityGroupEgress:
        - IpProtocol: tcp
          FromPort: 22
          ToPort: 22
          CidrIp: 192.168.0.0/18
      Tags:
        - Key: Name
          Value: !Sub '${ProjectName}-eice-sg'

Outputs:
  VPCId:
    Description: 'VPC ID'
    Value: !Ref VPC
    Export:
      Name: !Sub '${ProjectName}-vpc-id'

  PrivateSubnet1Id:
    Description: 'Private Subnet 1 ID'
    Value: !Ref PrivateSubnet1
    Export:
      Name: !Sub '${ProjectName}-private-subnet-1-id'

  PrivateSubnet2Id:
    Description: 'Private Subnet 2 ID'
    Value: !Ref PrivateSubnet2
    Export:
      Name: !Sub '${ProjectName}-private-subnet-2-id'

Preparing the WARP RPM

Since there was no official Cloudflare WARP repository for Amazon Linux 2023, I substituted the one for CentOS/RHEL8.
The WARP dependency packages (desktop-file-utils nftables nss-tools) were installed from the official Amazon Linux 2023 repository.
For the WARP itself, I downloaded the RPM for CentOS/RHEL8 from the Cloudflare download page, saved it to S3, and used it for installation.

Building the EC2 Instance (ec2-warp-launch-template.yaml)

I built an EC2 environment with CloudFormation that includes the following resources.

  • IAM role (for SSM + S3 access)
  • Security group (allows SSH from the EC2 Instance Connect Endpoint)
  • Launch Template (configures Cloudflare WARP via UserData)
  • EC2 instance (launched using the Launch Template)
Full template
AWSTemplateFormatVersion: '2010-09-09'
Description: 'Launch Template with Cloudflare WARP in IPv6-only VPC (ARM64 Optimized)'

Parameters:
  VpcId:
    Type: AWS::EC2::VPC::Id
    Description: 'VPC ID'

  SubnetId:
    Type: AWS::EC2::Subnet::Id
    Description: 'Subnet ID'

  InstanceType:
    Type: String
    Default: 't4g.micro'
    AllowedValues: ['t4g.nano', 't4g.micro', 't4g.small']
    Description: 'EC2 instance type (ARM64 only)'

  KeyPairName:
    Type: AWS::EC2::KeyPair::KeyName
    Description: 'EC2 Key Pair for SSH access'

  WarpRpmS3Uri:
    Type: String
    Description: 'S3 URI for WARP RPM'

  ImageId:
    Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
    Default: '/aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-arm64'
    Description: 'AMI ID for EC2 instance'

Resources:
  EC2Role:
    Type: AWS::IAM::Role
    Properties:
      RoleName: !Sub '${AWS::StackName}-ec2-role'
      AssumeRolePolicyDocument:
        Version: '2012-10-17'
        Statement:
          - Effect: Allow
            Principal:
              Service: ec2.amazonaws.com
            Action: sts:AssumeRole
      ManagedPolicyArns:
        - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
      Policies:
        - PolicyName: WarpS3Access
          PolicyDocument:
            Version: '2012-10-17'
            Statement:
              - Effect: Allow
                Action: s3:GetObject
                Resource: arn:aws:s3:::cloudflare-warp-temp/*

  EC2InstanceProfile:
    Type: AWS::IAM::InstanceProfile
    Properties:
      InstanceProfileName: !Sub '${AWS::StackName}-instance-profile'
      Roles:
        - !Ref EC2Role

  EC2SecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: 'Security group for WARP EC2 instance'
      VpcId: !Ref VpcId
      SecurityGroupEgress:
        - IpProtocol: -1
          CidrIpv6: '::/0'
          Description: 'All outbound traffic over IPv6'
        - IpProtocol: -1
          CidrIp: '0.0.0.0/0'
          Description: 'All outbound traffic over IPv4'
      Tags:
        - Key: Name
          Value: 'warp-ec2-sg'

  WarpLaunchTemplate:
    Type: AWS::EC2::LaunchTemplate
    Properties:
      LaunchTemplateName: !Sub '${AWS::StackName}-launch-template'
      LaunchTemplateData:
        ImageId: !Ref ImageId
        InstanceType: !Ref InstanceType
        KeyName: !Ref KeyPairName
        IamInstanceProfile:
          Arn: !GetAtt EC2InstanceProfile.Arn
        NetworkInterfaces:
          - DeviceIndex: 0
            SubnetId: !Ref SubnetId
            Ipv6AddressCount: 1
            Groups:
              - !Ref EC2SecurityGroup
        UserData:
          Fn::Base64: !Sub |
            #!/bin/bash
            # Install dependencies
            dnf install -y desktop-file-utils nftables nss-tools
            # Download and install WARP
            aws s3 cp "${WarpRpmS3Uri}" /tmp/cloudflare-warp.rpm
            rpm -ivh /tmp/cloudflare-warp.rpm
            # Start WARP service
            systemctl enable --now warp-svc
            for i in {1..30}; do warp-cli status &>/dev/null && break; sleep 2; done
            # Register and configure WARP
            script -q -c "yes | warp-cli registration new" /dev/null
            warp-cli mode warp
            # Exclude IPv6 from WARP tunnel (IPv4 only through WARP)
            warp-cli tunnel ip add-range ::/0
            warp-cli connect
            # Restart SSM agent
            systemctl restart amazon-ssm-agent

  WarpEC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      LaunchTemplate:
        LaunchTemplateId: !Ref WarpLaunchTemplate
        Version: !GetAtt WarpLaunchTemplate.LatestVersionNumber

Outputs:
  InstanceId:
    Description: 'EC2 Instance ID'
    Value: !Ref WarpEC2Instance
    Export:
      Name: !Sub '${AWS::StackName}-instance-id'

Key Points of the WARP Configuration

  • Since starting warp-svc can take several tens of seconds, I added a wait process
# WARPサービスの有効化・起動
systemctl enable --now warp-svc

# サービス起動待機(最大60秒)
for i in {1..30}; do warp-cli status &>/dev/null && break; sleep 2; done
  • When running warp-cli registration new, you are interactively asked to agree to the terms, but I handled this with a pseudo TTY
# WARPの登録
script -q -c "yes | warp-cli registration new" /dev/null
  • I configured a split tunnel so that IPv6 traffic is excluded from the WARP tunnel.
# IPv6をWARPトンネルから除外(IPv4のみWARP経由)
warp-cli tunnel ip add-range ::/0

Please check the official documentation and FAQ (https://developers.cloudflare.com/warp-client/known-issues-and-faq/ ) for Cloudflare WARP's terms of use and limitations before using it.

Verification

I verified by connecting via SSH through the EC2 Instance Connect Endpoint.

$ aws ec2-instance-connect ssh --instance-id i-xxxxxxxxxxxxx71f5 --region ap-northeast-1

Checking the WARP Status

$ warp-cli status
Status update: Connected
Network: healthy

Checking IPv6 Communication

$ curl -6 -s https://ipv6.icanhazip.com
2406:da14:xxxx:xxxx:xxxx:xxxx:848b:afaa

The global IPv6 address assigned to the EC2 instance was returned. This goes through the Egress-Only IGW.

Checking IPv4 Communication

$ curl -4 -s https://ipv4.icanhazip.com
104.xx.xxx.105

An IPv4 address owned by Cloudflare was returned. I was able to confirm that the WARP tunnel is functioning properly.

Checking the SSM Connection

After configuring WARP, I confirmed that SSM's "start-session" can be used.

$ aws ssm start-session --target i-xxxxxxxxxxxxx71f5 --region ap-northeast-1

Even on an EC2 instance with no public IPv4 address, NAT Gateway, or VPC endpoints (ssm, ssmmessages, ec2messages), I was able to connect using Session Manager.

SSM connection

Cost Comparison

Item EC2 Public IP NAT Gateway Cloudflare WARP
Fixed cost $0.005/hour (about $3.6/month) $0.062/hour (about $45/month) $0
EC2 data transfer (in) $0 $0 $0
EC2 data transfer (out) $0.114/GB $0.114/GB $0.114/GB
NAT Gateway processing - $0.062/GB -

Summary

I confirmed that even in a VPC environment that is IPv6-only and has no NAT Gateway, using Cloudflare WARP makes it possible to use services that require IPv4 communication, such as SSM.

For workloads that mainly use IPv6 communication and perform IPv4 communication for auxiliary purposes, especially low-spec instances, or cost-conscious development environments that take advantage of the t4g.small free tier extended through the end of 2026, IPv4 over IPv6 connectivity via WARP is effective.

However, Amazon Linux 2023 is not included among the operating systems supported by Cloudflare WARP, and support from either Cloudflare or AWS cannot be expected. For the configuration introduced here, I strongly recommend limiting it to test environments where service impact is not a concern, or to personal use.

In the future, I hope that AWS will officially provide a low-cost IPv4 over IPv6 mechanism, and that DualStack support will progress across services from various companies, including AWS, so that an environment practical with native IPv6 will be established.

https://dev.classmethod.jp/articles/access-ipv4-internet-from-ipv6-only-subnet-via-cloudflare-warp/

Share this article

AWSのお困り事はクラスメソッドへ