59

My Android device is the Nexus One. But this should apply to all current Android devices.

How do I change the name of my Android device?

When I connect to my wireless router's client tables, my android devices is listed for example as: android_1234567890abedfc. I'd like to give it a more readable name.

22

To change the hostname (device name) you have to use the terminal (as root):

For Eclair (2.1): echo MYNAME > /proc/sys/kernel/hostname

For Froyo (2.2): (works also on most 2.3) setprop net.hostname MYNAME

Then restart your wi-fi. To see the change, type uname -a

some devices needs reboot for work!

  • Does this work on jelly bean? – jrg Sep 1 '12 at 3:43
  • 3
    This works, but does not persist on reboot. – palswim Aug 8 '13 at 18:16
  • 1
    uname -a doesn't show the hostname for me, though it does say localhost. what do you expect it to show? – endolith Feb 28 '16 at 0:11
15

Summary:

  • getprop net.hostname (Android System Hostname, likely android_24412414 type name)
  • echo $HOSTNAME (shell/terminal/env hostname, likely ro.product.device from build.prop)
  • cat /proc/sys/kernel/hostname (Linux System Hostname, likely localhost)
  • head /etc/hosts (Linux System Hostname, likely localhost)
  • hostname (Command not always installed, if installed via busy box, will read /proc/sys/kernel/hostname)

Depends on which version of Android you have.

Android 4.0 and Above

Newer versions will use the right build.prop entry. Well, that is to say, Android reads the build.prop as it's normal boot process. Once the Connectivity Service runs, it checks to see if net.hostname is set in the Settings, then if empty, then it uses the "android_" + (permanent) android ID. So that's all you need to do.

Add net.hostname=HOSTNAMEHERE to /system/build.prop (Root may be needed). Leave a blank line at the end of the file.

