Fixed IP addresses with OpenStack Neutron for tenant networks

In OpenStack Neutron, many times one prefers to rely on DHCP to have instances (VMs) have IP addresses assigned, mostly for simplicity. But there are cases where one would like to reserve a few IPs statically to be used by certain VMs. Well, it is possible to achieve this by manually creating ports inside the tenant network and attach them to an instance.

For example:

$ neutron net-list
+--------------------------------------+---------+--------------------------------------------------+
| id                                   | name    | subnets                                          |
+--------------------------------------+---------+--------------------------------------------------+
| 3d1b9e2c-485c-42dd-bc81-acc1f901e8fc | private | 5e2fa420-b780-4f44-90e7-8dad7a299f73 10.0.0.0/24 |
| 5b078cbb-ffc8-40a4-a3d0-d129c91eeba2 | public  | 5f09a031-fa5d-4c80-884d-8a7cf82977c9             |
+--------------------------------------+---------+--------------------------------------------------+

$ neutron net-show private
+-----------------+--------------------------------------+
| Field           | Value                                |
+-----------------+--------------------------------------+
| admin_state_up  | True                                 |
| id              | 3d1b9e2c-485c-42dd-bc81-acc1f901e8fc |
| name            | private                              |
| router:external | False                                |
| shared          | False                                |
| status          | ACTIVE                               |
| subnets         | 5e2fa420-b780-4f44-90e7-8dad7a299f73 |
| tenant_id       | c38cd73e1e8e41d880001e621aa3ef3d     |
+-----------------+--------------------------------------+

$ neutron subnet-show 5e2fa420-b780-4f44-90e7-8dad7a299f73
+------------------+--------------------------------------------+
| Field            | Value                                      |
+------------------+--------------------------------------------+
| allocation_pools | {"start": "10.0.0.2", "end": "10.0.0.254"} |
| cidr             | 10.0.0.0/24                                |
| dns_nameservers  | 8.8.4.4                                    |
|                  | 8.8.8.8                                    |
| enable_dhcp      | True                                       |
| gateway_ip       | 10.0.0.1                                   |
| host_routes      |                                            |
| id               | 5e2fa420-b780-4f44-90e7-8dad7a299f73       |
| ip_version       | 4                                          |
| name             | private_subnet                             |
| network_id       | 3d1b9e2c-485c-42dd-bc81-acc1f901e8fc       |
| tenant_id        | c38cd73e1e8e41d880001e621aa3ef3d           |
+------------------+--------------------------------------------+

This tenant subnet is using CIDR 10.0.0.0/24. Let’s say we want to reserve IP address 10.0.0.200. A possible solution when using OpenStack Neutron consists of manually creating a port that reserves that address:

$ neutron port-create private --fixed-ip ip_address=10.0.0.200 --name win1
Created a new port:
+-----------------------+-----------------------------------------------------------------------------------+
| Field                 | Value                                                                             |
+-----------------------+-----------------------------------------------------------------------------------+
| admin_state_up        | True                                                                              |
| allowed_address_pairs |                                                                                   |
| device_id             |                                                                                   |
| device_owner          |                                                                                   |
| fixed_ips             | {"subnet_id": "5e2fa420-b780-4f44-90e7-8dad7a299f73", "ip_address": "10.0.0.200"} |
| id                    | 74a86226-c286-4395-a223-a9fc3728e5b9                                              |
| mac_address           | fa:16:3e:05:b2:8d                                                                 |
| name                  | win1                                                                              |
| network_id            | 3d1b9e2c-485c-42dd-bc81-acc1f901e8fc                                              |
| security_groups       | 1a02d4ff-99eb-4f69-ba18-22141e7ba2b9                                              |
| status                | DOWN                                                                              |
| tenant_id             | c38cd73e1e8e41d880001e621aa3ef3d                                                  |
+-----------------------+-----------------------------------------------------------------------------------+

Once this is done, it is possible to boot a new Nova instance (VM) attached to this particular port:

$ nova boot --flavor=m1.small --image=w2012r2 --nic port-id=74a86226-c286-4395-a223-a9fc3728e5b9 win1

The nice thing about using this port is that the instance is able to get the 10.0.0.200 IPv4 address either by relying on DHCP, or just by having this IPv4 address configured statically 🙂

Advertisements

10 thoughts on “Fixed IP addresses with OpenStack Neutron for tenant networks

  1. Good day! This is kind of off topic but I need some guidance
    from an established blog. Is it very hard to set up your own blog?

    I’m not very techincal but I can figure things out pretty fast.
    I’m thinking about making my own but I’m not sure where to begin. Do you have any ideas or suggestions?

    Many thanks

  2. Pingback: styk.tv | fixed ip addresses with openstack neutron for tenant networks

  3. Hello my friend! I want to say that this article is awesome, nice written and include almost
    all vital infos. I would like to peer more posts like this .

  4. What’s Going down i am new to this, I stumbled upon this I
    have discovered It positively helpful and it has helped me out loads.

    I hope to contribute & help different users like
    its aided me. Good job.

  5. I read this piece of writing completely regarding
    the difference of most up-to-date and earlier technologies, it’s remarkable article.

  6. Yesterday, while I was at work, my cousin stole my apple ipad and tested to see if it can survive a twenty five
    foot drop, just so she can be a youtube sensation. My iPad is now
    broken and she has 83 views. I know this is completely off topic but I had to share it with
    someone!

  7. Wonderful goods from you, man. I have understand your stuff previous to and
    you’re just too magnificent. I really like what you have acquired here, really like what you are saying and the way
    in which you say it. You make it entertaining and you still care for to keep it sensible.
    I can not wait to read far more from you. This is really a terrific site.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s