Simple MT-Proto proxy
Install dependencies, you would need common set of tools for building from source, and development packages for openssl and zlib.
On Debian/Ubuntu:
apt install git curl build-essential libssl-dev zlib1g-devOn CentOS/RHEL:
yum install openssl-devel zlib-devel
yum groupinstall "Development Tools"Clone the repo:
git clone https://github.com/TelegramMessenger/MTProxy
cd MTProxyTo build, simply run make, the binary will be in objs/bin/mtproto-proxy:
make && cd objs/binIf the build has failed, you should run make clean before building it again.
- Obtain a secret, used to connect to telegram servers.
curl -s https://core.telegram.org/getProxySecret -o proxy-secret- Obtain current telegram configuration. It can change (occasionally), so we encourage you to update it once per day.
curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf- Generate a secret to be used by users to connect to your proxy.
head -c 16 /dev/urandom | xxd -ps- Run
mtproto-proxy:
./mtproto-proxy -u nobody -p 8888 -H 443 -S <secret> --aes-pwd proxy-secret proxy-multi.conf -M 1... where:
nobodyis the username.mtproto-proxycallssetuid()to drop privileges.443is the port, used by clients to connect to the proxy.8888is the local port. You can use it to get statistics frommtproto-proxy. Likewget localhost:8888/stats. You can only get this stat via loopback.<secret>is the secret generated at step 3. Also you can set multiple secrets:-S <secret1> -S <secret2>.proxy-secretandproxy-multi.confare obtained at steps 1 and 2.1is the number of workers. You can increase the number of workers, if you have a powerful server.
Also feel free to check out other options using mtproto-proxy --help.
- Generate the link with following schema:
tg://proxy?server=SERVER_NAME&port=PORT&secret=SECRET(or let the official bot generate it for you). - Register your proxy with @MTProxybot on Telegram.
- Set received tag with arguments:
-P <proxy tag> - Enjoy.
Due to some ISPs detecting MTProxy by packet sizes, random padding is added to packets if such mode is enabled.
It's only enabled for clients which request it.
Add dd prefix to secret (cafe...babe => ddcafe...babe) to enable
this mode on client side.
- Create systemd service file (it's standard path for the most Linux distros, but you should check it before):
nano /etc/systemd/system/MTProxy.service- Edit this basic service (especially paths and params):
[Unit]
Description=MTProxy
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/MTProxy
ExecStart=/opt/MTProxy/mtproto-proxy -u nobody -p 8888 -H 443 -S <secret> -P <proxy tag> <other params>
Restart=on-failure
[Install]
WantedBy=multi-user.target- Reload daemons:
systemctl daemon-reload- Test fresh MTProxy service:
systemctl restart MTProxy.service
# Check status, it should be active
systemctl status MTProxy.service- Enable it, to autostart service after reboot:
systemctl enable MTProxy.serviceghcr.io/dzalunin/mtproxy:latest
Install docker https://docs.docker.com/engine/install/
Create a docker-compose.yml file.
services:
mtproxy:
image: ghcr.io/dzalunin/mtproxy:latest
container_name: mtproxy
ports:
- "443:443"
environment:
- MT_FAKETLS_DOMAIN=www.google.com
volumes:
- ./config:/etc/mtproxy
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8888/stats"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
Run:
docker compose up -dAfter startup, run docker compose logs, copy connection links:
======== Connection Links ========
https://t.me/proxy?server=1.2.3.4&port=443&secret=ee1...
https://t.me/proxy?server=1.2.3.4&port=443&secret=ee2...
| Variable | Description | Default |
|---|---|---|
MT_HTTP_PORT |
Proxy port | 443 |
MT_STATS_PORT |
Stats port | 8888 |
MT_WORKERS |
Worker count (use 1 for TLS) | 1 |
MT_MAX_CONNECTIONS |
Max connections | 60000 |
MT_SECRET |
Secret(s), comma-separated | auto |
MT_SECRET_COUNT |
Number of generated secrets | 1 |
MT_FAKETLS_DOMAIN |
FakeTLS domain | empty |
MT_AUTO_UPDATE_CONFIG |
Auto-update Telegram config | 1 |
EXTERNAL_IP |
External IP (if auto-detect fails) | auto |
Supported formats:
-
Single secret:
32 hex characters -
Multiple secrets:
secret1,secret2,secret3
If not provided, they are generated automatically. Secret can be generated by head -c 16 /dev/urandom | od -An -tx1 | tr -d ' \n'
| Port | Description |
|---|---|
| 443 | MTProto proxy |
| 8888 | Stats endpoint |
Enable via:
environment:
- MT_FAKETLS_DOMAIN=www.google.comRequirements:
- domain must resolve correctly
- use popular domains (Cloudflare, Google, etc.)
The container uses:
/etc/mtproxy
It stores:
proxy-secret— Telegram server keyproxy-multi.conf— Telegram configsecret— user secrets