> ## Documentation Index
> Fetch the complete documentation index at: https://docs.megaport.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuring Advanced BGP Settings

> This help topic describes how to configure advanced Border Gateway Protocol (BGP) settings in the Megaport NAT Gateway (NAT).

export const Anchor = ({name}) => {
  const errorPrefix = '\x1b[31;1;4mERROR\x1b[0m: Anchor -';
  if (name === undefined || name === null || name === 'undefined') {
    console.error(`${errorPrefix} \`name\` must have a value — rendering an empty string instead`);
    return <></>;
  }
  const raw = typeof name === 'string' ? name : JSON.stringify(name);
  const id = raw.replace(/\s+/g, '-').replace(/[^A-Za-z0-9_-]/g, '').replace(/-+/g, '-').replace(/^-+|-+$/g, '');
  if (!id) {
    console.error(`${errorPrefix} \`name\` "${name}" sanitizes to an empty id — rendering an empty string instead`);
    return <></>;
  }
  return <a style={{
    scrollMarginTop: 'var(--scroll-mt)'
  }} id={id}></a>;
};

export const Gloss = ({term, anchor, langDir = 'en'}) => {
  const errorPrefix = '\x1b[31;1;4mERROR\x1b[0m: Gloss -';
  if (typeof term !== 'string') {
    term = String(term);
  }
  if (typeof anchor !== 'string') {
    anchor = String(anchor);
  }
  if (!term || term === 'undefined') {
    console.error(`${errorPrefix} the \`term\` property is required — rendering an empty string instead`);
    return <></>;
  }
  if (!anchor || anchor === 'undefined') {
    console.error(`${errorPrefix} the \`anchor\` property is required — rendering an empty string instead`);
    return <></>;
  }
  const lang = langDir === 'en' ? '/' : '/' + langDir + '/';
  const glossaryPage = lang + 'glossary/#' + anchor;
  return <a href={glossaryPage}>{term}</a>;
};

export const productShort_0 = "NAT Gateway"

export const productShortWithArticle_0 = "a NAT Gateway"

