title: How to Add an IP Address to a VM? created at: Fri Jul 19 2024 13:02:18 GMT+0000 (Coordinated Universal Time) updated at: Mon Feb 10 2025 16:44:57 GMT+0000 (Coordinated Universal Time) --- # How to Add an IP Address to a VM? The article contains instructions on how to manually add an IP address to servers with different operating systems. To add an IP address, you will need to edit the network interfaces file. You can do this using standard OS editors. For example, in the Linux OS family, you can use the *vi*, *nano*, etc. Example command to edit /etc/network/interfaces ```bash vi /etc/network/interfaces ``` # IPv6 settings ![media\_How%20to%20Add%20an%20IP%20Address%20to%20a%20VM\_/TzQusyU3BPjSAD-link-solid.svg](media_How%20to%20Add%20an%20IP%20Address%20to%20a%20VM_/TzQusyU3BPjSAD-link-solid.svg) To add an IPv6 address, you will need information about the network parameters. This information is available in the VM card: go to **Virtual Machines** → click on the VM name → **IP addresses** tab → **IPv6** tab → **Network parameters** button. ![Example parameters ](media_How%20to%20Add%20an%20IP%20Address%20to%20a%20VM_/OhpsV8u_TfQDFD-example-parameters.png) # AlmaLinux To assign an IP address: 1. Connect to the server via SSH with superuser permissions. 2. To assign an IPv4 address Specify the network settings in **/etc/sysconfig/network-scripts/ifcfg-<interface>** file, where <interface> is the name of the network interface. For example, /etc/sysconfig/network-scripts/ifcfg-eth0. Example of settings ```bash DEVICE=eth0 ONBOOT=yes BOOTPROTO=static IPADDR=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 ``` ``` Comments to the example DEVICE — interface name IPADDR — IP address NETMASK — network mask GATEWAY — gateway IP address To assign an IPv6 address Add IPv6 settings to the network interface file **/etc/sysconfig/network-scripts/ifcfg-<interface>**, where <interface> is the interface name. For example, /etc/sysconfig/network-scripts/ifcfg-eth0. Example of settings ``` ```bash IPV6INIT=yes IPV6ADDR=2001:0DB8::/64 IPV6_DEFAULTGW=2001:0DB8::1 ``` ``` Comments to the example IPV6ADDR — IPv6 address with network prefix IPV6_DEFAULTGW — gateway IP address ``` 1. Restart the NetworkManager software: ```bash systemctl restart NetworkManager ``` 1. Reconnect the network interface: ```bash nmcli device disconnect <interface> && nmcli device connect <interface> ``` ``` Comments to the command <interface> — name of the network interface ``` # CentOS To assign an IP address: 1. Connect to the server via SSH with superuser permissions. 2. To assign an IPv4 address ``` Specify the network settings in **/etc/sysconfig/network-scripts/ifcfg-<interface>** file, where <interface> is the name of the network interface. For example, /etc/sysconfig/network-scripts/ifcfg-eth0. Example of settings ``` ```bash DEVICE=eth0 ONBOOT=yes BOOTPROTO=static IPADDR=192.168.1.100 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 ``` ``` Comments to the example DEVICE — interface name IPADDR — IP address NETMASK — network mask GATEWAY — gateway IP address To assign an IPv6 address Add IPv6 settings to the network interface file **/etc/sysconfig/network-scripts/ifcfg-<interface>**, where <interface> is the interface name. For example, /etc/sysconfig/network-scripts/ifcfg-eth0. Example of settings ``` ```bash IPV6INIT=yes IPV6ADDR=2001:0DB8::/64 IPV6_DEFAULTGW=2001:0DB8::1 ``` ``` Comments to the example IPV6ADDR — IPv6 address with network prefix IPV6_DEFAULTGW — gateway IP address ``` 1. Restart the NetworkManager software: ```bash systemctl restart NetworkManager ``` # Debian, Ubuntu ![media\_How%20to%20Add%20an%20IP%20Address%20to%20a%20VM\_/uFgGxlqp8k7FBe-link-solid.svg](media_How%20to%20Add%20an%20IP%20Address%20to%20a%20VM_/uFgGxlqp8k7FBe-link-solid.svg) To assign an IP address: 1. Connect to the server via SSH with superuser permissions. 2. Specify the network settings in **/etc/network/interfaces**: To assign an IPv4 address ``` Example of settings ``` ```bash iface ens3 inet static address 192.168.2.100 netmask 255.255.255.0 gateway 192.168.2.1 auto ens3 ``` ``` Comments to the example ens3 — network interface address — IP address netmask — network mask gateway — gateway IP address To assign an IPv6 address Example of settings ``` ```bash iface ens3 inet6 static address 2001:0DB8:: netmask 64 gateway 2001:0DB8::1 auto ens3 ``` ``` Comments to the example ens3 — network interface address — IPv6 address netmask — subnet prefix length gateway — gateway IP address ``` 1. Restart the *networking* service: ```bash systemctl restart networking ``` # Assigning an IPv6 address in Windows ![media\_How%20to%20Add%20an%20IP%20Address%20to%20a%20VM\_/70ntvnW9pFAz-4-link-solid.svg](media_How%20to%20Add%20an%20IP%20Address%20to%20a%20VM_/70ntvnW9pFAz-4-link-solid.svg) 1. Connect to the virtual machine via VNC or SPICE. To do so, in VMmanager go to **Virtual machines** → click on the VM name → **VNC (SPICE)**. 2. Press Win + R and execute the command: ```bash ncpa.cpl ``` 1. Right-click on the network connection → **Properties**. 2. Check that **IPv6 (TCP/IPv6)** is enabled. Select it and click on **Properties**. 3. Enable the option **Use the next** **IPv6 address**. 4. Enter any IPv6 address from the subnet that VMmanager allocated for the server. 5. Specify the\*\* Subnet prefix length\*\* that VMmanager allocated for the server. 6. Specify the **Main gateway** of the physical network. 7. Click on \*\*OK \*\*to save the settings.