Sharing Wi-Fi with Termux: A Complete Guide with Commands and Settings

Mobile Internet on an Android device can be turned into a full-fledged Wi-Fi access point not only through the standard system settings, but also with the help of Termux — a powerful terminal emulator for AndroidThis method is relevant when the standard distribution function is blocked by the operator, works unstable or requires root rightsUnlike apps like NetShare or PdaNet, Termux allows you to flexibly configure network settings, including SSID, channel and even MAC address filtering.

It's important to understand that Termux distribution isn't just an alternative to the built-in feature, but a tool for advanced users. There's no graphical interface, and all settings are configured through command lineHowever, with the correct configuration, such hotspot may be more stable than the standard one, especially on devices with custom firmware or older versions Android (below 10th). In this article, we will look at two main methods: using a utility hostapd (for devices with support Wi-Fi Direct) and through iptables + dnsmasq (universal method).

Preparing the device: what you need to do before you start

Before you begin setup, make sure your device meets the minimum requirements:

  • 📱 Android version: 7.0 and above (on Android 6.0 and below may be required root rights).
  • 🔧 Termux: installed from F-Droid (version from Google Play is outdated and does not support packages).
  • 📶 Wi-Fi module: must support the mode AP (Access Point)You can check this with the command iw list | grep "AP".
  • 🔌 Battery charge: not less than 50% (the setup and distribution process consumes energy intensively).

If your device does not support the mode AP, distribution via Termux will be impossible without root or kernel modifications. Also note that some operators (e.g., MTS or Beeline) may block distribution on tariffs with unlimited Internet - in this case, a bypass will be required via VPN or change TTL.

⚠️ Attention: On devices with processors MediaTek (For example, Redmi Note 8 Pro or Realme 6) Additional driver configuration may be required. Check the compatibility of your model on the forums. 4PDA or XDA Developers.

Before you begin, update packages in Termux:

pkg update && pkg upgrade -y

pkg install root-repo x11-repo -y # For advanced features (optional)

Method 1: Sharing via hostapd (for devices with AP support)

Utility hostapd (Host Access Point Daemon) is a standard solution for organizing an access point in Linux-systems. In Android It can be launched via Termux, but with some limitations. This method is suitable for devices whose Wi-Fi adapter supports the mode. master (for example, most of the pictures on Qualcomm Snapdragon).

Setup steps:

  1. Install the required packages:
    pkg install hostapd dnsmasq -y
  2. Create a configuration file for hostapd:
    mkdir -p ~/wifi-ap
    

    echo 'interface=wlan0

    driver=nl80211

    ssid=MyTermuxAP

    hw_mode=g

    channel=6

    wpa=2

    wpa_passphrase=12345678

    wpa_key_mgmt=WPA-PSK

    rsn_pairwise=CCMP' > ~/wifi-ap/hostapd.conf

    Here wlan0 — the name of your Wi-Fi interface (check through ip a), A MyTermuxAP And 12345678 — network name and password respectively.

  3. Configure a DHCP server (dnsmasq):
    echo 'interface=wlan0
    

    dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,24h

    dhcp-option=3,192.168.1.1

    dhcp-option=6,192.168.1.1

    server=8.8.8.8

    log-dhcp' > ~/wifi-ap/dnsmasq.conf

After creating the configs, start the services:

hostapd ~/wifi-ap/hostapd.conf &

dnsmasq -C ~/wifi-ap/dnsmasq.conf -d &

echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A POSTROUTING -o rmnet_data -j MASQUERADE

⚠️ Attention: If after launch hostapd you see an error nl80211: Could not configure driver mode, your Wi-Fi adapter does not support the mode AP. Try it. An alternative method is with iptables or use an external USB Wi-Fi adapter with SoftAP support..

The device supports AP mode (checked via iw list)

Termux has access to /proc and /sys (no errors when writing to ip_forward)

The Wi-Fi password must be at least 8 characters long.

The wlan0 interface is not busy with other processes (check with netstat -tulnp)-->

Method 2: Universal distribution via iptables and dnsmasq

