OpenStack Add Direct Attached DHCP IPs

Configure OpenStack Neutron to assign direct-attached DHCP IPs to instances on flat or VLAN provider networks.

OpenStack Add Direct Attached DHCP IPs

Direct-attached IPs are assigned to instances via DHCP on a Neutron provider network at boot.

Prerequisites

  • OpenStack 2024.2 Dalmatian
  • Physical network (VLAN or flat) accessible by instances
  • Neutron ML2 plugin with flat or VLAN driver
  • DHCP agent running on at least one network node

Step 1: Configure Physical Network Mapping

Edit /etc/neutron/plugins/ml2/ml2_conf.ini on the controller:

[ml2]
type_drivers = flat,vlan,vxlan

[ml2_type_flat]
flat_networks = physnet1

[ml2_type_vlan]
network_vlan_ranges = physnet1:100:200

Edit the agent config on compute and network nodes:

For OVS (/etc/neutron/plugins/ml2/openvswitch_agent.ini):

[ovs]
bridge_mappings = physnet1:br-provider

For Linux Bridge (/etc/neutron/plugins/ml2/linuxbridge_agent.ini):

[linux_bridge]
physical_interface_mappings = physnet1:ens224

Restart agents:

sudo systemctl restart neutron-openvswitch-agent
# OR
sudo systemctl restart neutron-linuxbridge-agent

Step 2: Create a Flat Provider Network

openstack network create \
  --provider-network-type flat \
  --provider-physical-network physnet1 \
  --share \
  --external \
  direct-net

openstack subnet create \
  --network direct-net \
  --subnet-range 10.100.0.0/24 \
  --allocation-pool start=10.100.0.100,end=10.100.0.200 \
  --gateway 10.100.0.1 \
  --dns-nameserver 8.8.8.8 \
  --dhcp \
  direct-subnet

Step 3: Launch an Instance

openstack server create \
  --flavor m1.small \
  --image "Ubuntu 22.04" \
  --network direct-net \
  direct-vm

Verify the IP assignment:

openstack server show direct-vm -c addresses

Step 4: Assign a Specific IP

Pre-create a port with a fixed IP:

openstack port create \
  --network direct-net \
  --fixed-ip subnet=direct-subnet,ip-address=10.100.0.150 \
  reserved-port

openstack server create \
  --flavor m1.small \
  --image "Ubuntu 22.04" \
  --port reserved-port \
  specific-ip-vm

Step 5: Add Multiple IPs

Create and attach an additional port:

openstack port create --network direct-net extra-port
openstack server add port direct-vm extra-port

Configure the interface inside the VM:

sudo dhclient ens4

DHCP Agent Configuration

Edit /etc/neutron/dhcp_agent.ini:

[DEFAULT]
interface_driver = openvswitch
dhcp_driver = neutron.agent.linux.dhcp.Dnsmasq
enable_isolated_metadata = true
force_metadata = true

Enable high availability in /etc/neutron/neutron.conf:

[DEFAULT]
dhcp_agents_per_network = 2

Troubleshooting

  • VM gets no IP: Verify neutron-dhcp-agent is running: openstack network agent list
  • Wrong subnet: Check allocation pool: openstack subnet show <subnet>
  • Duplicate IP: Check conflicting ports: openstack port list --network direct-net
  • No external connectivity: Verify physical switch VLAN/trunk and bridge mappings