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

Closed
timoc opened this issue Jul 9, 2016 · 7 comments
Closed

HOSTNAME enviromental variable is localhost not system name #352

timoc opened this issue Jul 9, 2016 · 7 comments

Comments

@timoc
Copy link

@timoc 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

@fornwall
Copy link
Member

@fornwall fornwall commented Jul 19, 2016

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?

@timoc
Copy link
Author

@timoc 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.

HostName 172.1.1.1

And can be added to the documentation

@Exaeta
Copy link

@Exaeta 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!

@Exaeta
Copy link

@Exaeta 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}\$ "
@metimocyn
Copy link

@metimocyn metimocyn commented May 16, 2017

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

@xeffyr
Copy link
Member

@xeffyr xeffyr 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.

@xeffyr xeffyr closed this Jan 28, 2019
@danintel

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
7 participants