Preparation#
An old phone that is still functional (a new phone will also work)
Termux software
A domain name (you can get a free one from Freenom)
A Cloudflare account with domain proxy enabled
Installing Linux on Termux#
I will demonstrate the process on an Android 11 phone
After installation, open Termux
Installing openssh#
Since it's not easy to operate on a phone, I will use ssh. If you are comfortable operating on a phone, you can skip this step. Alternatively, you can install any other ssh software you prefer.
After opening the software, enter pkg install openssh
(I forgot to take a screenshot here)
After installation, enter passwd
to set a password
Then enter sshd
to start openssh
Enter whoami
to get the username
Enter ifconfig
to get the IP address
Connecting via ssh from a computer#
The port is the port of the ssh service, and the default port for openssh is 8022
On your computer, use ssh -p port username@ip_address
to connect (replace port
with the actual port number and username@ip_address
with the username and IP address you obtained earlier)
Installing Linux#
Once connected, enter bash <(curl -L gitee.com/mo2/linux/raw/2/2)
to install Linux
You can use other installation methods if you prefer. If you have another method, you can skip this step.
Choose the first proot container
You may see a screen to choose the container again, but I didn't capture it. Just choose the first proot container again.
Choose the first neon option
Choose any font you like
Choose the first option
Choose the first option
Choose the Linux distribution you want to use. However, please note that the official Cloudflare documentation only supports a few Linux distributions.
You can just click through the rest
I recommend installing a VNC server on this screen because later on, Cloudflare will require browser login, which requires a graphical interface.
Installing and starting the web service#
You can search for instructions on how to install a web service
Installing cloudflared#
Go to https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation/ and choose the appropriate installation method for your operating system
If you're not sure which one to choose, click on "Cloudflare package repository"
Follow the instructions in the official documentation to install (I forgot to take a screenshot here)
Logging in and creating a tunnel#
Then open a remote desktop connection
In the terminal, enter cloudflared tunnel login
A link will appear, click on the link to log in
After logging in, click on the link in the terminal again and select your domain name
VNC might be slow, so now go back to the ssh terminal. Enter cloudflared tunnel create tunnel_name
to create a tunnel. You can choose any name for the tunnel (replace tunnel_name
with your desired name).
Then enter cloudflared tunnel list
to check if the tunnel has been successfully created and copy the tunnel ID
Binding the domain name#
Enter cloudflared tunnel route dns tunnel_name domain_name
to bind the domain name
tunnel_name
is the name of the tunnel you created earlier, and domain_name
is your own domain name
Writing the configuration file#
Enter nano ~/.cloudflared/config.yml
to write the following configuration
tunnel: <tunnel_ID>
credentials-file: /root/.cloudflared/<tunnel_ID>.json
protocol: http2
originRequest:
connectTimeout: 30s
noTLSVerify: false
ingress:
- hostname: <domain_name>
service: http://localhost:port
- service: http_status:404
If you want to open multiple ports, you can follow the example in the image below
After saving, enter
nano /etc/systemd/system/cloudflared.service
and write the following
[Unit]
Description=cloudflared
After=network.target
[Service]
TimeoutStartSec=0
Type=notify
ExecStart=/usr/bin/cloudflared --loglevel debug --transport-loglevel warn --config /root/.cloudflared/config.yml tunnel run <tunnel_name>
Restart=on-failure
RestartSec=5s
[Install]
WantedBy=multi-user.target
Make sure there are no line breaks
Save the file
Starting the service#
Enter systemctl enable cloudflared --now
Testing if it's successful#
Open the website and see if the penetration is successful
Other#
Other services are also supported, please refer to the documentation
To access via ssh, you need to set up the local terminal
https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/use_cases/ssh/
To access via ssh in a browser, you need to configure it in the Cloudflare Zero panel. You can refer to the documentation or I can write another post about it.
I have tested that running a web service on Termux can also be accessed through Linux, so it should not be limited to software. You can also try installing KSWeb on your phone.