7

I currently use SSHelper to transfer my data to the Android 4.0 device. The app displays the IP address that is currently assigned. Since this IP address changes regularly, I'd like to use a hostname for the device, with all my Linux computers, that works with Avahi/Zeroconf and I have computername.local.

How do I get such a hostname for my Android device?

3 Answers 3

3

I am leaving my old answer since the browse and parsing examples may still be useful for some people.

Thanks to the developer's version 5.5 update to SSHelper, you can create a user defined name to be the phones Zeroconf instance name. SSHelper will run the SSH server on a non-rooted Android.

  1. Update SSHelper to version 5.5
  2. Open Android Bluetooth settings and turn on Bluetooth.
  3. Now in lower right corner there is settings to "Rename phone". Customize the name.
  4. Turn off Bluetooth if you want.
  5. Restart SSHelper.

It will register the Bluetooth name as the ZeroConf name. Now, as long as the machine you are connecting from has the avahi/bonjour client software, you can ping, ssh, sftp, or rsync to PhoneName.local. If you do not change your Bluetooth name, it will default register with the Device model name. e.g. "Nexus_4"

# For example:
ping Nexus_4.local
SSH Nexus_4.local
0
3

In the March 2014 update to SSHelper the documentation states new changes to it's Zeroconf broadcasting name. In the documentation Configuration section of the details it describes the checkbox to "Enable Zeroconf broadcasting". When this is enabled any other client on the local network, will be able to browse and then connect for SSHelper on the network.

As of SSHelper ver 5.0, the registered instance name is the model name of your android. For instance, "Nexus 4".

Update: version 5.5 allows a way to set the hostname. I am leaving this 5.0 version answer since the below instructions can still be useful.

You do not need to look at the SSHelper app to know which ip/hostname to connect to from your other machine.

From linux (you may need to install avahi-utils):

avahi-browse --terminate --resolve --parsable _ssh._tcp

More specifically, entering this command will SSH connect to the android e.g. "Nexus 4" server without needing to know it's name:

ssh `avahi-browse --terminate --resolve --parsable _ssh._tcp \
| grep "Nexus.*;local;" \
| sed -E 's/.*Nexus.*;local;(.*.local);.*/\1/g'`

For OS X (10.9 Mavericks), there is nothing to install but you must run dns-sdand then Ctrl + C to kill the process after you see the android bonjour hostname.

# If your model name is not "Nexus 4", Be sure to use your phones model name.
dns-sd -L "Nexus 4" _ssh._tcp local

# this will output something like this:
# Nexus\0324._ssh._tcp.local. can be reached at 192-168-1-6.local.:22

# so now ping by the name found from above:
ping 192-168-1-6.local
2
  • Yes, it's really a pity that--accordig to your description--it's not possible to set a human-friednly hostname, just to do ssh MY-ANDROID.local!.. Commented Jan 3, 2014 at 22:56
  • Yes it is now possible to set a custom name. Note the updates to this answer.
    – glenschler
    Commented Apr 6, 2015 at 12:10
2

I have yet to find a way to create a hostname for an Android device. What I have done is that I set an IP reservation for my phone, so that every time I go to use SSH (I use QuickSSHd, but it should work for SSHelper) you can at least point to the same IP address.

There is no way to set a host name for the phone, that I have found.

2
  • 1
    Okay I lied, there is an easy way to change the hostname, but it's not what you'd expect for trying to SSH. You can use getprop hostname.net and setprop hostname.net NEW_NAME to change the hostname of your phone and how it appears to you router, but this does not let you SSH by hostname.
    – Mr. Monkey
    Commented Mar 26, 2013 at 17:15
  • Actually it's net.hostname, but without your comment I wouldn't have found it.
    – elmicha
    Commented Nov 1, 2013 at 23:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .