Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOSTNAME enviromental variable is localhost not system name #352

timoc opened this issue Jul 9, 2016 · 7 comments

HOSTNAME enviromental variable is localhost not system name #352

timoc opened this issue Jul 9, 2016 · 7 comments


Copy link

timoc commented Jul 9, 2016

This should be the system hostname, or the phones name. This name is the one usually registered in the local dns when connected to a wifi network. having the hostname in the PS1 will make it easier for people to set up ssh connections as all they should need is

ssh -p 8022 termux@<phonename>

and/or can add this to their ssh config (assuming the phone is called myphone)

Host myphone
    HostName myphone
    User termux
    Port 8022 
    ForwardX11 yes
    ForwardX11Trusted yes
    IdentitiesOnly yes
    IdentityFile ~/.ssh/termux.key

which allow people to just

ssh myphone

which works with emacs tramp for editing files on the phone filesystem

Copy link

I don't think Android (as of 5.0 or later) allows setting a system hostname. At least not without root - do you have a root setup where you can test this?

Copy link

timoc commented Jul 26, 2016

I guess hostname The hostname issue I have looked into, but i cannot find the detail. Usually there is a device ID that is used for the hostname, and this is part of the android platform. If you can publish this, then that would be a good substitute.

The above process also works by using IP address.


And can be added to the documentation

Copy link

Exaeta commented Aug 21, 2016

Hello! Android does have hostnames. Hostnames are required of all network devices... normally it is something like "android38793629130". Not being able to use a custom hostname without root is not the same as not having a hostname at all!

Copy link

Exaeta commented Aug 21, 2016

Add the following to ~/.bash_profile:

GREEN="\[$(tput setaf 2)\]"
RESET="\[$(tput sgr0)\]"

export PS1="${GREEN}\$(id -n -u)@\$(getprop net.hostname):\$(pwd)${RESET}\$ "

Copy link

Maybe this can be added to the sshd script, or another termux script that will tell you about your local network environs?

Copy link

ghost commented Jan 28, 2019

Android has 2 hostnames:

  1. DHCP hostname, usually it something like android38793629130.
  2. System hostname (sysctl kernel.hostname). Which is hardcoded at system-level to be localhost - typical Android devices doesn't meant to be used as servers or something similar.

Variable "HOSTNAME" is set by bash, value obtained from libc function gethostname() which obviously will return "localhost".

Obtaining DHCP hostname is something related to Termux:API... I guess it can be added to "termux-wifi-connectioninfo". Anyway DHCP hostname usable only on wifi networks.

@ghost ghost closed this as completed Jan 28, 2019

This comment has been minimized.

@ghost ghost locked and limited conversation to collaborators Oct 9, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

6 participants