If hostapd It doesn't work, you can organize distribution through a bridge between Wi-Fi and mobile Internet (tethering). This method is less stable, but works on most devices, including those whose Wi-Fi adapter does not support the mode. AP. Operating principle: Android creates a virtual interface, and iptables redirects traffic.

Instructions:

  • 🔄 Activate modem mode in Android settings (Settings → Wireless & networks → Tethering & portable hotspot).
  • 📡 Install the required packages:
    pkg install iptables dnsmasq -y
  • 🔧 Configure NAT (traffic redirection):
    iptables -t nat -A POSTROUTING -o rmnet_data -j MASQUERADE
    

    iptables -A FORWARD -i wlan0 -o rmnet_data -j ACCEPT

    echo 1 > /proc/sys/net/ipv4/ip_forward

    Here rmnet_data — mobile internet interface (may be called rmnet0 or ccmni0; please check through ifconfig).

  • 🌐 Start the DHCP server:
    dnsmasq -i wlan0 --dhcp-range=192.168.1.100,192.168.1.200,255.255.255.0,24h

After executing the commands, connect to the network MyTermuxAP (or other specified SSID) from another device. If the internet isn't working, check:

  • 🔌 Is the mobile internet interface specified correctly? (rmnet_data).
  • 🔒 Is there any blocking of distribution by the operator (try connecting through VPN).
  • 📵 Is tethering disabled in Android settings?
📊 What distribution method have you tried before?
Standard modem mode in Android
Applications like NetShare
Termux (hostapd/iptables)
Never tried it

Solutions to common errors

When setting up distribution via Termux, users often encounter common issues. Below is a table of the most common errors and how to resolve them:

Error Cause Solution
Could not configure driver mode The Wi-Fi adapter does not support the mode AP Use the method with iptables or an external USB adapter
Device or resource busy Interface wlan0 busy with the system Disable Wi-Fi in Android settings or restart your device.
There is a network connection, but no internet Wrong rules iptables or operator blocking Check your NAT rules and try changing them. TTL (For example, iptables -t mangle -A POSTROUTING -j TTL --ttl-set 65)
dnsmasq: failed to create listening socket Port 53 busy or no rights Launch dnsmasq with a flag -p 5353 or as superuser

If none of the methods worked, check:

  • 🛠️ Android kernel version: on older kernels (below 3.4) there may not be enough support netfilter.
  • 📋 SELinux policies: in mode enforcing Some transactions are blocked. Check the status via getenforce.
  • 🔄 VPN Conflicts: Disable all VPN applications before setup.
What should I do if Termux asks for root privileges?

If the commands require root and you don't have one, try:

1. Use proot-distro to isolate the environment:

pkg install proot-distro

proot-distro install ubuntu

proot-distro login ubuntu

2. Launch Termux in Linux Deploy (requires root only for installation).

3. On some devices, the command helps termux-setup-storage to access system files.

Optimizing connection speed and stability

By default, Termux sharing can be slower than the standard Android feature. To improve performance:

  • 📈 Change Wi-Fi channel: in the file hostapd.conf try the channels 1, 6 or 11 (they are less busy).
  • 🔄 Disable Wi-Fi power saving:
    settings put global wifi_sleep_policy 2

    (Where 2 - "never turn off" mode).

  • 🛡️ Increase MTU (if pings are high):
    ifconfig wlan0 mtu 1400
  • 📡 Use 5 GHz (if the adapter supports): in hostapd.conf replace hw_mode=g on hw_mode=a and specify a channel from the range 36-165.

To monitor traffic and connected devices, use:

watch -n 1 "iw dev wlan0 station dump" # View connected clients

nethogs wlan0 # Monitoring traffic by process

Security: How to Secure Your Access Point

By default, distribution via Termux uses WPA2-PSK, but there are risks:

  • 🔓 Weak passwords: easily selected by brute force.
  • 🕵️ MAC address leak: Clients can be tracked.
  • 📡 Traffic sniffing: without encryption, data is transmitted openly.

