New /etc/hosts domain not working when called with SSH from terminal

2

I am connecting via ssh to a remote server, as follows:

ssh user@128.x.x.x

The process works fine as I have the password to get into the server I need to work with.

I wanted to set a name to the IP address, as I would like to make the process smoother and avoid typing and remembering the server IP every single time.

I have edited the /etc/hosts file adding the IP and linking to a new name, as follows (second row):

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
::1             localhost
128.x.x.x       newname

I have flushed the DNS cache with:

sudo killall -HUP mDNSResponder; sleep 2; echo macOS DNS Cache Reset | say

And yet, when calling the ssh server from the terminal via this command:

ssh user@newname

The command does not work and shows the following error message:

ssh: connect to host newname port 22: Operation timed out

Any suggestion is welcomed thanks!

uomoz

Posted 2019-09-06T22:37:34.647

Reputation: 21

1Odd. What happens if you run ping newname? Also, have you tried just closing and reopening a terminal window? – JakeGould – 2019-09-06T23:01:19.027

1Consider using a Host entry in your ~/.ssh/config file instead. – MZB – 2019-09-07T00:18:50.437

Hi everyone and thanks for the answers

@JackGould I have tried closing and reopening the terminal, nothing changed so far. If I run ping newname the following lines appear: PING newname (128.x.x.x): 56 data bytes Request timeout for icmp_seq 0 Request timeout for icmp_seq 1 ...

@MZB I have deleted the newname lines from /etc/hosts, and I have created/edited a ~/.ssh/config file as follows: Host newname HostName 128.x.x.x User user

I have flushed the cache, closed/reopened the terminal, still not working. Maybe a port or id_rsa (not using either of them)? – uomoz – 2019-09-09T18:59:32.907

No answers