Create and assign multiple floating IPs or Public IPs to a VM
Create and assign multiple floating IPs to a VM
Floating IPs are mapped to a VM local interface so you first need to create new interfaces for your VM on its local subnet.
Assuming you want to add 2 floating IPs and your VM is connected to the subnet named ik-private-net-1
then :
taylor@laptop (pub1|taylor):~$ openstack port create --network ik-private-net-1 second-port
taylor@laptop (pub1|taylor):~$ openstack port create --network ik-private-net-1 third-port
Then we reserve 2 floating IPs
openstack floating ip create ext-floating1
[...]
| floating_ip_address | 195.15.244.233 |
[...]
openstack floating ip create ext-floating1
[...]
| floating_ip_address | 195.15.247.113 |
[...]
Our IPs are 195.15.244.233
and 195.15.247.113
.
We mapped the floating IPs to the local ports created before.
taylor@laptop (pub1|taylor):~$ openstack floating ip set --port 7c506570-17fa-400d-a4a9-ea08e6c7fe72 195.15.244.233
taylor@laptop (pub1|taylor):~$ openstack floating ip set --port 4483d7cd-bd51-4855-81b7-be4e233ce1ca 195.15.247.113
taylor@laptop (pub1|taylor):~$ openstack floating ip list -c "Floating IP Address" -c "Fixed IP Address"
+---------------------+------------------+
| Floating IP Address | Fixed IP Address |
+---------------------+------------------+
| 195.15.247.113 | 10.0.0.185 |
+----------------+------------+
| 195.15.244.233 | 10.0.0.16 |
+----------------+------------+
+---------------------+------------------+
Now you must configure the routing inside your virtual machine :
Replace the network device names, IPs and gateways accordingly to your setup.
root@ik-private-subnet-1-vm-1:~# ip addr add 10.0.0.185/24 dev ens7
root@ik-private-subnet-1-vm-1:~# ip route add default via 10.0.0.1 dev ens7 src 10.0.0.185 table table1
root@ik-private-subnet-1-vm-1:~# ip rule add from 10.0.0.185/32 table table1
root@ik-private-subnet-1-vm-1:~# ip route add default via 10.0.0.1 dev ens8 src 10.0.0.16 table table2
root@ik-private-subnet-1-vm-1:~# ip addr add 10.0.0.16/24 dev ens8
root@ik-private-subnet-1-vm-1:~# ip rule add from 10.0.0.16/32 table table2
These rules and routes aren't persistent after a reboot. Making them persistent depends on the Operating System so it isn't explained here.
Create and assign multiple public IPs to a VM
In this example we will add 3 public IPs to a Linux VM.
First, create 3 ports on the public network
taylor@laptop (pub1|taylor):~$ openstack port create --network ext-net1 myport1
taylor@laptop (pub1|taylor):~$ openstack port create --network ext-net1 myport2
taylor@laptop (pub1|taylor):~$ openstack port create --network ext-net1 myport3
We add the 3 ports to our VM
taylor@laptop (pub1|taylor):~$ openstack server add port my-VM-name myport1
taylor@laptop (pub1|taylor):~$ openstack server add port my-VM-name myport2
taylor@laptop (pub1|taylor):~$ openstack server add port my-VM-name myport3
Now we configure the routing from inside the VM
Assuming our 3 public IPs are 195.15.242.231
on ens7
, 195.15.242.159
on ens8
and 195.15.242.91
on ens9
then :
root@my-VM-name:~# echo 201 myport1 >> /etc/iproute2/rt_tables
root@my-VM-name:~# echo 202 myport2 >> /etc/iproute2/rt_tables
root@my-VM-name:~# echo 203 myport3 >> /etc/iproute2/rt_tables
root@my-VM-name:~# ip rule add from 195.15.242.231 table myport1 prio 1
root@my-VM-name:~# ip rule add from 195.15.242.159 table myport2 prio 1
root@my-VM-name:~# ip rule add from 195.15.242.91 table myport3 prio 1
root@my-VM-name:~# ip route add default via 195.15.242.1 dev ens7 src 195.15.242.231 table myport1
root@my-VM-name:~# ip route add default via 195.15.242.1 dev ens8 src 195.15.242.159 table myport2
root@my-VM-name:~# ip route add default via 195.15.242.1 dev ens9 src 195.15.242.91 table myport3
These rules and routes aren't persistent after a reboot. Making them persistent depends on the Operating System so it isn't explained here.