For the purposes of this example, the following networks are defined:
$ neutron net-list
+--------------------------------------+--------+-------------------------------------------------------+
| id | name | subnets |
+--------------------------------------+--------+-------------------------------------------------------+
| 3ff9b903-e921-4752-a26f-cba8f1433992 | net0 | cae5afad-217c-4e8b-8413-cdbce5214a5d 10.0.0.0/24 |
| 93c8ddfc-7baa-4667-a01c-dfbdf5d47f15 | public | ffcca46d-b3df-42db-a967-1068d8b158f5 192.168.200.0/24 |
+--------------------------------------+--------+-------------------------------------------------------+
Start by create an instance normally and assigning a floating ip
address:
$ nova boot --image centos-6-x86_64 --flavor m1.small \
--nic net-id=3ff9b903-e921-4752-a26f-cba8f1433992 \
--key-name lars webserver
$ neutron floatingip-create public
Created a new floatingip:
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| fixed_ip_address | |
| floating_ip_address | 192.168.200.6 |
| floating_network_id | 93c8ddfc-7baa-4667-a01c-dfbdf5d47f15 |
| id | 7b83c022-bd92-4176-9ac7-38624b91dc3b |
| port_id | |
| router_id | |
| tenant_id | 28a490a259974817b88ce490a74df8d2 |
+---------------------+--------------------------------------+
$ nova add-floating-ip webserver 192.168.200.6
Now create another floating ip address:
$ neutron floatingip-create public
+---------------------+--------------------------------------+
| Field | Value |
+---------------------+--------------------------------------+
| fixed_ip_address | |
| floating_ip_address | 192.168.200.7 |
| floating_network_id | 93c8ddfc-7baa-4667-a01c-dfbdf5d47f15 |
| id | c8846e61-6046-4c06-a9a3-d8122c388c63 |
| port_id | |
| router_id | |
| tenant_id | 28a490a259974817b88ce490a74df8d2 |
+---------------------+--------------------------------------+
We can't just add this using add-floating-ip
:
$ nova add-floating-ip webserver 192.168.200.7
ERROR: Error. Unable to associate floating ip (HTTP 400) (Request-ID: req-a8ea0fbb-fec8-4427-ac8b-628ca2d8b107)
You can't have two floating ip addresses associated with the same fixed
ip address. Floating ip addresses are implemented as NAT rules on the
neutron router, and it doesn't make sense to have multiple NAT rules
with the same fixed ip address but different floating addresses.
So we need to add another fixed ip to our instance:
$ nova add-fixed-ip webserver 3ff9b903-e921-4752-a26f-cba8f1433992
$ nova show | grep net0
| net0 network | 10.0.0.4, 10.0.0.5, 192.168.200.6 |
Unfortunately, our instance isn't going to know about this new
address; DHCP will only pick up a single address -- and with two fixed
addresses, you don't know which address you're going to get by
default. Because that will cause all kinds of grief, you're going to
have to configure networking statically on your host.
How you do that depends on your distribution, so for now we're just
going to add the new address manually:
# ip address add 10.0.0.5/24 dev eth0
# ip address show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether fa:16:3e:1c:4e:d0 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.5/24 brd 10.0.0.255 scope global eth0
inet 10.0.0.4/24 scope global secondary eth0
inet6 fe80::f816:3eff:fe1c:4ed0/64 scope link
valid_lft forever preferred_lft forever
Now we can associate the second floating ip with the new fixed
address:
$ nova add-floating-ip --fixed-address 10.0.0.5 webserver 192.168.200.7
I have configured simple ip-based virtual hosts on each of 10.0.0.4
and 10.0.0.5. With this configuration, I can now run:
$ curl http://192.168.200.7/
And get:
This is virtual host 10.0.0.5.
And similarly:
$ curl http://192.168.200.6/
This is virtual host 10.0.0.4.