Search code examples
azureazure-virtual-network

Azure Network : Prevent subnet to subnet communication


I have the following subnets

  1. Subnet_1 = 10.2.3.0
  2. Subnet_1 = 10.2.4.0

I want to prevent subnet to subnet communication. As far as I see, it can be done using the Network Security Group. However I am not sure about the required change.


Solution

  • I tried to reproduce the same in my environment to prevent communication between 2 Subnet

    I have created 2 subnets in my Vnet, like below.

    Subnet 1: Prod-Subnet (10.0.1.0/24)

    Subnet 2: default (10.0.0.0/24)

    In order to prevent communication between both the VNet, you need to create an inbound and outbound rule in same NSG group, like below.

    enter image description here

    I have created 2 virtual machines and attached above subnets to 2 virtual machines, like below.

    Prod-subnet attached to VM1 Default Subnet attached to VM2

    enter image description here

    Create inbound and outbound rule in Network Security Group to block the communicatioin ,like below.

    Inbound Rule:

    Source IP: 10.0.0.9/24
    Source Port: * ( for all)
    Destination IP: 10.0.1.0/24
    Destination Port: *( for all)
    Service: custom
    

    (Note: If you want block particular service and port, mention the port details and protocol type)

    enter image description here

    Outbound Rule:

    Source IP: 10.0.1.0/24
    Source Port: * ( for all)
    Destination IP: 10.0.0.0/24
    Destination Port: *( for all)
    Service: custom
    

    enter image description here

    Tested communication and its getting denied from the subnets.

    VM 1 Result

    enter image description here

    VM 2 Result

    enter image description here