Deleting a network interface from a VM
A virtual machine supports up to eight network interfaces. You can delete network interfaces you no longer need on both stopped and running VMs.
Note
Still, you cannot delete a VM's network interface if it is the only one it has.
To delete a network interface from a VM:
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID>
command. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command for deleting a network interface from a VM:
yc compute instance detach-network-interface --help
-
Get a list of VMs in the default folder:
yc compute instance list
Result:
+----------------------+-----------------+---------------+---------+----------------------+ | ID | NAME | ZONE ID | STATUS | DESCRIPTION | +----------------------+-----------------+---------------+---------+----------------------+ | fhm0b28lgfp4******** | first-instance | ru-central1-a | RUNNING | my first vm via CLI | | fhm9gk85nj7g******** | second-instance | ru-central1-a | RUNNING | my second vm via CLI | +----------------------+-----------------+---------------+---------+----------------------+
Save the ID of the VM from which you want to delete a network interface.
-
Stop the selected VM if needed by specifying its ID:
Note
The feature of adding and removing network interfaces on running VMs is at the Preview stage. To access the feature, contact
support.yc compute instance stop <VM_ID>
-
Get a list of network interfaces for the selected VM by specifying its ID:
yc compute instance get <VM_ID>
Result:
... network_interfaces: - index: "0" mac_address: d0:0d:1a:**:**:** subnet_id: e2lrucutusnd******** primary_v4_address: address: 192.168.1.20 one_to_one_nat: address: 158.***.**.*** ip_version: IPV4 security_group_ids: - enpuatgvejtn******** - index: "1" mac_address: d0:1d:1a:**:**:** subnet_id: e2lpp96bvvgp******** primary_v4_address: address: 192.168.2.3 security_group_ids: - enpuatgvejtn******** - enpg8d2hqh1o******** - index: "2" mac_address: d0:2d:1a:**:**:** subnet_id: e2lv9c6aek1d******** primary_v4_address: address: 192.168.4.17 security_group_ids: - enpuatgvejtn******** - enpg8d2hqh1o******** ...
Save the number (the
index
field value) of the network interface you want to delete. -
Delete the network interface:
yc compute instance detach-network-interface \ --id <VM_ID> \ --network-interface-index <network_interface_number>
Where:
--id
: ID of the selected VM. Instead of the ID, you can use the--name
parameter to specify the VM name.--network-interface-index
: Previously saved number of the VM's network interface you need to delete.
Result:
... network_interfaces: - index: "0" mac_address: d0:0d:1a:**:**:** subnet_id: e2lrucutusnd******** primary_v4_address: address: 192.168.1.20 one_to_one_nat: address: 158.***.**.*** ip_version: IPV4 security_group_ids: - enpuatgvejtn******** - index: "1" mac_address: d0:1d:1a:**:**:** subnet_id: e2lpp96bvvgp******** primary_v4_address: address: 192.168.2.3 security_group_ids: - enpuatgvejtn******** - enpg8d2hqh1o******** ...
Use the detachNetworkInterface REST API method for the Instance resource or the InstanceService/DetachNetworkInterface gRPC API call.