Is there a way to add an IP to a virtual machine without rebooting the virtual machine?
OnApp version 3.2
Yes, you can add an IP to a VM without rebooting the VM but it will require manually configuring the IP address on the VM and manually adding iptables and arptables rules to the hypervisor for proper routing. The following steps outline how to do this.
1- Add the additional IP address to the VM through the CP interface without rebooting the VM.
2- Manually configure the IP address as a secondary IP address on the interface the IP is linked to on the VM.
3- SSH into the hypervisor that the VM is running on and run the following command to get the iptables information for the primary IP of the VM. Replace $ip_address with the primary IP assigned to the VM interface
iptables -L --line-numbers -n | grep $ip_address
4-This will return something like the following
# iptables -L --line-numbers -n | grep 192.168.2.2
17 ACCEPT all -- 192.168.2.2 0.0.0.0/0 PHYSDEV match --physdev-in x06lo6hia4uqi8 --physdev-out app1
18 x06lo6hia4uqi8 all -- 0.0.0.0/0 18.104.22.168.2 PHYSDEV match --physdev-out x06lo6hia4uqi8
From this you will need to make a not of the physdev-in and physdev-out values in the ACCEPT line. In this case the physdev-in value is x06lo6hia4uqi8 (the VM interface name) and the physdev-out value is app1 (the appliance network interface name)
5- Once you know the VM interface name and the appliance network interface that it is linked to you can then add the iptables rules to the FORWARD chain for the new IP with the following commands. Replace $new_ip with the new IP address assigned to the VM, $vm_interface with the VM interface name from above and $appnet_interface with the appliance network interface
iptables -A FORWARD -s $new_ip -m physdev --physdev-in $vm_interface --physdev-out $appnet_interface -j ACCEPT
iptables -A FORWARD -d $new_ip -m physdev --physdev-out $vm_interface -j $vm_interface
So for this example if the new IP being added is 192.168.2.3 the commands would look like
iptables -A FORWARD -s 192.168.2.3 -m physdev --physdev-in x06lo6hia4uqi8 --physdev-out app1 -j ACCEPT
iptables -A FORWARD -d 192.168.2.3 -m physdev --physdev-out x06lo6hia4uqi8 -j x06lo6hia4uqi8
6- Once the iptables rules are in place you will also need to add a rule to arptables to get the routing set up properly. The command to add the arptables rule would look like the following
arptables -A FORWARD -s 192.168.2.3 --arpop 2 -j ACCEPT
7- If the VM was properly configured with the new IP address and the iptables/arptables rules have been properly added the new IP address should now be routing to the VM.