Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Another method of changing your hostname UNIX
We all know you can change the host name in OS X through /etc/hostconfig, but that can have problems, such as Apache not working right.

In the Terminal type:
% sudo open -a /Applications/TextEdit.app /usr/share/init/tcsh/rc
In TextEdit look for a line:
set host = `hostname`
change `hostname` to anything you like:
set host = "Big Papa"
There you go, new host name without the hassle of hostconfig.

[Editor: I have not tested this myself, but the rc file does contain the hostname reference. I don't know the implications of changing it here versus editing hostconfig or using NetInfo Manager...anyone have any thoughts?]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[6,816 views]  

Another method of changing your hostname | 10 comments | Create New Account
Click here to return to the 'Another method of changing your hostname' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
eh ?
Authored by: robh on Sep 10, '01 02:14:58PM

All this does is set a variable.
What uses that variable ?. I doubt any application looks at the contents of that variable.

Use /etc/hostconfig to do this properly.



[ Reply to This | # ]
eh ?......
Authored by: marcelv on Sep 10, '01 05:53:02PM

and a shorter way to type the command;

open -a /Applications/TextEdit.app

is just;

open -a TextEdit

There's no need to type the full path of the app

Marcelv



[ Reply to This | # ]
This method works better than hostonfig
Authored by: JoeHope on Sep 10, '01 06:50:01PM

I changed my hostname via hostconfig, and months later had trouble getting lam-mpi (a parallel processing/cluster package) running, as it kept translating "localhost" to the name I'd chosen, and was then unable to find this strange new machine on the LAN.

I was sad to have to turn my prompt, etc back to localhost, but lam-mpi worked when I put hostconfig back to -AUTOMATIC-.

Setting my hostname this way works properly. It now uses my new name in the prompt, and other local apps, but it doesn't confuse lam-mpi. Thanks.

Joe.



[ Reply to This | # ]
only changes prompt and shell's environment variable
Authored by: wluh on Sep 10, '01 07:47:09PM

Unfortunately, changing the host name in this way does not allow you to ssh or telnet into your machine using that name. it only changes what the prompt says is the host name, i.e. if you set host = "mycomputer" then turn on sharing, and try to ping or telnet from another computer, it won't find it. And only "localhost" is honored if you try to browse on console any web pages that you have on your computer. (In fact, I'm not sure if the proposed solutions I've seen on this site's archives would have their hand-tailored hostnames honored by the network without registering with their parent domain).

The reason is that the "rc" file calls "tcsh.defaults" after setting the host environment variable and sets the prompt based on the string stored in the host env variable. These variables are set for the shell, not for the system.



[ Reply to This | # ]
The correct way to change your hostname
Authored by: pete_yandell on Sep 11, '01 02:55:51AM

All of the posts I've seen actually slightly miss the correct way to change your hostname on OS X.

The above technique doesn't actually change your hostname at all; you will still get "localhost" if you run the hostname command from a terminal. All it does is convince your shell that the hostname is different and therefore changes the prompt you get in terminal windows. If this is all you want to do then it may be a good solution.

To really change your hostname, your need to do two things:
1) Edit the /etc/hostconfig file and change the HOSTNAME= line
AND
2) Open up NetInfo Manager, choose the "machines" directory, create a new subdirectory with the same name as your new hostname and add a new property to this directory called "ip_address" with a value of "127.0.0.1"

The second step is very important and I haven't seen it discussed before. Without it, your machine may try to look up its IP address from its name and fail which can cause assorted problems like the one the previous poster described. (For me, printing from the command line using lpr was very broken until I performed this second step.)

As always, be careful playing with NetInfo Manager. You can break things very badly.



[ Reply to This | # ]
The correct way to change your hostname
Authored by: iloatheny on Jun 08, '02 06:50:25PM

Posts like this needs to be highlighted so it stands out from all the conflicting / outdated info regarding common troubleshooting issues like this one.



[ Reply to This | # ]
or better
Authored by: spyro_le_dragon on Sep 11, '01 07:56:54AM

or better: open -e <file path>

as open -e opens in textedit



[ Reply to This | # ]
oooops
Authored by: spyro_le_dragon on Sep 11, '01 08:01:28AM

ooops I was supposed to reply to "eh...."
(but macosxhints doesn't show messages history in the 'post a comment' page, and that is bad)



[ Reply to This | # ]
Prompt vs System
Authored by: Lazaru5 on Oct 05, '01 03:30:28PM

All this article does is have you change the rc (Resource Configuration) file for tcsh. The default tcsh shell (terminal) prompt includes the system's hostname in it. All you've done is changed the prompt. Likewise, if you use a different shell (zsh - the Z Shell - is also included with OSX {or it was with the PB which is all I've seen}), it will have no effect on the prompt because this change only affects tcsh.

As has been pointed out, /etc/hostconfig is the proper place to change your system's hostname.

If some things, like Apache, break when you change your hostname, it's because of DNS problems. Apache likes to know the IP address of the machine it's running on. If you maintain /etc/hosts along with /etc/hostconfig, Apache should be fine.

BTW, in shell scripts, the backtick character '`' has a special meaning. Placing a command between backticks runs that command. In this case, the result of the command "hostname" is inserted into the variable "host". There is an actual unix command called 'hostname' which returns the system's hostname (it can also set it, but only /etc/hostconfig makes it permanent after reboot).

By now most of you know that 'ls' lists the contents of a directory (folder). If you were to type "set foo = `ls`" and then "echo $foo", you'd get the contents of that variable - in this case, the directory listing - displayed on the screen.



[ Reply to This | # ]
changing hostname
Authored by: gteague on Mar 04, '02 12:46:39AM

i've tried nearly all of these tips and some others (editing the /etc/rc.boot file) and none of them seem to cover all the bases.

for example: i have a lan behind a router with an external ip of 216.x.x.x and i have a website on a server inside the lan. so my server has an internal 10.x.x.x address and the website on the server has the 216.x.x.x external address for the fully qualified internet domain name.

changing just the /etc/hostconfig file on this server seems to work. upon restart the generic localhost is replaced by the machine name. a ping to the website or the hostname pings the external (216.x) address. but, a ping to localhost also pings this external address rather than 127.0.0.1. i fear this might cause trouble for some internal operations.

and on a host on the lan it is worse since it too takes on the external address rather than the internal (10.x) one. so i would have 2 hosts on the same lan whose discrete names break back to the same ip address.

what i would think i need is for localhost to still map to 127.0.0.1, the website to break back to the external address (although this might not be needed since i have the router (which technically is the owner of the external address) set to forward requests to port 80 (http) for that address to the lan server. so i would say that the server itself doesn't even need this external address.

i need the local hostname to break back to the internal (10.x) ip addresses. and this is probably realized by a hosts file. but i've been reluctant so far to dig into that mess. redhat and mac os9 just require a hosts file, but osx seems to need the official caching server (bind) running and feeding off lookupd.

it's way too much for me. can't anyone just call or email apple and try to get a upper-tier tech to tell us all the 'apple blessed' way?

/guy



[ Reply to This | # ]