Recommendations for protection:

  1. Use a complex password (minimum 12 characters, with numbers and special characters).
  2. Limit the number of connected devices:
    hostapd ~/wifi-ap/hostapd.conf --max_num_sta=3 &
  3. Enable MAC filtering:
    echo 'macaddr_acl=1
    

    accept_mac_file=/sdcard/allowed_mac.txt' >> ~/wifi-ap/hostapd.conf

    In the file allowed_mac.txt List the allowed addresses (one per line).

  4. Disable SSID broadcasting (will hide the network from outsiders):
    echo 'ignore_broadcast_ssid=1' >> ~/wifi-ap/hostapd.conf
⚠️ AttentionMAC filtering and SSID hiding are not reliable protection—they are easily bypassed. For critical tasks, use VPN on client devices.

Launch automation: scripts for quick distribution

To avoid entering commands manually each time you launch it, create a script:

#!/data/data/com.termux/files/usr/bin/bash

Script for automatic Wi-Fi distribution via hostapd

Root check (optional)

if [ "$(id -u)" -ne 0 ]; then

echo "Running without root: some features may not work"

fi

Network setup

echo "1" > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A POSTROUTING -o rmnet_data -j MASQUERADE

iptables -A FORWARD -i wlan0 -o rmnet_data -j ACCEPT

Starting hostapd and dnsmasq

hostapd ~/wifi-ap/hostapd.conf &

dnsmasq -C ~/wifi-ap/dnsmasq.conf -d &

echo "Access point started! SSID: MyTermuxAP, Password: 12345678"

Save the file as start_ap.sh and make it executable:

chmod +x start_ap.sh

./start_ap.sh

To stop distribution use:

pkill hostapd

pkill dnsmasq

iptables -t nat -D POSTROUTING -o rmnet_data -j MASQUERADE

iptables -D FORWARD -i wlan0 -o rmnet_data -j ACCEPT

echo "0" > /proc/sys/net/ipv4/ip_forward

FAQ: Answers to Frequently Asked Questions

Is it possible to share Wi-Fi via Termux without root?

Yes, but with limitations. Without root, you won't be able to:

  • Modify system files in /proc or /sys (will be required su).
  • Use some Wi-Fi adapter modes (for example, AP on MediaTek).
  • Tune iptables for all interfaces (only those that have access).

However, the method with iptables + dnsmasq It often works without root if the operator doesn't block distribution.

Why is the distribution speed through Termux lower than through a standard hotspot?

This is related to:

  • Lack of hardware acceleration (Wi-Fi drivers are optimized for standard mode).
  • Additional load on the CPU (Termux emulates many functions in software).
  • Suboptimal default settings (eg small beacon_int).

To improve speed:

  • Reduce MTU to 1400.
  • Use channels 5 GHz (if supported).
  • Disable background processes in Android (Settings → Battery → Optimization).
How to share Wi-Fi via Termux on Android 12+?

Starting from Android 12Google has tightened restrictions on access to system interfaces. For sharing to work:

  1. Use Termux from F-Droid (the Google Play version is not updated).
  2. Enable developer mode and turn it on USB debugging.
  3. For iptables a patch may be required Magisk (module iptables for Android 12+).
  4. If hostapd It doesn't start, try create_ap:
    pkg install create_ap
    

    create_ap wlan0 eth0 MyTermuxAP 12345678

Is it possible to share Wi-Fi via Termux on iPhone?

No. Termux is only available for AndroidOn . iOS There are no similar terminal emulators with full access to system functions due to limitations Apple. Alternatives:

  • Use the default Modem mode in iPhone settings.
  • Install Personal Hotspot through Settings → Cellular.
  • For advanced settings you will need jailbreak and tools like TetherMe.
How to share internet from a PC using Termux?

Termux only works on Android, but you can:

  1. Connect your Android device to your PC via USB and distribute the Internet from it (mode USB-tethering).
  2. Use Windows or Linux for distribution:
    • On Windows: netsh wlan set hostednetwork mode=allow ssid=MyNet key=password.
    • On Linux: nmcli dev wifi hotspot ifname wlan0 ssid MyNet password "12345678".