Skip to content

Instantly share code, notes, and snippets.

@hoanganhcoder
Last active June 5, 2025 13:50
Show Gist options
  • Save hoanganhcoder/bf68f645b4a785b9413c867563b0b3a9 to your computer and use it in GitHub Desktop.
Save hoanganhcoder/bf68f645b4a785b9413c867563b0b3a9 to your computer and use it in GitHub Desktop.
Hướng Dẫn Thiết Lập Proxy Telegram - Proxy truy cập Telegram qua các khi vực bị chặn

📡 Hướng Dẫn Thiết Lập Proxy Telegram (MTProxy) Trên Ubuntu 22.04

🛡️ Giới Thiệu

MTProxy là proxy chính thức do Telegram phát triển, giúp người dùng vượt qua các lệnh cấm hoặc hạn chế truy cập Telegram. Proxy này được tích hợp sẵn trong các ứng dụng Telegram (cả di động và máy tính), cho phép kết nối dễ dàng chỉ với một vài thao tác.

🔐 Tính Năng Bảo Mật

  • An toàn: MTProxy sử dụng giao thức bảo mật MTProto của Telegram. Proxy chỉ thấy lưu lượng được mã hóa và không thể giải mã nội dung tin nhắn.
  • Ẩn danh: Proxy không biết ai đang sử dụng nó; chỉ thấy danh sách các địa chỉ IP.

⚙️ Hướng Dẫn Cài Đặt MTProxy Trên Ubuntu 22.04

1. Khởi Tạo Máy Chủ

  • Dịch vụ: Ubuntu
  • Cấu hình đề xuất: 512MB RAM, 2 vCPU, 1TB băng thông.
  • Lưu ý: Chọn vị trí máy chủ ở nơi không bị chặn Telegram.

2. Kết Nối SSH Vào Máy Chủ

ssh ubuntu@<địa_chỉ_IP>

3. Cập Nhật Hệ Thống

sudo apt-get update

4. Cài Đặt Các Gói Cần Thiết

sudo apt install git curl build-essential libssl-dev zlib1g-dev

update : Với các hệ thống Centos thì cần cài thêm 1 số lib c++

sudo dnf install git curl make automake gcc gcc-c++ kernel-devel g++ openssl-devel zlib-devel xxd

5. Tải Mã Nguồn MTProxy

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

6. Chỉnh Sửa Makefile

Mở tệp Makefile và thêm -fcommon vào cuối dòng COMMON_CFLAGSCOMMON_LDFLAGS:

nano Makefile

7. Biên Dịch MTProxy

make

8. Di Chuyển Tệp Nhị Phân

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

9. Chuyển Đến Thư Mục Mới

cd /opt/MTProxy

10. Tải Khóa Bí Mật Từ Telegram

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

11. Tải Cấu Hình Từ Telegram

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

12. Tạo Khóa Bí Mật Cho Proxy

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

Lưu lại chuỗi hex này để sử dụng sau.

13. Tạo Người Dùng mtproxy

sudo useradd -m -s /bin/false mtproxy

14. Cập Nhật Quyền Sở Hữu Thư Mục

sudo chown -R mtproxy:mtproxy /opt/MTProxy

15. Mở Cổng 8443

  • Nếu bạn đang sử dụng ufw, chạy lệnh:
sudo ufw allow 8443/tcp

16. Xác Định Địa Chỉ IP Riêng Và Công Khai

ip add

tìm trong kết quả : inet <PUBLIC_IP>/.. brd <PRIVATE_IP> scope global eth0

17. Tạo Dịch Vụ systemd Cho MTProxy

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

Thêm nội dung sau, thay thế <YOUR_SECRET_FROM_STEP_12>, <YOUR_PRIVATE_IP>, và <YOUR_PUBLIC_IP>:

[Unit]
Description=MTProxy
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/MTProxy
ExecStart=/opt/MTProxy/mtproto-proxy -u mtproxy -p 8888 -H 8443 -S <YOUR_SECRET_FROM_STEP_12> --aes-pwd proxy-secret proxy-multi.conf -M 1 --http-stats --nat-info <YOUR_PRIVATE_IP>:<YOUR_PUBLIC_IP>
Restart=on-failure

[Install]
WantedBy=multi-user.target

