Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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 preferred_lft forever
    inet6 fe80::f816:3eff:febf:f96a/64 scope link 
       valid_lft forever preferred_lft forever

This should be enough to get you started. Good luck!

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 preferred_lft forever
    inet6 fe80::f816:3eff:febf:f96a/64 scope link 
       valid_lft forever preferred_lft forever

This should be enough to get you started. Good luck!