export const Link = ({href, children}) => {
  const errorPrefix = '\x1b[31;1;4mERROR\x1b[0m: Link -';
  if (typeof href !== 'string') {
    href = String(href);
  }
  if (!href || href === 'undefined') {
    console.error(`${errorPrefix} the \`href\` property is required — rendering an empty string instead`);
    return <></>;
  }
  if (href.includes('{') || href.toUpperCase().includes('%7B')) {
    console.error(`${errorPrefix} could not resolve a variable in href "${href}" — rendering an empty string instead`);
    return <></>;
  }
  const isExternal = (/^https?:\/\//).test(href);
  return <a href={href} className="link" target={isExternal ? '_blank' : undefined} rel={isExternal ? 'noreferrer' : undefined}>
      {children ?? href}
      {isExternal && <span className="sr-only"> (opens in a new tab)</span>}
    </a>;
};

export const Image = ({src, alt = '', caption, width, height, shadow}) => {
  const errorPrefix = '\x1b[31;1;4mERROR\x1b[0m: Image -';
  if (typeof src !== 'string') {
    src = String(src);
  }
  if (!src || src === 'undefined') {
    console.error(`${errorPrefix} \`src\` is required — rendering an empty string instead`);
    return <></>;
  }
  const img = <img className={['mega-image-style', shadow ? 'shadow' : ''].join(' ')} src={src} alt={alt} width={width} height={height} style={{
    display: 'block'
  }} />;
  return caption ? <figure>
      {img}
      <figcaption style={{
    textAlign: 'center',
    width
  }}>{caption}</figcaption>
    </figure> : img;
};

This topic describes how to manage advanced Border Gateway Protocol (BGP) settings in the Megaport NAT Gateway (NAT Gateway).

<Anchor name="override-asn" />

## Overriding the NAT Gateway ASN

The default <Gloss term="ASN" anchor="asn" /> assigned to the NAT Gateway is 133937. For most configurations, the default ASN is appropriate. Optionally, you can specify another local ASN to override the default ASN on a per-peer basis.

<Callout icon="triangle-exclamation" color="red">
  Cloud service providers (CSPs) can have restrictions on the ASN value. See the documentation for your CSP before overriding the default value.
</Callout>

**To override the NAT Gateway ASN**

1. In the <Link href="https://portal.megaport.com">Megaport Portal</Link>, go to the **Services** page.

2. Select the VXC and select the NAT Gateway A-End or B-End.

3. Next to the BGP connection, click **Edit**.

4. Select the **Advanced** tab.

5. In the **Local ASN** field, specify a public or private ASN (for example, specify a number from 64512 to 65534).

   The ASN range is from 2 to 4294967294, but the following ASNs are reserved:

   * 8074, 8075, 12076, 65515 - 65520 (reserved in Azure)
   * 23456, 64496-64511, 65535 - 65551 (reserved by Internet Assigned Numbers Authority (IANA))

   <Image src="/images/override-service-asn.png" shadow={true} width={650} />

6. Click **Update**.

7. Click **Save**.

<Anchor name="asn-prepend" />

## Setting route advertisement priority with ASN prepend

The <Gloss term="ASN" anchor="asn" /> path length determines the route advertisement priority for outgoing BGP paths. The route with the shortest AS path has the highest preference, and it is preferred over any longer path advertisements. Longer path lengths have a lower priority. AS path prepending lengthens the path to lower the path priority.

Setting an ASN prepend value is optional.

**To set the path advertisement priority on an existing BGP connection**

1. In the <Link href="https://portal.megaport.com">Megaport Portal</Link>, go to the **Services** page.

2. Select the VXC and select the NAT Gateway A-End or B-End.

3. Next to the BGP connection, click **Edit**.

4. Select the **Advanced** tab.

   <Image src="/images/as-path-prepend.png" shadow={true} width={650} />

5. In the **AS Path Prepend** field, specify the number of additional times to add the local ASN to the BGP path. You can specify an integer from 1 to 10. For example, an AS path prepend value of *2* prepends the ASN to the existing AS path twice, creating an AS path length of 3. Higher numbers deprioritize the path.

6. Click **Update**.

7. Click **Save**.

**To set the path advertisement priority on a new BGP connection**

1. Add a new BGP connection.
2. Select the **Advanced** tab.
3. In the **AS Path Prepend** field, specify the number of additional times to add the local ASN to the BGP path. You can specify an integer from 1 to 10. For example, an AS path prepend value of *2* prepends the ASN to the existing AS path twice, creating an AS path length of 3. Higher numbers deprioritize the path.
4. Click **Add**.
5. Click **Save**.

<Anchor name="bfd-protocol" />

## Enabling the BFD protocol

BGP shares network reachability information with adjacent BGP systems, which are referred to as *neighbors* or *peers*. The <Gloss term="BFD" anchor="bfd" /> protocol runs independent of BGP and detects path failure between directly connected BGP neighbors, allowing for a faster BGP routing re-convergence time.

BGP sends keepalive messages at regular intervals to maintain the BGP session. If a BGP neighbor doesn't receive a keepalive message within the specified BGP timer interval, the BGP session is torn down and failover occurs to another BGP neighbor.

BFD provides a faster method for detecting path failure between directly connected BGP neighbors. BFD sends control messages at regular, shorter intervals to maintain the BFD session. If a BFD neighbor doesn't receive a control message within the specified BFD timer interval, the BFD session is torn down and notifications are sent to the BGP process, which then tears down the BGP session and fails over to another BGP neighbor.

When you enable BFD, the system automatically applies these fixed settings:

* <Gloss term="Transmit Interval" anchor="bfd-transmit" />: 300 milliseconds
* <Gloss term="Receive Interval" anchor="bfd-receive" />: 300 milliseconds
* <Gloss term="Multiplier" anchor="bfd-multiplier" />: 3

<Note>
  These settings apply to all BGP connections on the VXC where BFD is enabled.
</Note>

**To enable BFD**

1. In the <Link href="https://portal.megaport.com">Megaport Portal</Link>, go to the **Services** page.

2. Select the VXC and select the A-End or B-End.

3. Next to the BGP connection, click **Edit**.

4. Select the **Advanced** tab.

5. Next to the **Use BFD** field, click **On**.
   <Image src="/images/bfd-on.png" shadow={true} width={650} />

6. Click **Update**.

7. Click **Save**.

<Callout icon="triangle-exclamation" color="red">
  You must enable BFD on the BGP neighbor as well.
</Callout>

**Default BFD values by Cloud Service Provider (CSP)**

* **AWS Direct Connect** -- BFD is supported natively by AWS Direct Connect connections. AWS automatically enables asynchronous BFD for virtual interfaces. However, you must enable BFD on NAT Gateway VXCs to AWS Direct Connect for your connection.

  By default, the AWS BFD liveness detection minimum interval is 300 milliseconds and the multiplier is 3 packets.

  <Note>
    Confirm support for other neighbors with your CSP, as well as specific default values.
  </Note>

* **Azure ExpressRoute** -- BFD is supported natively by Azure ExpressRoute on private peering. Azure configures BFD by default for all newly created ExpressRoute private peering interfaces on the Microsoft Enterprise Edge (MSEE). You must configure the NAT Gateway VXCs to Azure ExpressRoute private peering for BFD to enable it for your connection. Between BFD peers, the slowest peer determines the transmission rate.

* **Microsoft Enterprise Edge (MSEE) ExpressRoute routers** -- MSEE ExpressRoute routers have BFD transmit and receive intervals of 300 milliseconds.

* **Google Cloud Services** -- You can enable and configure BFD on Google Cloud Partner Interconnects. For more information, see the Google Cloud documentation to [Configure BFD for Cloud Router](https://docs.cloud.google.com/network-connectivity/docs/router/how-to/configuring-bfd#configure-peer-router).

<Anchor name="as-override" />

## Enabling AS Override

Each participant in a BGP session is identified by an AS number (autonomous system number). BGP has a built-in mechanism for preventing routing loops; if a router receives a route that already contains its own AS number in the path, the router rejects it.

When you enable AS Override, the { productShort_0 } replaces the peer's AS number with its own in the route advertisement, bypassing the loop-detection check of the downstream device.

For example, a company has two sites (New York and London) that use the same AS number (AS 65001) and are connected through { productShortWithArticle_0 } (AS 100):

1. The New York site (AS 65001) advertises a route to the { productShort_0 } (AS 100).
2. The { productShort_0 } (AS 100) passes that route to the London site.
3. The London router (AS 65001) sees AS 65001 in the AS\_PATH and rejects the prefix.

In the same scenario with AS Override enabled:

1. The New York site (AS 65001) advertises a route to the { productShort_0 } (AS 100).
2. The { productShort_0 } (AS 100) passes that route to the London site. The { productShort_0 } replaces AS 65001 with AS 100 in the AS\_PATH.
3. The London router (AS 65001) sees AS 100 in the AS\_PATH and accepts the prefix because it doesn't match its own AS number.

<Note>
  You can only enable AS override on eBGP (external BGP) connections, where the Peer ASN and Local ASN are different. You cannot apply AS override to iBGP (internal BGP) connections, where the Peer ASN and Local ASN are the same.
</Note>

**To enable AS override**

1. In the <Link href="https://portal.megaport.com">Megaport Portal</Link>, go to the **Services** page.

2. Select the VXC, then select the A-End or B-End.

3. Next to the BGP connection, click **Edit**.

4. Select the **Advanced** tab.

5. Next to **AS Override**, click **On** to enable it.

   <Image src="/images/as-override.png" shadow={true} width={650} />

6. Click **Update**.

7. Click **Save**.

**To disable AS override**

1. In the <Link href="https://portal.megaport.com">Megaport Portal</Link>, go to the **Services** page.
2. Select the VXC, then select the A-End or B-End.
3. Next to the BGP connection, click **Edit**.
4. Select the **Advanced** tab.
5. Next to **AS Override**, click **Off** to disable it.
6. Click **Update**.
7. Click **Save**.

<Anchor name="med" />

<Anchor name="med" />

## Configuring a preferred route with MED

Multi-Exit Discriminator (MED) is a BGP path attribute that can influence a BGP neighbor to take a preferred route when the advertising autonomous system (AS) is the same for candidate routes, and there are multiple entry points for that AS. A lower MED metric is preferred over a higher metric.

Autonomous systems consider other BGP attributes before the MED attribute. The MED attribute breaks the tie between two routes when the weight, local preference, AS path, and origin type are the same. The exit point with the lowest MED metric is preferred.

For example, if you have a configuration that consists of two BGP neighbor devices, which are both members of the same autonomous systems (AS), AS 4 and AS 5:

* R2, with a MED metric of 10
* R3, with a MED metric of 20

AS 4 will prefer the path through R2 to reach AS 5.

Adding or changing an MED metric doesn't disrupt the service.

**To configure the MED**

1. In the <Link href="https://portal.megaport.com">Megaport Portal</Link>, go to the **Services** page.

2. Select the VXC and select the A-End or B-End.

3. Next to the BGP connection, click **Edit**.

4. Select the **Advanced** tab.

5. In the **Inbound** field, specify a 32-bit integer MED metric to apply to all routes received on this BGP connection. Leave blank to use the value received from the BGP neighbor.
   <Image src="/images/med.png" shadow={true} width={650} />

6. In the **Outbound** field, specify a 32-bit integer MED metric to apply to all routes transmitted by this BGP connection.

7. Click **Update**.

8. Click **Save**.

**Using MED with Google Cloud Platform**

Google Cloud Platform Cloud Router egress is determined by the first condition that is met:

* All egress traffic is sent to the route with the shortest AS path length.
* If routes have the same AS path lengths, all egress traffic is sent to the route with the lowest MED value (the lowest route metric).
* If routes have the same AS path lengths and MED values (the same route metrics), egress traffic is balanced across all routes using equal-cost multipath (ECMP).

<Note>
  Confirm support for other neighbors with your CSP, along with any specific routing metric influences that might have a higher priority than the MED.
</Note>

## Helpful references

* [Configuring BGP for Megaport NAT Gateway](/nat/configure-bgp)
* [Creating a NAT Gateway VXC](/nat/nat-gateway-vxc)
* [Megaport NAT Gateway Route Filtering](/nat/route-filtering)
* [NAT Gateway Features](/nat/nat-gateway-features)
