Ask Your Question
3

Add multiple specific IPs to instance

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

marcantonio gravatar image

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

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
4

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

larsks gravatar image

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

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": "10.0.0.18"} |
|                       | {"subnet_id": "f8ca90fd-cb82-4218-9627-6fa66e4c9c3c", "ip_address": "10.0.0.19"} |
| 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=10.0.0.18 \
  --fixed-ip subnet_id=net0-subnet0,ip_address=10.0.0.19

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:

#!/bin/sh

cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
DEVICE=eth0
BOOTPROTO=none
IPADDR=10.0.0.18
NETMASK=255.255.255.0
GATEWAY=10.0.0.1
ONBOOT=yes
EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth0:0 <<EOF
DEVICE=eth0:0
BOOTPROTO=none
IPADDR=10.0.0.19
NETMASK=255.255.255.0
GATEWAY=10.0.0.1
ONBOOT=yes
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 10.0.0.19 test0 192.168.200.6
$ nova add-floating-ip --fixed-address 10.0.0.18 test0 192.168.200.4

And now I can access the instance at either address:

$ ssh fedora@192.168.200.4 uptime
  14:51:52 up 4 min,  0 users,  load average: 0.00, 0.02, 0.02
$ ssh fedora@192.168.200.6 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@192.168.200.4 /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 10.0.0.18/24 brd 10.0.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 10.0.0.19/24 brd 10.0.0.255 scope global secondary eth0:0
       valid_lft forever ...
(more)
edit flag offensive delete link more

Comments

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

marcantonio gravatar imagemarcantonio ( 2014-05-28 10:03:32 -0600 )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 -0600 )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 -0600 )edit

See http://developer.openstack.org/api-ref/networking/v2/?expanded=create-port-port-binding-detail,create-port-detail#create-port (http://developer.openstack.org/api-re...) 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 -0600 )edit
2

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

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=192.168.2.40 <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

Comments

Can you add a port to a running VM?

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

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

Seen: 18,903 times

Last updated: May 28 '14