Connecting to Azure IoT Hub using IPv6 devices
Introduction
This article introduces an approach to connect IPv6 devices to Azure IoT Hub.
Azure IoT Hub
Azure IoT Hub is a crucial component in the Internet of Things (IoT) ecosystem, designed to facilitate seamless communication between IoT devices and the cloud. It plays an indispensable role in connecting, monitoring, and managing large networks of IoT devices, making it a cornerstone for businesses across various industries. Azure IoT Hub not only ensures secure and reliable device-to-cloud and cloud-to-device communication but also provides features like device provisioning, scalability, and integration with Azure services, making it a fundamental tool for harnessing the power of IoT. For more details, please follow – Azure - IoT Hub documentation
Emergence of IPv6 IoT Devices
With the rapid proliferation of IoT devices, the need for a larger address space and improved network capabilities has led to the emergence of IPv6-enabled IoT devices. IPv6 provides a vastly expanded address pool, which is essential for accommodating the growing number of devices in IoT ecosystems. As IoT continues to evolve and diversify, the adoption of IPv6 for IoT device connectivity is becoming increasingly prevalent, ensuring that devices can connect and communicate efficiently and securely in a connected world.
Challenges
At this moment, some of the Azure services including Azure IoT Hub does not natively support IPv6 device connectivity or communication. However, this can be achieved by deploying an IPv6-to-IPv4 gateway that can bridge the gap between IPv6-enabled devices and Azure IoT Hub, facilitating communication and data exchange.
In the architectural flow mentioned below, our Nginx act as a proxy stream server which translates the IPv6 address to IPv4 address.
Architectural overview
Please note: The entire communication from device to IoT Hub happens over port 8883.
As shown in the above diagram, this setup involves below major Azure services:
- Public Azure load balancer with IPv6 frontend IP.
- Dual stack (IPv4 & IPv6 enabled) virtual machines as a load balancer’s backend.
- Nginx running as a streaming server on the virtual machines.
- IoT Hub enabled with private endpoints.
- Azure storage account enabled with private endpoints.
Resource deployment and configuration
Dual stack NIC
Dual stack network virtual machine
Standard SKU public IPv6 IP
Public Azure load balancer
For more details, please follow – Azure - Deploy an IPv6 dual stack application
Setting up Nginx stream server
Installing Nginx
Please note: We have used the Ubuntu, commands may be vary depending upon the OS flavour.
Configuring Nginx
Edit Nginx configuration:
Paste the following block:
Test the Nginx configuration:
Nginx reload for the latest configuration:
Verify the listening ports:
NSG configuration
Since the communication happens via Azure load balancer which is a layer 4 load balancer, the traffic initiated by IPv6 devices is forwarded as it is to VM by load balancer keeping the session intact.
Hence, we have to allow the traffic for devices on the NSG level. For more details, please follow – Azure - Create, change, or delete a network security group
Sample NSG rule
|
NSG rule parameter |
NSG rule value |
|
Source |
IP Addresses |
|
Source IP addresses/CIDR ranges |
Device IPv6 Address |
|
Source port range |
* |
|
Destination |
IP Addresses |
|
Destination IP addresses/CIDR ranges |
Nginx VM IPv6 Address |
|
Service |
Custom |
|
Destination port ranges |
8883 |
|
Protocol |
TCP |
|
Action |
Allow |
Route device messages to Azure storage
You can also leverage message routing feature of IoT Hub to route the messages to Azure storage account. Follow the document for the same – Azure - IoT Hub message routing
Validating entire setup
- Setup an Azure virtual machine with Public IPv6 address.
- Map the custom host entry for IoT Hub hostname:
- edit /etc/hosts
- add custom entry as mentioned below:
<lb_ipv6_fip> <iot_hub_hostname>
- Download the IoT Hub required certificates from – Azure Samples – IoT MQTT Sample - IoTHubRootCA
- Convert pem to crt file by using below command:
$ openssl x509 -outform der -in IoTHubRootCA.crt.pem -out IoTHubRootCA.crt - Trust the certificate:
$ cp IoTHubRootCA.crt /usr/local/share/ca-certificates/ $ sudo update-ca-certificates - Follow the guide to generate messages using sample code - Using MQTT to connect an IoT Hub with Python
- Install paho-mqtt client:
$ pip install paho-mqtt - Get the sample code from the same repo – Sample code
- Generate SAS token for your device by using following command:
$ az iot hub generate-sas-token -d <device_id> -n <hub_name> - Modify the sample code by adding below details:
- IoT Hub name
- Device ID
- SAS token
- Run the code i.e. python file.
- Observe the traffic in following ways:
$ tail –f /var/log/nginx/access.log $ tcpdump port 8883 Azure > IoT Hub > Metrics > Select metric as telemetry message sent
Published on:
Learn moreRelated posts
Routing options for VMs from Private Subnets
Virtual Machines deployed in Azure used to have Default Outbound Internet Access. Until today, this allows virtual machines to connect to...
Secure, High-Performance Networking for Data-Intensive Kubernetes Workloads
The intersection of Generative AI and cloud computing has been transforming how organizations build and manage their infrastructure. The deman...
Network Connectivity for RISE with SAP S/4HANA Cloud Private Edition on Azure
In this article, we will explore different ways to connect to RISE with SAP S/4HANA Cloud Private Edition deployment on Azure, guiding yo...
Optimize Azure Landing Zone with Azure Virtual Network Manager IP Address Management
Optimize Azure Landing Zone with Azure Virtual Network Manager IP Address Management What you will learn from this blog This blog explores how...
ExpressRoute Metro is now generally available!!
We are excited to announce general availability of ExpressRoute Metro, a new private connectivity architecture designed to enhance network res...
ExpressRoute guided configuration of multi-site circuits and connections is generally available
ExpressRoute guided experience for configuring multi-site resiliency circuits and connections is generally available in Azure public cloud. Th...
Manage NSG association on Subnets via Azure Policy
In this blog article, we will cover how to deny the creation of a subnet in a Virtual Network if the subnet does not have a Network Sec...
Effortless Private Endpoint Management in Azure Landing Zones: A Streamlined and Compliant Approach
1. Challenge In Azure Landing Zones, the network infrastructure, including components like VNET Gateways and ExpressRoute circuits, is part of...
Unlocking Secure VM Connectivity with Azure Bastion
In today’s digital landscape, where security breaches are an unfortunate reality, safeguarding sensitive data and infrastructure has become mo...
Use cases of Advanced Network Observability for your Azure Kubernetes Service clusters
Introduction Advanced Network Observability is the inaugural feature of the Advanced Container Networking Services (ACNS) suite bringing...