Last Updated: February 25, 2016
·
2.486K
· Lorin Hochstein

Manually configure a VM for OpenStack floating IP

Sometimes I need to manually launch a virtual machine but give it a floating IP as if it was handed out by OpenStack (using nova-network). This is for quick and dirty testing only.

Assume you have a virtual machine that has the IP address 10.40.1.101, and you want it to have the IP address 10.20.0.101. This is what you would do on the controller, assuming your public interface is eth3:

ip addr add 10.20.0.101/32 dev eth3
iptables -t nat -A nova-network-OUTPUT -d 10.20.0.101/32 -j DNAT --to-destination 10.40.1.101
iptables -t nat -A nova-network-PREROUTING -d 10.20.0.101/32 -j DNAT --to-destination 10.40.1.101
iptables -t nat -A nova-network-float-snat -s 10.40.1.101/32 -o eth3 -j SNAT --to-source 10.20.0.101

Note: Since OpenStack doesn't know you've handed out this IP, it may hand it out to another instance.