# Set up reverse DNS

## API Overview

Reverse DNS (formerly IP Whitelabel) allows mailbox providers to verify the sender of an email by performing a reverse DNS lookup upon receipt of the emails you send.

Reverse DNS is available for [dedicated IP addresses](/docs/sendgrid/ui/account-and-settings/dedicated-ip-addresses/) only.

When setting up reverse DNS, Twilio SendGrid will provide an A Record (address record) for you to add to your DNS records. The A Record maps your sending domain to a dedicated Twilio SendGrid IP address.

A Reverse DNS consists of a subdomain and domain that will be used to generate a reverse DNS record for a given IP address. Once Twilio SendGrid has verified that the appropriate A record for the IP address has been created, the appropriate reverse DNS record for the IP address is generated.

You can also manage your reverse DNS settings in the [Sender Authentication section of the Twilio SendGrid App](https://app.sendgrid.com/settings/sender_auth).

For more about Reverse DNS, see ["How to set up reverse DNS"](/docs/sendgrid/ui/account-and-settings/how-to-set-up-reverse-dns/) in the Twilio SendGrid documentation.

## Operation overview

```json
{"path":"https://api.sendgrid.com/v3/whitelabel/ips","method":"post","servers":[{"url":"https://api.sendgrid.com","description":"for global users and subusers"},{"url":"https://api.eu.sendgrid.com","description":"for EU regional subusers"}]}
```

**This endpoint allows you to set up reverse DNS.**

## Operation details

### Authentication

API Key

### Headers

```json
[{"in":"header","name":"Authorization","required":true,"default":"Bearer <<YOUR_API_KEY_HERE>>","schema":{"type":"string"}},{"name":"on-behalf-of","in":"header","description":"The `on-behalf-of` header allows you to make API calls from a parent account on behalf of the parent's Subusers or customer accounts. You will use the parent account's API key when using this header. When making a call on behalf of a customer account, the property value should be \"account-id\" followed by the customer account's ID (e.g., `on-behalf-of: account-id <account-id>`). When making a call on behalf of a Subuser, the property value should be the Subuser's username (e.g., `on-behalf-of: <subuser-username>`). See [**On Behalf Of**](/docs/sendgrid/api-reference/how-to-use-the-sendgrid-v3-api/on-behalf-of) for more information.","required":false,"schema":{"type":"string"},"refName":"#/components/parameters/OnBehalfOf","modelName":"__components_parameters_OnBehalfOf"}]
```

### Request body

```json
{"schema":{"type":"object","required":["ip","domain"],"example":{"ip":"192.168.1.1","subdomain":"email","domain":"example.com"},"properties":{"ip":{"type":"string","description":"The IP address for which you want to set up reverse DNS."},"subdomain":{"type":"string","description":"The subdomain that will be used to send emails from the IP address. This should be the same as the subdomain used to set up an authenticated domain."},"domain":{"type":"string","description":"The root, or sending, domain that will be used to send message from the IP address."}}},"encodingType":"application/json"}
```

### Responses

```json
[{"responseCode":"201","schema":{"description":"","content":{"application/json":{"schema":{"title":"Reverse DNS","type":"object","required":["id","ip","rdns","users","domain","valid","legacy","a_record"],"example":{"id":1,"ip":"192.168.1.1","rdns":"o1.email.example.com","users":[{"username":"john@example.com","user_id":7},{"username":"jane@example.com","user_id":8}],"subdomain":"email","domain":"example.com","valid":true,"legacy":false,"a_record":{"valid":true,"type":"a","host":"o1.email.example.com","data":"192.168.1.1"}},"refName":"ReverseDns","modelName":"ReverseDns","properties":{"id":{"type":"integer","description":"The ID of the Reverse DNS."},"ip":{"type":"string","description":"The IP address that this Reverse DNS was created for."},"rdns":{"type":"string","description":"The reverse DNS record for the IP address. This points to the Reverse DNS subdomain."},"users":{"type":"array","description":"The users who are able to send mail from the IP address.","items":{"type":"object","required":["username","user_id"],"properties":{"username":{"type":"string","description":"The username of a user who can send mail from the IP address."},"user_id":{"type":"integer","description":"The ID of a user who can send mail from the IP address."}}}},"subdomain":{"type":"string","description":"The subdomain created for this reverse DNS. This is where the rDNS record points."},"domain":{"type":"string","description":"The root, or sending, domain."},"valid":{"type":"boolean","description":"Indicates if this is a valid Reverse DNS."},"legacy":{"type":"boolean","description":"Indicates if this Reverse DNS was created using the legacy whitelabel tool. If it is a legacy whitelabel, it will still function, but you'll need to create a new Reverse DNS if you need to update it."},"last_validation_attempt_at":{"type":"integer","description":"A Unix epoch timestamp representing the last time of a validation attempt."},"a_record":{"type":"object","required":["valid","type","host","data"],"properties":{"valid":{"type":"boolean","description":"Indicates if the a_record is valid."},"type":{"type":"string","description":"The type of DNS record."},"host":{"type":"string","description":"This is the web address that will be mapped to the IP address."},"data":{"type":"string","description":"The IP address being set up with Reverse DNS."}}}}},"examples":{"response":{"value":{"id":123,"ip":"192.168.1.2","rdns":"o1.email.example.com","users":[],"subdomain":"email","domain":"example.com","valid":true,"legacy":false,"a_record":{"valid":true,"type":"a","host":"o1.email.example.com","data":"192.168.1.2"}}}}}}}}]
```

Set up reverse DNS

```js
const client = require("@sendgrid/client");
client.setApiKey(process.env.SENDGRID_API_KEY);

const data = {
  ip: "192.168.1.1",
  subdomain: "email",
  domain: "example.com",
};

const request = {
  url: `/v3/whitelabel/ips`,
  method: "POST",
  body: data,
};

client
  .request(request)
  .then(([response, body]) => {
    console.log(response.statusCode);
    console.log(response.body);
  })
  .catch((error) => {
    console.error(error);
  });
```

```python
import os
from sendgrid import SendGridAPIClient


sg = SendGridAPIClient(os.environ.get("SENDGRID_API_KEY"))

data = {"ip": "192.168.1.1", "subdomain": "email", "domain": "example.com"}

response = sg.client.whitelabel.ips.post(request_body=data)

print(response.status_code)
print(response.body)
print(response.headers)
```

```csharp
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using SendGrid;

public class Program {
    public static async Task Main() {
        string apiKey = Environment.GetEnvironmentVariable("SENDGRID_API_KEY");
        var client = new SendGridClient(apiKey);

        var data =
            @"{
            ""ip"": ""192.168.1.1"",
            ""subdomain"": ""email"",
            ""domain"": ""example.com""
        }";

        var response = await client.RequestAsync(
            method: SendGridClient.Method.POST, urlPath: "whitelabel/ips", requestBody: data);

        Console.WriteLine(response.StatusCode);
        Console.WriteLine(response.Body.ReadAsStringAsync().Result);
        Console.WriteLine(response.Headers.ToString());
    }
}
```

```java
import com.sendgrid.*;
import java.io.IOException;
import org.json.JSONObject;
import java.util.HashMap;

public class Example {
    public static void main(String[] args) throws IOException {
        try {
            SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
            Request request = new Request();
            request.setMethod(Method.POST);
            request.setEndpoint("/whitelabel/ips");
            request.setBody(new JSONObject(new HashMap<String, Object>() {
                {
                    put("ip", "192.168.1.1");
                    put("subdomain", "email");
                    put("domain", "example.com");
                }
            }).toString());
            Response response = sg.api(request);
            System.out.println(response.getStatusCode());
            System.out.println(response.getBody());
            System.out.println(response.getHeaders());
        } catch (IOException ex) {
            throw ex;
        }
    }
}
```

```go
package main

import (
	"fmt"
	"github.com/sendgrid/sendgrid-go"
	"os"
)

func main() {
	apiKey := os.Getenv("SENDGRID_API_KEY")
	host := "https://api.sendgrid.com"
	request := sendgrid.GetRequest(apiKey, "/v3/whitelabel/ips", host)
	request.Method = "POST"
	request.Body = []byte(`{
  "ip": "192.168.1.1",
  "subdomain": "email",
  "domain": "example.com"
}`)
	response, err := sendgrid.API(request)
	if err != nil {
		fmt.Println(err.Error())
		os.Exit(1)
	} else {
		fmt.Println(response.StatusCode)
		fmt.Println(response.Body)
		fmt.Println(response.Headers)
	}
}
```

```php
<?php
// Uncomment the next line if you're using a dependency loader (such as Composer) (recommended)
// require 'vendor/autoload.php';

// Uncomment next line if you're not using a dependency loader (such as Composer)
// require_once '<PATH TO>/sendgrid-php.php';

$apiKey = getenv("SENDGRID_API_KEY");
$sg = new \SendGrid($apiKey);
$request_body = json_decode('{
    "ip": "192.168.1.1",
    "subdomain": "email",
    "domain": "example.com"
}');

try {
    $response = $sg->client
        ->whitelabel()
        ->ips()
        ->post($request_body);
    print $response->statusCode() . "\n";
    print_r($response->headers());
    print $response->body() . "\n";
} catch (Exception $ex) {
    echo "Caught exception: " . $ex->getMessage();
}
```

```ruby
require 'sendgrid-ruby'
include SendGrid

sg = SendGrid::API.new(api_key: ENV['SENDGRID_API_KEY'])
data = JSON.parse('{
  "ip": "192.168.1.1",
  "subdomain": "email",
  "domain": "example.com"
}')

response = sg.client.whitelabel.ips.post(request_body: data)
puts response.status_code
puts response.headers
puts response.body
```

```bash
curl -X POST "https://api.sendgrid.com/v3/whitelabel/ips" \
--header "Authorization: Bearer $SENDGRID_API_KEY" \
--header "Content-Type: application/json" \
--data '{"ip": "192.168.1.1", "subdomain": "email", "domain": "example.com"}'
```
