1

I have setup a Centos Linux Server. I can connect to my server with command:

ssh My_Name @ Ip_Address 

How can I set a name for my server so that I can connect with the command:

ssh My_Name @ My_Server_Name.com 

The .com or '.net' does not matter, I just want to have a name for my server.

1

2 Answers 2

6

If you just want to do this for convenience, the simplest method is to add a stanza to your ssh configuration file ~/.ssh/config :

Host my_server_name HostName some_ip_address User my_name ... any other options 

Then you can ssh my_server_name to connect.


Other options include:

  • using mDNS and connecting to the .local name your machine advertises (mDNS is called bonjour in the Apple world; a common linux implementation is avahi).

  • editing the /etc/hosts file on each client machine to provide a mapping from the IP address to the chosen server name.

  • installing and configuring a DNS server on a machine in your local network, and setting it as the preferred DNS server for all other local machines.

2
  • My intention is rather something else. when I connect to my server from outside of home I need to use IP_Address_1 and when I connect inside home [within my home network] I need to use IP_Address_2. So I want to set a name, so that I can always use a unique name wether in home or out of home. Commented Dec 26, 2016 at 23:13
  • @Admia, if you want a FQDN you can use from inside or outside your house, I think you would need to (1) lease a domain (2) set up outside name resolution per your registrar's instructions and (3) set up a DNS server in your home that would provide local addresses for the same names. Alternately, you could write a wrapper script which would check your current IP address, and ssh to either the local or the public IP for your centos system, depending on whether you were in or out of the house. Commented Dec 26, 2016 at 23:17
2

And to add a further possibility if you want a more general solution than just for your ssh connection, you could add the alias to your /etc/hosts file

IP address YourAlias1 ... 

This would allow you to use the alias with any other programs, but wouldn't include the ssh user name as the first answer gave.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.