# Problem with hostname



## ReckLess (Jul 2, 2012)

Hello!
My name is Steve and I've got a stupid problem with my FreeBSD that I can't resolve by myself (it makes me become mad). My problem is that I can't view my current hostname anymore but I didn't touch anything, but what do I view? Just a _%_. I'm going to show you now my configured files:

/etc/rc.conf


```
defaultrouter="192.168.2.1"
hostname="tff.game-server.cc"
ifconfig_em0="inet 192.168.2.2  netmask 255.255.255.0"
moused_enable="YES"
mysql_enable="YES"
sshd_enable="YES"
```

/etc/hosts


```
::1			localhost localhost.game-server.cc
127.0.0.1		localhost localhost.game-server.cc
192.168.2.2		tff.game-server.cc tff
```

/root/.cshrc


```
alias h		history 25
alias j		jobs -l
alias la	ls -a
alias lf	ls -FA
alias ll	ls -lA

# A righteous umask
umask 22

set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin)

setenv	EDITOR	vi
setenv	PAGER	more
setenv	BLOCKSIZE	K

if ($?prompt) then
	# An interactive shell -- set some stuff up
	set prompt = "`/bin/hostname -s`# "
	set filec
	set history = 100
	set savehist = 100
	set mail = (/var/mail/$USER)
	if ( $?tcsh ) then
		bindkey "^W" backward-delete-word
		bindkey -k up history-search-backward
		bindkey -k down history-search-forward
	endif
endif
```

When I type _hostname_ on the shell, I get this reply:


```
tff.game-server.cc
```

Just a snapshot to make you understand my problem:


----------



## wblock@ (Jul 2, 2012)

See the man page for csh(1).  The %M and %m variables can be used instead of running hostname(1) for every prompt.

```
set prompt = "%M # "
```

Why that's not displaying is another question.  If that is set only in /root/.cshrc, other users will not see it.  Everyone has their own .cshrc.


----------



## ReckLess (Jul 2, 2012)

wblock@ said:
			
		

> See the man page for csh(1).  The %M and %m variables can be used instead of running hostname(1) for every prompt.
> 
> ```
> set prompt = "%M # "
> ...



It didn't work.


----------



## ReckLess (Jul 2, 2012)

I think that the problem isn't in the .cshrc file (just because the other users is displayed otherwise hostname).


----------



## wblock@ (Jul 2, 2012)

ReckLess said:
			
		

> It didn't work.



Whoa, too many details, slow down.

Seriously, give us something to work with.  What happened, exactly?


----------



## ReckLess (Jul 2, 2012)

wblock@ said:
			
		

> Whoa, too many details, slow down.
> 
> Seriously, give us something to work with.  What happened, exactly?



I just typed _chsh root_ for a quick edit of main directory and then a _reboot now_.


----------



## wblock@ (Jul 3, 2012)

Why are you running chsh(1)?  Why reboot?  To see a prompt change, just log out and log back in.

Still not able to tell what is happening.  What did it show?  What is the output of
`% hostname`


----------



## ReckLess (Jul 3, 2012)

I typed a _reboot now_ because I couldn't see my hostname anymore after _logout_, however if you go up (in first post) you can read the part of hostname command.


----------



## ReckLess (Jul 3, 2012)

I couldn't fix it (I was getting too boring), so I decided to mount a backup of my OS. Thanks for your helps, now you may as well close.


----------



## ReckLess (Jul 3, 2012)

Sorry if I'm triple-posting but I can give you an easy fix if you got my same problem. Just edit /etc/csh.cshrc, adding:


```
alias h		history 25
alias j		jobs -l
alias la	ls -a
alias lf	ls -FA
alias ll	ls -lA

# A righteous umask
umask 22

set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin)

setenv	EDITOR	vi
setenv	PAGER	more
setenv	BLOCKSIZE	K

if ($?prompt) then
	# An interactive shell -- set some stuff up
	set prompt = "`/bin/hostname -s`# " #You can add there what you want if you don't like your registered hostname
	set filec
	set history = 100
	set savehist = 100
	set mail = (/var/mail/$USER)
	if ( $?tcsh ) then
		bindkey "^W" backward-delete-word
		bindkey -k up history-search-backward
		bindkey -k down history-search-forward
	endif
endif
```


----------



## wblock@ (Jul 3, 2012)

In post #2, I said "Everyone has their own .cshrc."  What you're doing there is editing the system-wide default.  Every user will get that file, instead of being able to use their own.  One problem is that you have it displaying a # prompt, regardless of user.  Traditionally, a # prompt lets you see you are logged in as root.

Again, running hostname(1) every time a prompt is displayed can be avoided by using the existing variables.


----------



## TheDreamer (Jul 3, 2012)

A better alternative to:


```
set prompt = "`/bin/hostname -s`# " #You can add there what you want if you don't like your registered hostname
```

might be:


```
set prompt = "%m%# "
```

%m is the hostname up to the first '.', and %# is the appropriate prompt character for normal users or the superuser.

The Dreamer.


----------



## fullauto (Jul 5, 2012)

wblock@ said:
			
		

> Whoa, too many details, slow down.
> 
> Seriously, give us something to work with.  What happened, exactly?



snickering a bit.


----------