Kitkat's ConnectivityService.java, notice the IF isEmpty statement:

    // setup our unique device name
    if (TextUtils.isEmpty(SystemProperties.get("net.hostname"))) {
        String id = Settings.Secure.getString(context.getContentResolver(),
                Settings.Secure.ANDROID_ID);
        if (id != null && id.length() > 0) {
            String name = new String("android-").concat(id);
            SystemProperties.set("net.hostname", name);

Android 2.3 and Below

Older versions, Gingerbread, Froyo, etc, just clobber it. It doesn't bother to check. It will set net.hostname to android_24412414... no matter what. So you will need to change it after that Connectivity Service has finished loading. Luckily, it only runs the startup once, not on every new connection. So we just need to run setprop net.hostname HOSTNAMEHERE after that for it to stick. Unfortunately, it runs fairly late in the boot process, so you need something that will make the changes on boot_complete. Most likely an App that runs by itself.

Froyo's ConnectivityService.java:

    // setup our unique device name
    String id = Settings.Secure.getString(context.getContentResolver(),
            Settings.Secure.ANDROID_ID);
    if (id != null && id.length() > 0) {
        String name = new String("android_").concat(id);
        SystemProperties.set("net.hostname", name);

But then there is another issue.

The net.hostname setting, is not copied to the entire system! If you use a console/terminal application, you might not get the same hostname. My phone, a Samsung Sidekick 4G (semi-Galaxy S based) has an init.rc which runs hostname localhost, so all underneath commands will not see either your build.prop hostname or the android_id hostname! So you need to set that too.

hostname HOSTNAMEHERE or echo HOSTNAMEHERE > /proc/sys/kernel/hostname

Note: Depending on how you are doing it, you'll need to run the above command as root in order for it to work. Init.rc is typically on the read only system partition, so root access is needed to edit it.

The dhcpcd command, which is run to get a dhcp address, will not update to a hostname provided by the server (That can be fixed by adding the right dhcpcd-run-hooks and dhcpcd.conf), and it will not provide a hostname to the dhcp server if $(hostname) (The hostname command) is blank or localhost, and it does not internally use net.hostname. libnetutils is used for calling dhcpcd with -h "net.hostname", but if for some reason it decides not to call with -h, DHCPCD WILL STILL SEND THE SYSTEM HOSTNAME via gethostname(), as long as it's not "(none)", "localhost", or empty. On Stock Froyo anyway. Samsung screwed the pooch on some devices like mine. No hostname pass through, forced network time, etc.

My Solution for Gingerbread and below Samsung, Edit the DHCP Client Daemon config:

The last thing you can do is edit /etc/dhcpcd/dhcpcd.conf. If you add hostname YOURHOSTNAME to the file, it will use that, unless a hostname is given on the commandline. This won't fix the android_234etc issue, but will if the hostname is localhost (My problem, since Samsung screwed libnetutils and localhost in init.rc). You will need Root, but this works across reboots. This won't work if dhcpcd is called with -h Hostname option.

10

I found a way to do this on my rooted Nexus 7 with 4.2.2. The setting is saved persistently and works throughout reboots.
Source: http://nileshgr.com/2012/10/13/how-to-change-wifi-host-name-of-your-android-device

  1. Note that the device must be rooted to use adb
  2. Run adb pull /system/build.prop
  3. Edit the build.prop file and append net.hostname=NewHostname
  4. Run adb push build.prop /sdcard/build.prop (or /mnt/sdcard, if it fails)
  5. Run adb shell and execute the following commands:
    $ su
    # mount -o rw,remount /system
    # cp /sdcard/build.prop /system/build.prop (or /mnt/sdcard if you used that previously)
    # mount -o ro,remount /system
    # exit
  6. Reboot the device
  • This was fixed in newer versions of Android. It checks net.hostname from build.prop. Older Android versions do not (Mainly Froyo, maybe Gingerbread). – cde Jan 4 '14 at 12:22
  • ICS isnt 4.2.2, that would be JB – HasH_BrowN Sep 27 '14 at 20:17
  • an easier way to do this is to use the setprop command via a root shell on the device: for example setprop net.hostname NewHostName – Mark Oct 16 '14 at 0:00
  • 1
    @mark that would be clobbered on reboot. This answer is a permanent version. – cde Aug 7 '16 at 6:26
9

This works on CyanogenMod and probably other modified ROMs but not stock AOSP ROMs:

Go to Settings > Developer Options and scroll down to Device Hostname. Root is not needed.

(Click image to enlarge)

IMG:

  • 2
    Yeah, you can't do this on an Acer A100 tablet running Android 4.0.3. In fact, it doesn't even have "Device hostname" in the Developer Options. – bgmCoder Nov 4 '15 at 4:14
7

I have not ran stock in a long time but in Application Settings > Development you will see the option 'Device hostname'.

  • on what versions of Android? When I look at development options on my Droid 3 (Android 2.3.4), I don't have that option. – Michael Kohne Mar 19 '12 at 15:24
  • 3
    This works on CyanogenMOD and probably other modified ROMs but not stock AOSP ROMs. – Caleb Oct 18 '13 at 15:50
  • Completely dependent on the manufacturer and builder, as well as android version. – cde Jan 4 '14 at 12:21
5

Go to Google Play Store. Search for "hostname", and download hostname changer app.

Must be rooted.

  • Will renaming the device mess up anything internally? – bgmCoder Nov 4 '15 at 4:13
0

Hostname is used to easily identify and remember hosts connected to a network. It's set on boot, e.g. from /etc/hostname on Linux based systems. Hostname is also a part of DHCPREQUEST (standardized as code 12 by IETF) which a DHCP client (Android device in our case) makes to DHCP server (WiFi router) to get an IP address assigned. DHCP server stores the hostnames to offer services like DNS.

Android - instead of using Linux kernel's hostname service - used property net.hostname to set a unique host name for every device which was based on Android ID. This hostname property was also used for DHCP handshake. However since Android 5 - when the native dhcpcd was abandoned in favor of Java DHCP client - hostname is null in DHCPREQUEST. net.hostname is neither set, nor evaluated by DHCP client. So the WiFi routers show no host names for newer Android devices, neither we can set / unset / change it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.