Android: Change gateway address of hot-spot

user5081013 picture user5081013 · Jul 4, 2015 · Viewed 8.5k times · Source

Is there a way to change the gateway address of the AP hot-spot feature of Android from 192.168.43.1 to something else such as 192.168.43.3 without recompiling anything? I have a rooted Android device.

Answer

Sahil Bahl picture Sahil Bahl · Jul 6, 2015

You are trying to change the settings that have been hardcoded for android hotspot This is from http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.0.1_r1/android/net/wifi/WifiStateMachine.java

private boolean startTethering(ArrayList<String> available) {                                 

    boolean wifiAvailable = false;                                                            

    checkAndSetConnectivityInstance();                                                         

    String[] wifiRegexs = mCm.getTetherableWifiRegexs();                                      

    for (String intf : available) {                                                           
        for (String regex : wifiRegexs) {                                                     
            if (intf.matches(regex)) {                                                        

                InterfaceConfiguration ifcg = null;                                           
                try {                                                                          
                    ifcg = mNwService.getInterfaceConfig(intf);                               
                    if (ifcg != null) {                                                       
                        /* IP/netmask: 192.168.43.1/255.255.255.0 */                           
                        ifcg.setLinkAddress(new LinkAddress(                                  
                                NetworkUtils.numericToInetAddress("192.168.43.1"), 24));       
                        ifcg.setInterfaceUp();                                                

                        mNwService.setInterfaceConfig(intf, ifcg);                            
                    }                                                                          
                } catch (Exception e) {                                                       
                    loge("Error configuring interface " + intf + ", :" + e);                  
                    return false;                                                              
                }                                                                              

                if(mCm.tether(intf) != ConnectivityManager.TETHER_ERROR_NO_ERROR) {           
                    loge("Error tethering on " + intf);                                       
                    return false;                                                              
                }                                                                              
                mTetherInterfaceName = intf;                                                  
                return true;                                                                   
            }                                                                                  
        }                                                                                      
    }                                                                                          
    // We found no interfaces to tether                                                        
    return false;                                                                              
} 

Try check out this answer https://android.stackexchange.com/questions/46499/how-configure-the-dhcp-settings-of-wifi-tetheringhotspot-in-android