Automatically configure multiple NICs on EC2 instances

Ubuntu instances running on AWS can be set up to automatically configure source routing on multiple NICs via cloud-init (starting with cloud-init v24.1). The configuration can be set up to occur on different events, such as:

  • First boot (enabled by default)

  • Subsequent boots

  • Hotplug NIC additions and removals

Note

On Ubuntu 24.04 LTS and newer, hot-plugged NICs are configured by default.

Enable configuration during instance creation

To enable network configuration on additional events, one can add supplemental cloud-init user-data at instance creation time:

#cloud-config
# apply network config on every hotplug event
updates:
  network:
    when: ['hotplug']

To specify multiple events use:

#cloud-config
# apply network config on every boot and hotplug event
updates:
  network:
    when: ['boot', 'hotplug']

To learn more about configuring instances using cloud-init, refer to cloud-init datasources and EC2 as a cloud-init datasource.

Enable configuration on running instances

To enable network configuration on hotplug events for already running instances, execute the following command on the instance:

$ cloud-init devel hotplug-hook -s net enable

This is a last resort command for administrators to enable hotplug on running instances. The recommended method to enable this is using user-data while creating the instance as described in the previous section. For more information about this command, see cloud-init’s CLI documentation.