# What a target can be

Source: https://tiltas.openpanel.sh/docs/services/targets

> Where a Service sends its traffic, as seen from the Device that hosts it, and which addresses are refused.

A Service's **target** is `host:port` as seen from the Device that hosts the Service. That Device connects to it for
every visitor, so the target can be the Device itself or a computer the Device can reach on its own network.

| Target | Means |
|---|---|
| `localhost:3000` | a program on the hosting Device itself (its loopback, `127.0.0.1`) |
| `192.168.1.20:8123` | another computer on the hosting Device's LAN, such as Home Assistant |
| `printer.lan:631` | a name, resolved by the hosting Device |

A Web Service's target always has a port. A TCP Service's target may leave it out when the Service lists its
[ports](/docs/services/tcp#ports).

## Names and addresses

- **A name** is looked up by the hosting Device, once for each connection, and the connection goes to exactly the address
  it found. That address must be the Device's own loopback or on one of the Device's own networks; a name that points
  anywhere else is refused.
- **An address written out**, such as `10.20.0.5:5432`, may be anywhere the hosting Device can reach, except the
  addresses below.

## Addresses that are always refused

The hosting Device never connects to these, even when the target names them:

| Range | What it is |
|---|---|
| `169.254.0.0/16` | IPv4 link-local, which includes cloud metadata services such as `169.254.169.254` |
| `fe80::/10` | IPv6 link-local |
| `fd00:ec2::254` | the IPv6 metadata service of AWS |
| `100.64.0.0/10` | Device and Service addresses: a Service cannot point back into the Network |
| `fd7a:115c:a1e0::/48` | Device addresses in IPv6 |
| `0.0.0.0`, `::`, multicast and `255.255.255.255` | not addresses of a single computer |

The console and the API refuse a link-local, multicast or unspecified address when you save the Service ("This target
address is not allowed."). The hosting Device checks every connection again, including names that resolve to one of
these, and the visitor gets **Service unreachable** with "The Service's target is an address this Device may not
reach."

Blocking metadata addresses keeps a Service on a cloud server from handing out that server's credentials to anyone who
may open the Service.

## Web targets speak HTTP

A Web Service connects to its target over plain HTTP, and the target is written without `http://`. A program that only
answers HTTPS, such as a NAS's management page on port 5001, needs its HTTP port instead; or create a
[TCP Service](/docs/services/tcp) for it, and the browser speaks HTTPS to the program directly.

The program receives:

- the name the visitor used in `Host`, such as `gitea`, so the links it builds keep working;
- `X-Forwarded-For` set to the visitor's Device address, with `X-Forwarded-Host` and `X-Forwarded-Proto`;
- WebSockets and streamed responses as they are.

Any `Forwarded` or `X-Real-IP` header the visitor sent is removed. For who the visitor is, see
[Identity headers](/docs/services/identity-headers).

## Keep the program on localhost

If the program listens only on `127.0.0.1` and the Service's target is `localhost:port`, the Service is the only way to
reach it. A program that also listens on the LAN can be opened from the LAN without Tiltas, and without its checks.
