> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Enable Accelerated Networking For Virtual Machines

### More Info:

Ensure that Accelerated Networking feature is enabled for your Azure virtual machines (VMs) in order to provide low latency and high throughput for the network interfaces (NICs) attached to the VMs. Accelerated networking enables single root input/output virtualization (SR-IOV) for virtual machines, vastly improving its networking performance. This high-performance pathway bypasses the host from the datapath, reducing latency, jitter and CPU utilization, so it can be used with the most demanding network workloads that can be installed on the supported VM types.

### Risk Level

Medium

### Address

Security

### Compliance Standards

* Cloudanix Best Practice

### Triage and Remediation

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the misconfiguration "Enable Accelerated Networking for Virtual Machines" in Azure using the Azure console, follow these steps:

        1. Log in to the Azure portal.
        2. Navigate to the Virtual Machine that needs to be configured.
        3. Click on the "Networking" option in the left-hand menu.
        4. Click on the "Enable" button next to "Accelerated Networking."
        5. Choose the appropriate network interface and click "Save."

        Once you have completed these steps, the Accelerated Networking feature will be enabled for the virtual machine.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To enable Accelerated Networking for Virtual Machines in Azure using Azure CLI, follow the below steps:

        1. Open the Azure CLI in your terminal or Azure Cloud Shell.

        2. Run the following command to check if Accelerated Networking is already enabled for the VM:

           ```
           az vm show -g <resource-group-name> -n <vm-name> --query networkProfile.networkInterface.id
           ```

        3. Once you have verified that Accelerated Networking is not enabled, run the following command to enable it:

           ```
           az vm accerated-networking enable -g <resource-group-name> -n <vm-name>
           ```

        4. Wait for a few minutes for the changes to take effect.

        5. Run the following command to verify that Accelerated Networking is enabled for the VM:

           ```
           az vm show -g <resource-group-name> -n <vm-name> --query "networkProfile.networkInterfaces[0].enableAcceleratedNetworking"
           ```

           If the output is "true", then Accelerated Networking has been successfully enabled for the VM.

        That's it! You have successfully remediated the misconfiguration by enabling Accelerated Networking for Virtual Machines in Azure using Azure CLI.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration of enabling Accelerated Networking for Virtual Machines in Azure using Python, you can use the Azure Python SDK. Here are the steps to follow:

        1. Install the Azure Python SDK by running the following command in your terminal:

        ```
        pip install azure-mgmt-compute
        ```

        2. Authenticate with Azure by creating a Service Principal and assigning it the Contributor role for the subscription. You can do this using the Azure CLI or the Azure Portal.

        3. Import the necessary modules in your Python script:

        ```python theme={null}
        from azure.common.credentials import ServicePrincipalCredentials
        from azure.mgmt.compute import ComputeManagementClient
        ```

        4. Set the credentials for the Service Principal:

        ```python theme={null}
        TENANT_ID = '<your-tenant-id>'
        CLIENT_ID = '<your-client-id>'
        CLIENT_SECRET = '<your-client-secret>'
        SUBSCRIPTION_ID = '<your-subscription-id>'

        credentials = ServicePrincipalCredentials(
            client_id=CLIENT_ID,
            secret=CLIENT_SECRET,
            tenant=TENANT_ID
        )
        ```

        5. Create a ComputeManagementClient object using the credentials:

        ```python theme={null}
        compute_client = ComputeManagementClient(
            credentials=credentials,
            subscription_id=SUBSCRIPTION_ID
        )
        ```

        6. Get a list of all the virtual machines in the subscription:

        ```python theme={null}
        vm_list = compute_client.virtual_machines.list_all()
        ```

        7. For each virtual machine, check if Accelerated Networking is already enabled. If not, enable it:

        ```python theme={null}
        for vm in vm_list:
            if vm.network_profile.network_interfaces:
                for nic in vm.network_profile.network_interfaces:
                    nic_obj = compute_client.network_interfaces.get(
                        nic.id.split('/')[4],
                        nic.id.split('/')[8]
                    )
                    if not nic_obj.enable_accelerated_networking:
                        nic_obj.enable_accelerated_networking = True
                        compute_client.network_interfaces.create_or_update(
                            nic.id.split('/')[4],
                            nic.id.split('/')[8],
                            nic_obj
                        )
        ```

        8. Save and run the Python script. This will enable Accelerated Networking for all the virtual machines in the subscription that do not have it enabled.

        Note: Make sure to test this in a non-production environment before implementing it in a production environment.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>
