How to install MTProxy on CentOS 7 linux

to install this proxy in telegram app on mobile devices ,we need some reqirements

OS: CentOS 7 linux on VMWare.
Firewall: enabled
SElinux: enforcing

Install prerequisites:

at the beginning we install epel repository to install some packages and ssl.

# yum update
# yum install openssl-devel zlib-devel perl-core
# yum groupinstall "Development Tools"
# yum update curl nss

Upgrade openssl:

if openssl version shows you equal to 1.1.0 or higher, skip this step. so we check it:

# openssl version

and we see:

OpenSSL 1.0.2k-fips 26 Jan 2017

so run these instructins:

# cd /usr/local/src
# wget
# tar -zxf openssl-1.1.1d.tar.gz
# cd openssl-1.1.1d/
# ./config
# make
# make test
# make install

soft link to libssl is like this:

# ln -s /usr/local/lib64/ /usr/lib64/
# ln -s /usr/local/lib64/ /usr/lib64/

renaming old openssl and making soft link to new openssl is here:

# mv /usr/bin/openssl /usr/bin/openssl.old
# ln -s /usr/local/bin/openssl /usr/bin/openssl

check openssl version and it must be 1.1.0:

# openssl version
OpenSSL 1.1.1d 10 Sep 2019

Install MTproxy

in this step install git:

# yum install git

after that download mtproxy ,we find it on github:

# cd /opt/
# git clone
# cd MTProxy

open make file:

# vim Makefile

we see this line:

CFLAGS = $(ARCH) -O3 -std=gnu11 -Wall -mpclmul -march=core2 -mfpmath=sse -mssse3 -fno-strict-aliasing -fno-strict-overflow -fwrapv -DAES=1 -DCOMMIT=\"${COMMIT}\" -D_GNU_SOURCE=1 -D_FILE_OFFSET_BITS=64

and adding this line to the end of it:

-I/usr/local/src/openssl-1.1.1d/include/openssl -I/usr/local/src/openssl-1.1.1d/include/

easily find this line :

LDFLAGS = $(ARCH) -ggdb -rdynamic -lm -lrt -lcrypto -lz -lpthread -lcrypto

add this line to the end of above line:


changes is done when we execute make command:

# make

after make completion we can go to the next step.

Configure MTProxy

run this command to get secret and then connect telegram servers:

# curl -s -o proxy-secret

then run this command to obtining telegram configuration as you know we need it for our mtproxy server:

# curl -s -o proxy-multi.conf

Note: update the config once a day is better

Now we must generate a secret token for connecting to mtproxy,so the command is:

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

In return you will get this response:


Random Padding

As you know some ISPs ,determine MTProxy traffic by packet size then it’s better to enable random padding. to achieve it “dd” string must be added to the start of secret in telegram client.
changing it will be set in telegram client like this:


Systemd service

Running MTProxy as a service,need to create service file:

# vim /lib/systemd/system/MTProxy.service

put these lines in it:

[Unit] Description=MTProxy [Service] Type=simple WorkingDirectory=/opt/MTProxy ExecStart=/opt/MTProxy/objs/bin/mtproto-proxy -u nobody -p 8888 -H 443 -S b616b1c550f8fcce0a34465e0909b825 --aes-pwd proxy-secret proxy-multi.conf -M 1 Restart=on-failure [Install]

Note: replacing b616b1c550f8fcce0a34465e0909b825 with your own secret is Ok.

reload systemctl daemon:

# systemctl daemon-reload

At the end enable mtproxy service:

# systemctl enable MTProxy.service

Configure firewall

Run these commands to open port 443 and 8888 on firewall:

# firewall-cmd --add-port=443/tcp --permanent # firewall-cmd --add-port=8888/tcp --permanent

reload firewall:

# firewall-cmd --reload

Start MTproxy service

finally, to start mtproxy service run:

# systemctl start MTProxy.service

In telegram client, add new proxy and select MTProxy type, enter server ip address and port 443 and secret with adding “dd” string to start of it.

Promote Channel

When someone use your MTproxy,channel must be promote,to acheive it first send a message on telegram to @MTProxybot.

and you see, MTProxybot gives you a tag.

open MTProxy service file:

vim /lib/systemd/system/MTProxy.service

then edit line “ExecStart=/opt/MTProxy/objs/bin/mtproto-proxy -u nobody -p 8888 -H 443 -S b616b1c550f8fcce0a34465e0909b825 –aes-pwd proxy-secret proxy-multi.conf -M 1”

and add

“-P your_proxy_tag”.
save and run this command

# systemctl daemon-reload

Finally restart MTProxy service:

# systemctl restart MTProxy.service

How to install MTProxy on CentOS 7 linux

Leave a Reply

Your email address will not be published. Required fields are marked *