# Attach a Server or NIC to a Network Security Group

With NSGs, administrators can control and filter incoming and outgoing traffic to virtual resources. NSG rules only permit traffic and support security rules that allow traffic in both inbound and outbound directions. Any traffic not explicitly allowed is automatically blocked. When you attach NSGs to servers or Network Interface Cards (NICs), you can enforce granular security policies by restricting access to specific servers or NICs to secure your network from malicious activity, unauthorized access, and security threats.

Reviewing your configuration is vital to ensure it meets changing security requirements.

{% hint style="warning" %}
**Warning:** It is not recommended to use NSGs in parallel with an [<mark style="color:blue;">NIC-based Firewall</mark>](https://docs.ionos.com/sections-test/guides/network-services/vdc-networking/firewall). By default, NSGs act as bidirectional firewalls, which can override or conflict with the behavior of NIC-based firewalls and lead to unintended traffic rules.
{% endhint %}

{% hint style="info" %}
**Prerequisite:** Ensure that the NSGs are configured with appropriate firewall or template rules.
{% endhint %}

## Attach a Server or NIC to an NSG via the Network Security Groups window

To attach NSGs to a server or NIC, follow these steps:

1\. In the **DCD**, go to **Menu** > **Security** > **Network Security Groups**.

2\\. Select the checkbox(es) to associate the chosen NSGs with a server or an NIC.

3\. Select **Attach NSG to**.

![Select NSGs that must be attached](https://1737632334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MifAzdGvKLDTtvJP8sm%2Fuploads%2Fgit-blob-5f84c51a4098717de30134f9b9d3e3d02f88ed47%2Fattach-nsg-select.png?alt=media)

4\. Select one of the following in the **Attach Network Security Groups** pop-up window:

* **Select the target VM or NIC:**
  * **Server:** Select a server from the drop-down list. The list contains the servers that you have configured in the respective data center. Upon selection, the chosen NSGs are automatically configured for all the NICs associated with the corresponding server.
  * **NIC:** Select an NIC from the drop-down list. The list contains the NICs associated with the respective data center. The selected NSGs are associated with the selected NIC upon selection. This is beneficial for granular control, where you can apply NSGs to individual VMs or NICs requiring unique security configurations.
* **What action should be taken with the selected Network Security Groups?**
  * **Add selected security groups without affecting any existing ones:** Select the option to add the selected NSGs without affecting the existing NSGs.
  * **Replace any existing security groups with the selected ones:** Select the option to replace the existing NSGs with the selected NSGs. All the rules of the chosen server or the NIC will be overridden with the rules of the new NSGs.

**Note:** When a server is added to an NSG, all its NICs automatically inherit the NSG rules. However, this inheritance might not be explicitly shown in the network map visualizations.

![Attach NSGs to a server or an NIC](https://1737632334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MifAzdGvKLDTtvJP8sm%2Fuploads%2Fgit-blob-7e0d6f5cb2283ad442b374d333acb325f415e540%2Fattach-nsg.png?alt=media)

{% hint style="success" %}
**Result:** The selected security group(s) is associated with the selected server or the NIC.
{% endhint %}

## Attach a Server or NIC to an NSG from the Inspector pane

To attach a server or NIC from the Inspector pane, follow these steps:

1\. In the **DCD**, go to **Menu** > **Virtual Data Centers** and select the data center from **My Virtual Data Centers**.

2\. Depending on whether you want to attach a server or NIC to an NSG, perform the following action:

{% tabs %}
{% tab title="Attach a Server to an NSG" %}
1\. In the Inspector pane, select the data center and go to the **Settings** tab.

2\. In the **Network Security Groups**, select one or more network security groups from the drop-down list. You can choose from any of the default or custom groups.

![Attach NSGs to a server](https://1737632334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MifAzdGvKLDTtvJP8sm%2Fuploads%2Fgit-blob-f287915529498a231ba6e7e70884f973b2c21f10%2Fattach-server-nsg-inspector.png?alt=media)
{% endtab %}

{% tab title="Attach an NIC to an NSG" %}
1\. In the Inspector pane, select the data center and go to the **Network** tab.

2\. Open the properties of the NIC for which you want to set up an NSG.

3\. In the **Network Security Groups**, select one or more network security groups from the drop-down list. You can choose from any of the default or custom groups.

![Attach NSGs to an NIC](https://1737632334-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MifAzdGvKLDTtvJP8sm%2Fuploads%2Fgit-blob-18fba91a38079215fc4a182c049822771e475d78%2Fattach-nic-nsg-inspector.png?alt=media)
{% endtab %}
{% endtabs %}

3\. Provision your changes.

{% hint style="success" %}
**Result:** The selected security group(s) is associated with the selected server or the NIC.
{% endhint %}
