Updating the VM internal IP address
After you create a VM, you can update internal IP addresses of its network interfaces.
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder used by default is the one specified when creating the CLI profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also specify a different folder for any command using --folder-name or --folder-id. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.
-
See the description of the CLI command for updating the internal IP address of a VM network interface:
yc compute instance update-network-interface --help -
Get a list of VMs in the default folder:
yc compute instance listResult:
+----------------------+-----------------+---------------+---------+----------------------+ | 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 | +----------------------+-----------------+---------------+---------+----------------------+ -
Select
IDof the VM in question. -
Stop the selected VM.
-
Get a list of network interfaces for the VM by specifying its ID:
yc compute instance get <VM_ID>Result:
... network_interfaces: - index: "0" mac_address: d0:0d:24:**:**:** subnet_id: e2lpp96bvvgp******** primary_v4_address: address: 192.168.2.23 one_to_one_nat: address: 158.160.**.*** ip_version: IPV4 - index: "1" mac_address: d0:1d:24:**:**:** subnet_id: e2lrucutusnd******** primary_v4_address: address: 192.168.1.32 - index: "2" mac_address: d0:2d:24:**:**:** subnet_id: e2lv9c6aek1d******** primary_v4_address: address: 192.168.4.26 ...Save the
indexfield value, which is the number of the network interface you want to update the internal IP address for. -
Update the internal IP address of the selected VM network interface:
yc compute instance update-network-interface \ --id <VM_ID> \ --ipv4-address <internal_IP_address> \ --network-interface-index <network_interface_number>Where:
--id: VM ID.--ipv4-address: Internal IP address. Specify a new IP address or enterautoto assign it automatically.--network-interface-index: VM network interface number you saved earlier.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
To update the internal IP address of a VM network interface, add the
ip_addressparameter to thenetwork_interfacesection of the network interface you need in theyandex_compute_instanceresource configuration:resource "yandex_compute_instance" "vm-1" { ... network_interface { ... ip_address = "<internal_IP_address>" } }For more information about the
yandex_compute_instanceresource parameters, see the relevant provider documentation. -
Create the resources:
-
In the terminal, navigate to the configuration file directory.
-
Make sure the configuration is correct using this command:
terraform validateIf the configuration is valid, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
-
Apply the configuration changes:
terraform apply -
Type
yesand press Enter to confirm the changes.
Terraform will create all the required resources. You can check the new resources using the management console
. -
To update the internal IP address of a VM network interface, use the updateNetworkInterface REST API method for the Instance resource or the InstanceService/PrimaryAddress gRPC API call.