You can test Android, Apple APP, and H5 apps locally without having to change the hosts of the ROOT user on your mobile phone. Android h5

Source: Internet
Author: User

You can test Android, Apple APP, and H5 apps locally without having to change the hosts of the ROOT user on your mobile phone. Android h5

Mobile APP development and H5 apps often need to be tested separately in the local and online environments. Generally, the operation is to modify hosts, and I have been doing this all the time, however, modification to the hosts on the mobile phone requires the ROOT permission, which is too troublesome and may lead to the risk of changing bricks. In addition, some mobile phones cannot be ROOT at all.

After a busy afternoon, I finally got the expected result. Here are two important points:


A local DNS service is a bit like DNS hijacking. This is a permanent solution.
First, you need a Linux virtual machine or a server
My configuration below uses the Centos7.0 system. The version may be different if it is not available.

1. Install DNSMasq


# Install yum install dnsmasq-y service dnsmasq start # edit the configuration parameter vi/etc/dnsmasq. conf # Find resolv-file and remove the annotator. Add the file path # indicates that dnsmasq searches for the upstream dns server resolv-file =/etc/resolv from the specified file. conf # Find no-hosts, and make sure there is # Well number (indicating that it is commented out) in front of it. Otherwise, the hosts configuration does not work # The IPlisten-address of the listener is, =/etc/hostscache-size = 32768 # configure the NIC parameters. The NIC names of centos7 and 6 are different, use ifconfig to view and replace # centos 7 before vi/etc/sysconfig/network-scripts/ifcfg-eth0 # centos7 is not necessarily the same vi/etc/sysconfig/network-scripts/ifcfg-enp3s0 # Up to write three, note that if the original configuration exists, you need to adjust DNS1 = = = # DNS3 = # Save and resolv. cat/etc/resolv. conf # Check if DNS has been added # register the chkconfig dnsmasq on service # restart/etc/init. d/dnsmasq restart # systemctl restart dnsmasq # Check whether the installation is successful netstat-tunlp | grep 53yum install bind-utils # test whether to Enable DNS configuration dig # edit the hosts file, configure the ing between the IP address of the local DNS hijacking domain name vi/etc/hosts192.168.0.105



In this way, DNS hijacking on the server is basically configured. The next step is to set the corresponding dns ip address on the mobile phone,

Choose "Network Settings"> "wifi connection"> "modify Network"> "advanced"> "static IP Mode"> "Modify the IP address of the first NS", and the second is available for the normal public DNS.


For example:


Note: After modifying the hosts, You need to restart dnsmasq and the network.

2. Use a local network proxy

This method has some limitations. It can be used for H5 web applications and may be ineffective for some native apps. However, it can be used with some software for front-end packet capture and viewing, it is useful for viewing data such as test interfaces.

I used two software,
1. Fiddler
This software is very convenient to use. There are many introductions on the Internet. I will not mention it here, but it is said that it only supports windows platforms.
2. Whistle
This is an open-source project, cross-platform. I currently use this project, and the configuration is very simple.
The following describes how to install and use

It depends on Nodejs, so first install nodejs
As shown in the following figure, yum is used for installation.


curl --silent --location | bash -yum install -y nodejs


The download speed may be a little busy. It takes more than half a day to download 10 kb/s. Please wait.

npm install cnpm -g --registry= install -g whistlew2 start


This completes...

Viewing proxy request data means capturing data

Http: // 8900
Http: // 8899

: 8899 is the proxy port, but you can also view the packet capture data

You can view both ports and see the effect first (you can drag and drop the picture to view the large image)


For more information, see the official documentation.

The operation on the mobile phone is the same as the above DNS settings.

Open Network Settings-> wifi connection-> modify Network-> advanced-> proxy (manual configuration)-> enter the IP address of the server in the LAN, such as, port 8899


For example:



The last step is to modify the hosts on the server. Refer to the DNS configuration above for the same operation.

This is almost the case.

The last thing to note is to clear the cache on the mobile phone. You must close the browser and application, clear the memory, and enable it again. Otherwise, the DNS and network settings on the mobile phone may not be switched over.

The above configurations are all tested on Android devices, and there is no app for iOS to test, but it should be the same as the above.
Although the proxy method is not necessarily useful for some apps, we recommend that you use DNS and proxy together... That's it.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.