There was a problem loading the comments.

How to Change the IP Address of a Virtual Machine After a Network Change

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

How to Change the IP Address of a Virtual Machine

If your virtual machine has been moved to a different network or assigned a new IP address, you will need to update the network configuration inside the operating system.

Before making any changes, make sure you have the following information:

  • New IP address
  • Subnet mask or CIDR
  • Default gateway
  • DNS servers, if required

1. Check the Current Network Configuration

On Linux systems, you can check the current network configuration with:

 

ip addr
ip route

 

Identify the active network interface. Common interface names include:

 

eth0
ens18
ens3
enp1s0

 

2. Update the Network Configuration

The configuration method depends on the Linux distribution installed on your virtual machine

Debian and Debian-Based Systems Using /etc/network/interfaces

Check the current configuration:

 

cat /etc/network/interfaces

 

Edit the network configuration:

 

nano /etc/network/interfaces

 

Example configuration:

 

auto eth0
iface eth0 inet static
    address 192.0.2.10/24
    gateway 192.0.2.1

 

Replace the example IP address, CIDR, and gateway with the new network information assigned to your virtual machine

Do not change the interface name unless your server uses a different interface such as ens18, ens3, or enp1s0

 

Ubuntu Using Netplan

Check the available Netplan configuration files:

 

ls /etc/netplan/

 

Edit the Netplan configuration file:

 

nano /etc/netplan/*.yaml

 

Example:

 

network:
  version: 2
  ethernets:
    eth0:
      addresses:
        - 192.0.2.10/24
      routes:
        - to: default
          via: 192.0.2.1
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8

 

Apply the new configuration:

 

netplan apply

 

AlmaLinux, Rocky Linux, CentOS, and RHEL

Check the available NetworkManager connections:

 

nmcli connection show

 

Configure the new IP address:

 

nmcli connection modify "System eth0" ipv4.addresses 192.0.2.10/24
nmcli connection modify "System eth0" ipv4.gateway 192.0.2.1
nmcli connection modify "System eth0" ipv4.method manual

 

Apply the configuration:

 

nmcli connection up "System eth0"

 

Replace System eth0 with the actual connection name displayed by:

 

nmcli connection show

 

3. Verify the New IP Address

Check that the new IP address has been applied:

 

ip addr

 

Check the routing table and default gateway:

 

ip route

 

4. Test Connectivity

Test external network connectivity:

ping -c 4 1.1.1.1

Then test DNS resolution:

ping -c 4 google.com

 

Important

If you are connected to the virtual machine through SSH using the old IP address, your SSH connection may be lost immediately after applying the new network configuration.

We recommend performing network changes through the virtual machine's Console or VNC access. This allows you to regain access if the new network configuration is incorrect.


Share via
Did you find this article useful?  

Related Articles

© Ozonti Network LLC