Attaching a NIC to a VM

You can attach network interface cards (NICs) to a virtual machine (VM) of the same Net, placed in any Subnet of the same Subregion as the NIC. Attaching NICs to a VM partitions its network.

This action updates the state of the NIC from available to in-use. For more information, see About NICs > NICs Attachment to VMs.

The maximum number of NICs you can attach to a VM depends on the VM type used. For more information, see VM Types.

If you want to attach more than one NIC to a VM, a network interface configuration may be required depending on the chosen operating system (OS). This includes IP addressing and routing. You can configure the network interface directly on the OS level in the VM.

Linking a NIC to a VM Using Cockpit v2

  1. In the NICs dashboard, check the box of the NIC you want to link to a VM.
    The NIC is selected.

  2. Click IconLink Link to VM.
    The LINK VM dialog box appears.

  3. From the VM list, select the VM you want to link the NIC to.

  4. In the Device field, type the device index for the NIC link (between 1 and 7, both included).

  5. Click Link.
    The NIC is linked to the VM.

If you are linking a NIC to a running VM, the network interface may not automatically be configured inside the VM. Therefore, you must either restart the VM, or configure the network interface manually as follows:

  1. Connect to the VM. For more information, see Accessing Your VMs.

  2. Enable the network interface by typing the following command in a terminal of the VM:

    $ sudo ip link set NI_NAME up
  3. Configure the network interface using the Dynamic Host Configuration Protocol (DHCP) by typing the following command in a terminal of the VM:

    $ sudo dhclient NI_NAME

Linking a NIC to a VM Using OSC CLI

The LinkNic command attaches a network interface card (NIC) to a virtual machine (VM).
The interface and the VM must be in the same Subregion. The VM can be either running or stopped. The NIC must be in the available state. For more information, see Attaching a NIC to a VM.

Request sample
$ osc-cli api LinkNic --profile "default" \
    --NicId "eni-12345678" \
    --VmId "i-12345678" \
    --DeviceNumber 1

This command contains the following attributes that you need to specify:

  • DeviceNumber: The index of the VM device for the NIC attachment (between 1 and 7, both included).

  • DryRun: (optional) If true, checks whether you have the required permissions to perform the action.

  • NicId: The ID of the NIC you want to attach.

  • VmId: The ID of the VM to which you want to attach the NIC.

The LinkNic command returns the following elements:

  • LinkNicId: The ID of the NIC attachment.

  • ResponseContext: Information about the context of the response.

    • RequestId: The ID of the request.

Result sample
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "LinkNicId": "eni-attach-12345678"
}

Linking a NIC to a VM Using oapi-cli

The LinkNic command attaches a network interface card (NIC) to a virtual machine (VM).
The interface and the VM must be in the same Subregion. The VM can be either running or stopped. The NIC must be in the available state. For more information, see Attaching a NIC to a VM.

Request sample
$ oapi-cli --profile "default" LinkNic \
    --NicId "eni-12345678" \
    --VmId "i-12345678" \
    --DeviceNumber 1

This command contains the following attributes that you need to specify:

  • DeviceNumber: The index of the VM device for the NIC attachment (between 1 and 7, both included).

  • DryRun: (optional) If true, checks whether you have the required permissions to perform the action.

  • NicId: The ID of the NIC you want to attach.

  • VmId: The ID of the VM to which you want to attach the NIC.

The LinkNic command returns the following elements:

  • LinkNicId: The ID of the NIC attachment.

  • ResponseContext: Information about the context of the response.

    • RequestId: The ID of the request.

Result sample
{
  "ResponseContext": {
    "RequestId": "0475ca1e-d0c5-441d-712a-da55a4175157"
  },
  "LinkNicId": "eni-attach-12345678"
}

Attaching an FNI to an Instance Using AWS CLI

Before you begin: Install and configure AWS CLI. For more information, see Installing and Configuring AWS CLI.

To attach a FNI to an instance, use the attach-network-interface command following this syntax:

Request sample
$ aws ec2 attach-network-interface \
    --profile YOUR_PROFILE \
    --network-interface-id eni-12345678 \
    --instance-id i-87654321 \
    --device-index 2 \
    --endpoint https://fcu.eu-west-2.outscale.com

This command contains the following attributes that you need to specify:

  • (optional) profile: The named profile you want to use, created when configuring AWS CLI. For more information, see Installing and Configuring AWS CLI.

  • network-interface-id: The ID of the FNI to attach.

  • instance-id: The ID of the instance to which you want to attach the FNI.

  • device-index: The device index for the FNI attachment (between 1 and 7, both included).

  • endpoint: The endpoint corresponding to the Region you want to send the request to. For more information, see Installing and Configuring AWS CLI.

The attach-network-interface command returns the following element:

  • AttachmentId: The ID of the attachment operation.

Result sample
{
    "AttachmentId": "eni-attach-1234abcd"
}

The FNI is attached to the specified instance.

If you are attaching an FNI to a running instance, the network interface may not automatically be configured inside the instance. Therefore, you must either restart the instance, or configure the network interface manually as follows:

  1. Connect to the instance. For more information, see Accessing Your VMs.

  2. Enable the network interface by typing the following command in a terminal of the instance:

    $ sudo ip link set NI_NAME up
  3. Configure the network interface using the Dynamic Host Configuration Protocol (DHCP) by typing the following command in a terminal of the instance:

    $ sudo dhclient NI_NAME

Related Pages

Corresponding API Methods

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.