# Configure larger instance netmasks for all instances in a subnet

This page describes how to configure all Compute Engine instances in a
subnet with larger than default netmasks. To use this configuration, you create
a subnet and configure the **Resolve subnet mask** (`--resolve-subnet-mask`)
setting. When you connect compute instances to the subnet, the instances are
configured with a netmask that's the same size as the subnet's netmask, instead
of `/32`. For more information about compute instance netmasks, see [Compute
instance netmasks](https://docs.cloud.google.com/vpc/docs/compute-instance-netmasks).

## Before you begin

<br />

### Required roles


To get the permissions that
you need to create a subnet,

ask your administrator to grant you the
Compute Network Admin (`role/compute.networkAdmin`)
IAM role on your project.


For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt).


You might also be able to get
the required permissions through [custom
roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles) or other [predefined
roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

## Create a subnet to configure larger instance netmasks

### Console

1. In the Google Cloud console, go to the **VPC networks** page.

   [Go to VPC networks](https://console.cloud.google.com/networking/networks/list)
2. Select a VPC network.

3. Click the **Subnets** tab.

4. Click **Add subnet**.

5. For **Name**, enter a name for the subnet.

6. For **Region**, select a region.

7. For **Purpose** , select **None**.

8. For **IP stack type** , select **IPv4 (single stack)**.

9. For **Primary IPv4 range** , enter a [valid IPv4 address
   range](https://docs.cloud.google.com/vpc/docs/subnets#valid-ranges).

10. If you want to add a secondary IPv4 range, do the following:

    1. For **Subnet range name**, enter a name for the secondary IPv4 range.
    2. For **Secondary IPv4 range**, enter a valid IPv4 address range.
11. In **Resolve subnet mask**, select one of the following:

    - **All ranges**
    - **Primary range only**
12. Click **Add**.

### gcloud

```
gcloud compute networks subnets create SUBNET_NAME \
    --network=NETWORK_NAME \
    --range=IP_RANGE \
    --region=REGION \
    --resolve-subnet-mask=ARP_RANGES
```

Replace the following:

- `SUBNET_NAME`: a name for the subnet.
- `NETWORK_NAME`: the network to create the subnet in.
- `IP_RANGE`: the primary IPv4 address range for the subnet.
- `REGION`: the region for the subnet.
- `ARP_RANGES`: the ranges that you want to receive ARP replies from. Valid values are `ARP_PRIMARY_RANGE` and `ARP_ALL_RANGES`.

## Create a compute instance in the subnet

Create a compute instance that is connected to the subnet. For more
information about creating instances, see [Create an instance in a specific
subnet](https://docs.cloud.google.com/compute/docs/instances/create-vm-specific-subnet).

### gcloud CLI

```
gcloud compute instances create INSTANCE_NAME \
    --zone=ZONE \
    --subnet=SUBNET_NAME
```

Replace the following:

- `INSTANCE_NAME`: a name for your instance.
- `ZONE`: the zone to create the instance in.
- `SUBNET_NAME`: the name of the subnet to connect the instance to.

## Verify the configuration

After you create a compute instance, you can verify that the DHCP server
configures the correct netmask on the instance, and that the instance
receives ARP replies. You can verify ARP replies by using only one instance
because [Google Cloud always sends a reply for IP addresses in the
subnet's range](https://docs.cloud.google.com/vpc/docs/compute-instance-netmasks#how-arp-works-vpc).

The following steps show you how to verify the configuration on a Linux
instance.

1. Connect to your instance by using SSH.
2. Check the network interface configuration to verify that the netmask matches
   the subnet's netmask (not `/32`).

   ```
   ip addr show
   ```

   In the output, look for the `inet` line for your network interface, for
   example, `ens4`.
3. Verify that the instance can receive ARP replies for a different IP address
   in the subnet. You can use the `ping` command to trigger an ARP request. You
   can choose an IP address that's not in use---Google Cloud sends
   an ARP reply even if there is no reply to the `ping` request.

   ```
   ping -c 3 OTHER_IP_ADDRESS_IN_SUBNET
   ```

   Replace `OTHER_IP_ADDRESS_IN_SUBNET` with an IP address
   from the same subnet. This IP address doesn't need to be in use.
4. Check the ARP table to see the MAC address associated with the other IP
   address.

   ```
   ip neighbor
   ```

   The output displays the MAC address of the other IP address.