18. Tải Lại systemd Và Khởi Động Dịch Vụ

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

19. Kích Hoạt Dịch Vụ Khi Khởi Động

sudo systemctl enable MTProxy.service

20. Thiết Lập Cron Job Để Cập Nhật Cấu Hình Hàng Ngày ( Option, có thể không cần thiết)

sudo su
crontab -e

Thêm dòng sau:

0 4 * * * curl -s https://core.telegram.org/getProxyConfig -o /opt/MTProxy/proxy-multi.conf && chown -R mtproxy:mtproxy /opt/MTProxy && systemctl restart MTProxy.service

🔗 Kết Nối Telegram Với Proxy

Thay <YOUR_PUBLIC_IP><YOUR_SECRET_FROM_STEP_12>:

tg://proxy?server=<YOUR_PUBLIC_IP>&port=8443&secret=<YOUR_SECRET_FROM_STEP_12>

Liên kết HTTP:

https://t.me/proxy?server=<YOUR_PUBLIC_IP>&port=8443&secret=<YOUR_SECRET_FROM_STEP_12>

Bật random padding (thêm dd vào đầu secret):

https://t.me/proxy?server=<YOUR_PUBLIC_IP>&port=8443&secret=dd<YOUR_SECRET_FROM_STEP_12>

📊 Theo Dõi Trạng Thái Proxy

có thể dùng tuner ssh s2c để xem được ở máy client

curl localhost:8888/stats

🎉 Hoàn Tất!

Bạn có thể đăng ký proxy tại @MTProxybot. Sau khi đăng ký, bạn sẽ nhận được một tag để thêm vào lệnh khởi động trong file systemd, khi đăng kí tag có thể chọn channel Proxy Sponsor :

ExecStart=/opt/MTProxy/mtproto-proxy -u mtproxy -p 8888 -H 8443 -S <SECRET> -P <TAG> --aes-pwd proxy-secret proxy-multi.conf -M 1 --http-stats --nat-info <PRIVATE_IP>:<PUBLIC_IP>
@Thawor
Copy link

Thawor commented May 25, 2025

bạn ơi, trên centos 9 thì làm như thế nào nhỉ. mình chạy toàn fail thôi.

@hoanganhcoder
Copy link
Author

bạn ơi, trên centos 9 thì làm như thế nào nhỉ. mình chạy toàn fail thôi.

bạn cài thêm depend : sudo dnf install git curl make automake gcc gcc-c++ kernel-devel g++ openssl-devel zlib-devel xxd

@namcxn
Copy link

namcxn commented May 26, 2025

sao lắm bước thế, dùng 1 lệnh thôi là chạy được bằng docker rồi

To start the proxy all you need to do is docker run -d -p443:443 --name=mtproto-proxy --restart=always -v proxy-config:/data telegrammessenger/proxy:latest 
The container's log output (docker logs mtproto-proxy) will contain the links to paste into the Telegram app:
[+] Using the explicitly passed secret: '00baadf00d15abad1deaa515baadcafe'.
[+] Saving it to /data/secret.
[*] Final configuration:
[*]   Secret 1: 00baadf00d15abad1deaa515baadcafe
[*]   tg:// link for secret 1 auto configuration: : tg://proxy?server=3.14.15.92&port=443&secret=00baadf00d15abad1deaa515baadcafe
[*]   t.me link for secret 1: tg://proxy?server=3.14.15.92&port=443&secret=00baadf00d15abad1deaa515baadcafe
[*]   Tag: no tag
[*]   External IP: 3.14.15.92
[*]   Make sure to fix the links in case you run the proxy on a different port.

ref: https://hub.docker.com/r/telegrammessenger/proxy/

@hoanganhcoder
Copy link
Author

Có nhiều Option mà bạn, mình dùng telegrammessenger/proxy/ bị lỗi trong khi chạy nên chuyển qua GetPageSpeed/MTProxy
MTProxy by GetPageSpeed
Simple MT-Proto proxy.
This is a fork of MTProxy which includes various improvements and fixes that upstream has not merged due to abandonding their repository. Most of these fixes aim for stable running of MTProxy in production without surprises.`

Nên mình share cái nào chạy ổn hơn thôi 😅

@sshkarbanov
Copy link

Works perfect, Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment