Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
tijuanacartel
Old
#1  
Senior Member - OP
Thanks Meter 11
Posts: 118
Join Date: Nov 2010
Default [Q] Cyanogen: Set net.hostname at boot

Android 2.2 sets the default hostname to android_dfhjkahdjksf or something equally useless.
To override this in Cyanogen 6.1 you need to set the net.hostname property with setprop Eg:

# setprop net.hostname mickey

My problem is when I try to set this up at boot, something always overwrites my change with the default. I have tried putting it in my init.rc, /etc/init.d and /data/local/userinit.sh and it is always reset to default by the time the phone has booted.

Does anyone have any more ideas about how to permanently set the hostname? It would be a good option to have in cyanogenmod.
 
konax
Old
#2  
Junior Member
Thanks Meter 3
Posts: 9
Join Date: Aug 2008
UP. I'm very interesting too.
 
Gene Poole
Old
#3  
Recognized Contributor
Thanks Meter 513
Posts: 1,624
Join Date: Jul 2010
Location: Brighton IL
The root filesystem is stored in the boot.img and is expanded to a ramdisk every time you reboot. For changes to be permenant, you need to extract the boot.img file, extract the kernel and ramdisk sections, modify the ramdisk image with your changes, then recombine the kernel and ramdisk to a new boot.img and reflash it. You'll probably need to do this on a linux machine that understands unix permissions and ramdisk/cpio filesystems as well as having a good knowledge of linux and unix commands. See this thread:

http://forum.xda-developers.com/showthread.php?t=551711

note: your kernel may use a different "--base 0x19200000" option when building the kernel boot image.
 
prscott1
Old
(Last edited by prscott1; 15th December 2010 at 05:31 PM.)
#4  
prscott1's Avatar
Senior Member
Thanks Meter 19
Posts: 791
Join Date: Nov 2007
Location: Houston
Is there not a way to add a correlating line to the build.prop file?

EDIT: This doesn't work - whatever is setting the net.hostname writes out after build.prop is read.

I'm looking...

I did a search in the /system/etc directory for any file doing setprop (I'm using a miui rom) and found the following script. I did the setprop for net.hostname in there and it too is being overwritten.

search command:

grep -H -r setprop /system/etc


/system/etc/init.goldfish.sh

I'm running out of ideas other than using autostart to set it after reboot.

EDIT2: doh. I think I already knew this but it dawned on me that the default net.hostname comes from concatenating the "android_id" (found in the secure database table) to the end of "android_".

So seems more likely to reset it after reboot using a script (gscript to launch it manually or use autostart to launch it automatically at the end of reboot cycle).
*** Many thanks to all the brilliant devs who contribute to XDA!! You are the heartbeat of this community. ***
 
BlaY0
Old
#5  
BlaY0's Avatar
Recognized Developer
Thanks Meter 554
Posts: 1,551
Join Date: Sep 2007
Location: Medvode
Property net.hostname originate from services.jar (ConnectivityServices.java):
Code:
// 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);
}
Maybe CM guys would change this to add another "if /proc/sys/kernel/hostname is different than localhost, use it for net.hostname too" condition.

I'm not using CM so it is up to you guys to make a feature request.

Another approach would be to set service in init.rc that would start your net.hostname changing script on some property being set just after net.hostname is set. You could use also:
Code:
on property:net.hostname=android_blahblah
...but that wouldn't be so handy since you will have to change that line in init.rc every time you make a factory reset.
The Following 2 Users Say Thank You to BlaY0 For This Useful Post: [ Click to Expand ]
 
Sol Ido
Old
#6  
Member
Thanks Meter 78
Posts: 98
Join Date: Nov 2010
Location: BlueSky
Really interesting, thx !
 
radadev
Old
#7  
radadev's Avatar
Member
Thanks Meter 16
Posts: 59
Join Date: Dec 2010
Location: Dallas

 
DONATE TO ME
Quote:
Originally Posted by BlaY0 View Post
Property net.hostname originate from services.jar (ConnectivityServices.java):
Code:
// 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);
}
Maybe CM guys would change this to add another "if /proc/sys/kernel/hostname is different than localhost, use it for net.hostname too" condition.

I'm not using CM so it is up to you guys to make a feature request.

Another approach would be to set service in init.rc that would start your net.hostname changing script on some property being set just after net.hostname is set. You could use also:
Code:
on property:net.hostname=android_blahblah
...but that wouldn't be so handy since you will have to change that line in init.rc every time you make a factory reset.
Thanks a lot. I've been looking for this for the past hour or so. Traditional linux methods to set the hostname don't work... I think I'll add an option in cyanogenmod settings for this and submit it to Gerrit. Look for it to show up within the next day or two.

[TWRP-2.1]

[ wordpress | twitter | dropbox ]
Get a dropbox. You'll be glad you did.
 
BlaY0
Old
#8  
BlaY0's Avatar
Recognized Developer
Thanks Meter 554
Posts: 1,551
Join Date: Sep 2007
Location: Medvode
That's great m8! Cheers

Sent from my HTC Legend
 
numbat
Old
#9  
Junior Member
Thanks Meter 0
Posts: 1
Join Date: Mar 2009
Default underscores in hostnames are bad

The main thing I want to do is get rid of that underscore. Several of the places I hook up with with WiFi attempt to enter the hostname supplied during the DHCP conversation into a DNS. But underscore is illegal for this purpose.

Numbat.
 
lufc
Old
#10  
lufc's Avatar
Senior Moderator / Resident Priest
Thanks Meter 1472
Posts: 9,442
Join Date: Oct 2007
Location: Blackpool UK

 
DONATE TO ME
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums

Moving to Q&A
Pay attention and participate,Encourage,
not discourage, Listen to advice and accept instruction,
and in the end you will be wise.......... Prov. 19:20

 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...