The best way (IMO) is to set the necessary variables in your bash_profile
of your remote machine. I understand you don't want to modify anything on your remote but it's important to note that what you are doing is setting the environment variable PROMPT_COMMAND
When logged in to your remote, issue the command echo $HOSTNAME
and echo $PROMPT_COMMAND
. More than likely, you will get the hostname of your machine and the second will come up blank meaning that it's unset.
Setting the Title
Edit your .bash_profile
found in your home directory on the remote. This is your file and will not affect the rest of the system. Add the following line:
PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}\007"'
The \033]0;
(Esc 0;
) is the escape code to set the title. The ${HOSTNAME}
is the name of your machine.
Save your profile, log out and log back in and your title bar should now reflect your hostname.
Connecting via hostname vs IP
There are two ways to do this:
- Set the hostname in DNS
- modify your local
/etc/hosts
file
I prefer to set this in DNS so that the name will be available to all computers across your network. Going under the assumption that you have a "consumer grade" router (like Linksys or Netgear), you just have to add the hostname to your DHCP static lease (see your router documentation for specifics)
If you're on a corporate network, the Network Admin can add a record to the DNS server pointing to your host.
If those two options aren't available, you can simply edit your local /etc/hosts
file (need root
permissions. Below is my /etc/hosts
used as an example:
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
192.168.10.22 fatjoe
I added the hostname fatjoe
to the end of the hosts
file. When I save and exit, if I type ping fatjoe
it immediately begins to ping the correct IP - the change is immediate.