---
title: "Route incoming trunk calls by caller origin and number"
description: "Use SIP trunk routing rules to send mobile and landline callers to different gateways, route by caller country, or add a prefix by caller origin."
canonical: "https://bird.com/docs/guides/voice/trunk-routing-rules"
---

# Route incoming trunk calls by caller origin and number

A SIP trunk's **Inbound routing** can treat calls differently depending on who is calling and which number they dialed. Rules check facts about each call, such as the caller's line type or country, and pick what happens: send the call to a group of gateways, change the number your equipment receives, reject it, or forward it. This page gives working setups for the most common cases.

## Before you start

- A SIP trunk with inbound calling on, its gateways in at least one group, and your numbers pointed at it. [Set up a SIP trunk](/docs/guides/voice/sip-trunk-setup) covers all three.
- Open **Voice** > [**SIP Trunks**](https://bird.com/dashboard/w/voice/sip-trunks), open the trunk, and go to **Inbound routing** > **Rules**.

## How rules work

Bird checks the rules from top to bottom for each incoming call. The first rule whose **When** matches decides the call; a call that matches no rule uses the **Default route** (**No rule above matched**). Each rule and the default route has a **Then**: **Route to group**, **Reject**, or **Forward to number**. A trunk holds up to 50 rules.

A **When** is a condition over these call facts. Select a fact from the list, or use **Edit expression** to write the condition yourself.

| Fact              | What it holds                                                                                            |
| ----------------- | -------------------------------------------------------------------------------------------------------- |
| `orig.line_type`  | The caller's line type: `LINE_FIXED`, `LINE_MOBILE`, `LINE_TOLL_FREE`, `LINE_PAYPHONE` or `LINE_UNKNOWN` |
| `orig.country`    | The caller's two-letter country code, such as `GB`. Empty when the caller withheld their number          |
| `orig.anonymous`  | `true` when the caller withheld their number                                                             |
| `orig.number`     | The caller's number in E.164, with `+`                                                                   |
| `orig.digits`     | The caller's number without the leading `+`                                                              |
| `dest.number`     | The number that was dialed, in E.164, with `+`                                                           |
| `dest.digits`     | The number that was dialed, without the leading `+`                                                      |
| `call.local_hour` | The hour of the call, 0 to 23, in the routing's time zone                                                |
| `call.weekday`    | The day of the call, in the routing's time zone                                                          |

Write line types as constants, such as `orig.line_type == LINE_MOBILE`. An unknown constant fails when you save, while a misspelled string such as `"LINE_MOBLE"` is accepted and never matches.

## Send mobile and landline callers to different gateways

Use this when, for example, mobile callers should reach one SBC and everyone else another.

1. In **Groups**, create a group for each destination, for example `mobile` with your mobile SBC and `landline` with the other.
2. In **Rules**, select **Add rule** and name it _Mobile callers_. Set **When** to **Line type** with the value `LINE_MOBILE`.
3. Set **Then** to **Route to group** and choose `mobile`.
4. Set the **Default route** to **Route to group** and choose `landline`. It takes every call the rule did not match.
5. Select **Review and save**, then confirm.

The same pattern routes by country: set **When** with **Edit expression** to a condition such as `orig.country == GB`.

## Add a prefix by caller origin

Your SBC may expect a prefix in front of the dialed number that tells it the caller's origin, for example `801` for landline, `802` for mobile and `800` for anything else. Bird changes the user part of the Request-URI it sends to your gateway; the gateway's host and port stay the same. For a call to `+44 808 157 0123`, a mobile caller then arrives as `sip:802448081570123@198.51.100.20`.

You can set this up in two equivalent ways.

### One rule per origin

Use this when each origin should show as its own entry in the editor, or when origins differ by more than the prefix, such as a different group.

1. In **Rules**, select **Add rule**, name it _Landline_, and set **When** to **Line type** with the value `LINE_FIXED`.
2. Set **Then** to **Route to group**, choose your group under **Group**, then select **Override R-URI user part**. Type `801`, then use **Insert** to add `dest.digits` after it.
3. Repeat for _Mobile_ (`LINE_MOBILE`, prefix `802`).
4. Set the **Default route** to **Route to group** with the user part `800` followed by `dest.digits`.
5. Select **Review and save**, then confirm.

### One expression

Use this when only the prefix changes. Leave **Rules** empty, set the **Default route** to **Route to group** with your group, select **Override R-URI user part**, insert this expression, and add `dest.digits` after it:

```text
orig.line_type == LINE_FIXED ? "801" : orig.line_type == LINE_MOBILE ? "802" : "800"
```

Both setups deliver the same `INVITE`. A gateway's own **R-URI user part** accepts only fixed text around the dialed number, so put a prefix that depends on the caller in a rule or in the default route, as above.

## Check your setup

1. **Review and save** checks every condition and template and lists the errors with where they are. Nothing is saved until they are fixed.
2. Call one of your numbers from a mobile phone, from a landline and with your number withheld. At your SBC, compare the Request-URI of each received `INVITE` with what you expect.
3. Open each call under **Voice** > [**Legs**](https://bird.com/dashboard/w/voice/legs) and use its **SIP Call-ID** to find the same call in your SBC's logs.

## Next steps

| Page                                                     | What it covers                                             |
| -------------------------------------------------------- | ---------------------------------------------------------- |
| [Receiving calls](/docs/guides/voice/receiving-calls)    | Number routes, groups, the default route and refused calls |
| [Set up a SIP trunk](/docs/guides/voice/sip-trunk-setup) | A whole trunk setup in order, from creation to a test call |
| [Placing calls](/docs/guides/voice/placing-calls)        | What Bird expects on the `INVITE` your equipment sends     |

## Related resources

- [What is a voice API?](/explained/voice/what-is-a-voice-api) (answer)
- [Voice](/voice-api) (product)
- [Voice overview](/docs/guides/voice/overview) (docs)

[Get an implementation brief](/learn/workspace?topic=voice)
