How to Set Up MTProto Proxy for Telegram on Ubuntu 22.04

Estimated reading: 3 minutes 168 views

Introduction

MTProxy is Telegram’s official proxy protocol designed to improve connection reliability and privacy in certain network environments.
This guide will walk you through the process of setting up an MTProxy server on Ubuntu for testing, educational, or internal use. Please ensure all usage complies with your local laws and regulations..

Server Installation

1. SSH into your server

ssh root@your_server_ip

2. Update the system and install dependencies

sudo apt-get update -y
sudo apt install git curl build-essential libssl-dev zlib1g-dev -y

3. Clone the MTProxy repository

We recommend using the community-maintained fork for better reliability:

git clone https://github.com/GetPageSpeed/MTProxy
cd MTProxy

4. Modify the Makefile

Add -fcommon flag to both COMMON_CFLAGS and COMMON_LDFLAGS:

nano Makefile

5. Compile MTProxy

make

6. Install the binary

sudo mkdir /opt/MTProxy
sudo cp objs/bin/mtproto-proxy /opt/MTProxy/
cd /opt/MTProxy

7. Download configuration files

sudo curl -s https://core.telegram.org/getProxySecret -o proxy-secret
sudo curl -s https://core.telegram.org/getProxyConfig -o proxy-multi.conf

8. Generate your secret key

head -c 16 /dev/urandom | xxd -ps

Save this output for later use.

9. Create a dedicated user

sudo useradd -m -s /bin/false mtproxy
sudo chown -R mtproxy:mtproxy /opt/MTProxy

10. Configure the firewall

sudo ufw allow <YOUR_PORT>/tcp

 

11. Set up a systemd service

Create a service file:

sudo nano /etc/systemd/system/MTProxy.service

Paste this configuration (replace placeholders with your actual values):

[Unit]
Description=MTProxy
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/MTProxy
ExecStart=/opt/MTProxy/mtproto-proxy -u mtproxy -p 8888 -H <MTPROXY_PORT> -S <YOUR_SECRET STEP 8> --aes-pwd proxy-secret proxy-multi.conf -M 1
Restart=on-failure

[Install]
WantedBy=multi-user.target

 

Note: Port 8443 is used as an example. You can replace it with any other port you prefer. Just make sure the chosen port is open in your firewall and matches the one used in the service configuration below.

12. Start the service

sudo systemctl daemon-reload
sudo systemctl restart MTProxy.service
sudo systemctl status MTProxy.service

Connecting via Telegram

Method 1: Direct link connection

Create a connection link in this format:

tg://proxy?server=<SERVER_IP>&port=<MTPROXY_PORT>&secret=<SECRET_KEY>

Open this link directly in your mobile browser or share it through any app.

Method 2: Manual proxy configuration

  1. Open the Telegram app

  2. Go to Settings > Data and Storage > Proxy Settings

  3. Tap “Add Proxy.”

  4. Enter:

  • Server: Your server IP/domain
  • Port: <MTPROXY_PORT>
  • Secret: Your generated secret key (step 8)

5. Tap “Save” and enable the proxy

Conclusion

You’ve successfully deployed a high-performance MTProxy server for Telegram. This solution provides:

  • Improved connection reliability

  • Encrypted and secure communication

  • Enhanced accessibility in limited connectivity environments

For optimal performance, consider setting up a domain name with SSL instead of using raw IP addresses.

Share this Doc

How to Set Up MTProto Proxy for Telegram on Ubuntu 22.04

Or copy link

CONTENTS