Ask Your Question

Add multiple specific IPs to instance

asked 2014-05-27 15:08:17 -0500

marcantonio gravatar image

updated 2014-05-28 07:59:02 -0500

Does anyone know if it is possible to add additional specific IP address to a single instance? I followed the instructions here to add multiple IPs. However, I need to know the IP addresses in advance. So, for example, if I could run nova add-fixed-ip server network and specify the IP address I want to use, that would solve my problem.

I'm using Icehouse and Neutron.

My broad goal is to put 2 servers (active/passive) into OpenStack that use SSL-based virtual hosts. This means that I need to know the IPs ahead of time to configure Apache properly. I'm not crazy about the above solution, but, it's the best I could find.

Thanks, Marc

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-05-28 09:54:40 -0500

larsks gravatar image

updated 2014-05-28 09:57:08 -0500

You can create a port in Neutron with multiple fixed ips prior to booting your instance. For example, assuming that I have a network named net0 and a subnet named net0_subnet0, I can do this:

$ neutron port-create net0 \
  --fixed-ip subnet_id=net0-subnet0 \
  --fixed-ip subnet_id=net0-subnet0

Which gets me:

| Field                 | Value                                                                            |
| admin_state_up        | True                                                                             |
| allowed_address_pairs |                                                                                  |
| binding:vnic_type     | normal                                                                           |
| device_id             |                                                                                  |
| device_owner          |                                                                                  |
| fixed_ips             | {"subnet_id": "f8ca90fd-cb82-4218-9627-6fa66e4c9c3c", "ip_address": ""} |
|                       | {"subnet_id": "f8ca90fd-cb82-4218-9627-6fa66e4c9c3c", "ip_address": ""} |
| id                    | 3c564dd5-fd45-4f61-88df-715f71667b3b                                             |
| mac_address           | fa:16:3e:e1:15:7f                                                                |
| name                  |                                                                                  |
| network_id            | bb4e5e37-74e1-41bd-880e-b59e94236c5e                                             |
| security_groups       | 52f7a87c-380f-4a07-a6ff-d64be495f25b                                             |
| status                | DOWN                                                                             |
| tenant_id             | 4dfe8e38f68449b6a0c9cd73037726f7                                                 |

If you want to assign a specific fixed address, rather than letting Neutron assign one for you, you can add an ip_address parameter to the --fixed-ip option:

$ neutron port-create net0 \
  --fixed-ip subnet_id=net0-subnet0,ip_address= \
  --fixed-ip subnet_id=net0-subnet0,ip_address=

I can boot an instance using this port like this:

$ nova boot --nic port-id=3c564dd5-fd45-4f61-88df-715f71667b3b \
  --flavor m1.tiny --image fedora-20-x86_64 --key-name lars test0

The trick here is that when this instance comes up it will get one of those addresses assigned via DHCP...but you don't know which one. Your best bet is probably to pass in a script via --user-data that will perform the appropriate network configuration. For example, assuming that I'm running Fedora, I could use this:


cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth0:0 <<EOF

ifdown eth0
ifup eth0
ifup eth0:0

And save it in a file called, say, userdata.txt, and then boot like this:

$ nova boot --nic port-id=3c564dd5-fd45-4f61-88df-715f71667b3b \
  --flavor m1.tiny --image fedora-20-x86_64 --key-name lars \
  --user-data userdata.txt test0

Now, we map floating ips to those two fixed ips:

$ nova add-floating-ip --fixed-address test0
$ nova add-floating-ip --fixed-address test0

And now I can access the instance at either address:

$ ssh fedora@ uptime
  14:51:52 up 4 min,  0 users,  load average: 0.00, 0.02, 0.02
$ ssh fedora@ uptime
  14:51:54 up 4 min,  0 users,  load average: 0.00, 0.02, 0.02

And if we take a look at the network configuration we'll see both fixed addresses have been configured:

$ ssh fedora@ /sbin/ip a
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether fa:16:3e:bf:f9:6a brd ff:ff:ff:ff:ff:ff
    inet brd scope global eth0
       valid_lft forever preferred_lft forever
    inet brd scope global secondary eth0:0
       valid_lft forever ...
edit flag offensive delete link more


That's great. Is it possible to add ports after the VM has booted?

marcantonio gravatar imagemarcantonio ( 2014-05-28 10:03:32 -0500 )edit

You can, of course, use nova add-fixed-ip, but that doesn't permit you to choose a specific ip. I think you can use the --device-id parameter with neutron port-create to attach a port to a running instance. I am not actually sure this will work...testing it out right now.

larsks gravatar imagelarsks ( 2014-05-28 10:10:55 -0500 )edit

I'm not able to get anything other than nova add-fixed-ip to work with a running server...

larsks gravatar imagelarsks ( 2014-05-28 10:40:05 -0500 )edit

See,create-port-detail#create-port ( You can add the port to an active instance, but that is only updating the data model. You still have to reboot or config the interface to process it through neutron

solargroovy gravatar imagesolargroovy ( 2016-08-25 15:17:28 -0500 )edit

answered 2014-05-28 09:31:04 -0500

In order to boot a VM with a specific IP address you need to create an OpenStack Networking port with a specific IP address first, and then boot a VM specifying a port-id rather than a net-id.

neutron port-create net1 --fixed-ip ip_address= <net-id>
nova boot --image <img> --flavor <flavor> --nic port-id=<port-id> <vm-name>

Here cli commands about ports. Hope this is what you were searching for.

edit flag offensive delete link more


Can you add a port to a running VM?

marcantonio gravatar imagemarcantonio ( 2014-05-28 09:54:29 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-05-27 15:08:17 -0500

Seen: 23,556 times

Last updated: May 28 '14