Purpose
From cloud dashboard, security groups can be assigned to all virtual machines interfaces at once but in some cases, customer need to assign a different security groups for each network interface in the same virtual machine.
This guide consider that your already have Openstack client installed.
List all security groups
openstack security group list
openstack security group list
+--------------------------------------+--------------+------------------------+---------+------+
| ID | Name | Description | Project | Tags |
+--------------------------------------+--------------+------------------------+---------+------+
| c1c0bc6d-7020-4ef3-8959-e3e8d12c52e4 | SG1 | | None | [] |
| 7b7ecfe5-86ab-4690-ab3b-f7f291ce2d1f | default | Default security group | None | [] |
| f689cf11-4738-4dd5-9c91-fe4e6199cd15 | SG2 | lf sg | None | [] |
| 980246b9-bacb-494b-8705-a01026da8261 | Allow-Web | | None | [] |
+--------------------------------------+--------------+------------------------+---------+------+
List the VM ports (vNICs)
openstack port list --server <Instance-ID>
openstack port list --server 6af281d0-7c9f-4fbf-b819-6c45a810b0a6
+--------------------------------------+--------------------------------------+-------------------+----------------------------------------------------------------------------+--------+
| ID | Name | MAC Address | Fixed IP Addresses | Status |
+--------------------------------------+--------------------------------------+-------------------+----------------------------------------------------------------------------+--------+
| cf47cf83-68f9-4469-94d8-0099c23fac07 | cf47cf83-68f9-4469-94d8-0099c23fac07 | 02:cf:47:cf:83:68 | ip_address='10.240.0.3', subnet_id='1e8cbed1-2507-4289-8ded-bd393e91aaa2' | ACTIVE |
| 00bed026-7f44-49df-98eb-d1094fa6ad32 | 00bed026-7f44-49df-98eb-d1094fa6ad32 | 02:00:be:d0:26:7f | ip_address='10.10.210.6', subnet_id='181f461d-7f24-485d-9279-17eeb4c978b0' | ACTIVE |
+--------------------------------------+--------------------------------------+-------------------+----------------------------------------------------------------------------+--------+
Show the configured security group on each interface
neutron port-show <port ID>
neutron port-show cf47cf83-68f9-4469-94d8-0099c23fac07
security_groups | 7b7ecfe5-86ab-4690-ab3b-f7f291ce2d1f
Set security group of each port
neutron port-update --security-group <SG1 ID> --security-group <SG2 ID> <Port ID>
neutron port-update --security-group 7b7ecfe5-86ab-4690-ab3b-f7f291ce2d1f --security-group c1c0bc6d-7020-4ef3-8959-e3e8d12c52e4 cf47cf83-68f9-4469-94d8-0099c23fac07
Verify your changes
neutron port-show <port ID>
neutron port-show cf47cf83-68f9-4469-94d8-0099c23fac07
| security_groups | c1c0bc6d-7020-4ef3-8959-e3e8d12c52e4
| | 7b7ecfe5-86ab-4690-ab3b-f7f291ce2d1f