Ssh: Could not resolve hostname alias <name>: Name or service not known

I have more than one alias in my .zshrc file, but only one will not resolve.
I can connect using the IP address, but the alias will not work.
I have the same format for all of the computer aliases:
alias computername=‘username@192.168.1.xx’

As a note, I have reinstalled the OS, Manjaro 22, and this occurred previously on the same computer.
The other computers on my network has aliases as well and they all work fine.
Why is this happening?
SSH is running fine, NFS is running fine. All aliases are in the .zshrc file.

Hi @caj411, and welcome!

First thing I’m thinking reading this: make sure there are no unwanted spaces and/or unprintable characters.

I.e.: retype it.

Hope it helps!

1 Like

There is also the possibility to use ~/.ssh/config :wink:

2 Likes

Hello @caj411 and welcome here. :slightly_smiling_face:

I guess you try to use ‘computername’ as argument for a command and not as a command itself.

If you take a look in

man alias

… there is your awnser.

If you run ‘ssh computername’ you will get the resovle error while ssh says “could not resolve ‘computername’”. At this point you just can see the error. It does not see the alias-content.

If you for example use

alias ssh="ssh "

befor running 'ssh computername’ it should work.

… but @andreas85 comment would do this all without aliases in a more elegant way! :stuck_out_tongue_winking_eye:

I have tried different names and i’m only using letters and numbers, no spaces. It seems it must be tied to the IP address for some unfathomable reason.
Two laptops, very similar, an HP Envy and HP Pavillion, one is AMD, the other is Intel, both have Manjaro 22, brand new installs.

isn’t the only thing in the ~/.ssh folder the ssh keys and known hosts files? there is no config in mine.

Create it :wink:

I apologize but reading thru the man pages still doesn’t answer questions that I have.
Likewise searching the internet gives me a lot of conflicting information.

so, as you stated, yes, If I run ssh amd1, I get the ‘could not resolve’ output.
likewise, if I type the alias command alias , it lists all my aliases including the ones I put in the .zshrc file.

amd1=me@192.168.1.xx
cp='cp -i'
df='df -h'
free='free -m'
gitu='git add . && git commit && git push'
ls='ls $LS_OPTIONS'
mediaserver=me@192.168.1.xx
run-help=man
which-command=whence

I’m not sure if I understand your example.
I assume the space after "ssh " in the parenthesis was a typo?
Are you instructing me to use the alias command to enter my alias entries as opposed to adding my aliases directly in the .zshrc file?

From researching, I was under the impression with the newer versions of Manjaro, those with Zsh as the default shell, aliases were to be added directly into the .zshrc file, so I added them manually in the .zshrc file, i did not use the alias command.

I have read so much conflicting information, but most of it is from people using older versions where bash is still the default shell and from what I have read alias are managed differently.

btw where does the alias command ‘alias’ store the alias information?


Moderator edit: In the future, please use proper formatting: [HowTo] Post command output and file content as formatted text

Okay, I’ll put my aliases in there, I’ve not seen that option before.
So, name the file config and add my aliases in there. I’ll give it a go.

Okay, so this is baffling.
I have two computers. On one computer, I put my aliases in the .zshrc file and everything works fine.
On the other computer, I used your way with the config file in .ssh and it still will not resolve the IP. This is the same computer that would not resolve the IP in the .zshrc file either. It won’t resolve either way.

as an aside, when I have the aliases in the .zshrc file I can type the ‘alias’ command and they appear in the alias list. if I put them in the .ssh/config file, the aliases do not appear in the alias list.

  ~  cat .ssh/config                                                  ✔ 
Host 192.168.1.1x
	HostName mediaserver
	User me
	Port 22

Host 192.168.1.1x
	HostName amd1
	User me
	Port 22
    ~  alias                                                            ✔ 
cp='cp -i'
df='df -h'
free='free -m'
gitu='git add . && git commit && git push'
ls='ls $LS_OPTIONS'
run-help=man
which-command=whence
    ~  ssh amd1                                                 ✔ 
ssh: Could not resolve hostname amdds1: Name or service not known
   ~  ssh mediaserver
Last login: Mon Jan 16 15:09:42 2023 from 192.168.1.1x
me@mediaserver:~$

Moderator edit: In the future, please use proper formatting: [HowTo] Post command output and file content as formatted text

What do you mean with “alias”?

Just typing in the alias command.
example: alias l=“ls -al”
or in my case
example: alias mediaserver=“me@192.168.1.1x”

alias used to be so easy, just type 'alias name=‘command and options’, and it worked.
why has it become such a nightmare?

In your example, the command is missing.

Also, the syntax of your ssh config is not correct. Please read the man page.

“Read the man page” only works if the man pages are understood by the reader, that’s why we need help. If you see the error in our syntax, just point it out, it would reduce your workload.

btw, I understand what were trying to say now, I cannot use an alias to point at a string, it must be a command (including options). alias string=“command(& options)”
there were way too many usages of the word ‘string’ in the man pages. i thought i could use an IP in place of a command. I hate man pages, but that’s another thread.

Thanks for your help, I honestly would have never figured it out on my own
.
I figured out my syntax in the ~/.ssh/config.
I was reading an example incorrectly, everything works now.

Please remember, they pay you guys well because you have an attention to detail at a level that most people do not have. I understand you are fighting laziness and ignorance, but you’re fighting the good fight. Laziness and ignorance are terrible afflictions, particular when they are combined.

Thank you, I had never come across doing hosts that way, but it works. Thank you very much.

Some examples for ~/.ssh/config

ControlMaster auto
ControlPath /home/andreas/.ssh/tmp/%h_%p_%r
ControlPersist 1h
VisualHostKey yes
AddKeysToAgent yes
ForwardAgent yes

Host cvs
    Hostname 212.58.203.24
    LocalForward 8000 10.0.40.30:80
    Port 14731

Host notebook
    Hostname	192.168.178.88
    Port	22

Host server
    Hostname	192.168.178.18
    Port 48944
    User andreas

Host trac
    Hostname	10.0.40.30
    Port 25731
    ProxyJump root@cvs

Host gft
    ForwardAgent yes
    Hostname	10.0.40.50
    Port 15731
    ProxyJump root@cvs

Host trac19
    ForwardAgent yes
    Hostname	10.0.40.31
    Port 5731
    User root
    ProxyJump root@cvs
    ProxyCommand ssh %r@cvs nc %h %p %r

Host gast
    Hostname	192.168.178.11
    User andreas

Host jitsim
    ForwardAgent no
    Hostname	192.168.178.17
    LocalForward localhost:13130 localhost:13130
    Port 29942
    User andreas

Host jitsim1
    ForwardAgent no
    Hostname	192.168.178.14
    LocalForward localhost:13130 localhost:13130
    Port 29942
    User andreas

Host anni
    ForwardAgent yes
    Hostname	localhost
    Port 18945
    User anni

Host natalie
    ForwardAgent yes
    Hostname	localhost
    Port 18946
    User andreas

#Host 10.0.*
#    ForwardAgent yes
#    IdentityFile ~/.ssh/andreas.key
#    VisualHostKey yes
#    PasswordAuthentication no
#    ProxyCommand ssh -q root@cvs nc -q0 %h 22
#    Compression yes

#Host 10.0.19.31
#    ForwardAgent yes
#    IdentityFile ~/.ssh/andreas.key
#    VisualHostKey yes
#    PasswordAuthentication no
#    ProxyCommand ssh -q root@cvs nc -q0 %h 22
#    Compression yes

Host 10.0.40.71
    ForwardAgent yes
    IdentityFile ~/.ssh/andreas.key
    VisualHostKey yes
    PasswordAuthentication no
    ProxyCommand ssh -q root@cvs nc 10.0.40.71 22
    Compression yes

Host rsync18
    Hostname	213.58.103.25
    Port	22
    IdentityFile ~/.ssh/andreas.key
    VisualHostKey yes
    PasswordAuthentication no
    Compression yes

Host 192.168.1.40
    ForwardAgent yes
    IdentityFile ~/.ssh/andreas12.key
    VisualHostKey yes
    PasswordAuthentication no
    Compression yes

#Host 192.168.1.*
#    ForwardAgent yes
#    IdentityFile ~/.ssh/andreas12.key
#    VisualHostKey yes
#    PasswordAuthentication no
#    ProxyCommand ssh -q cvs1 nc -q0 %h 22
#    Compression yes

Host 10.0.41.6
    KexAlgorithms +diffie-hellman-group1-sha1
    Ciphers +3des-cbc

No, it was not a typo. man alias says:

DESCRIPTION
       ... An alias definition provides a string value that shall replace  
           a  command  name ...
 ....

EXAMPLES
        ...
        4. Set up nohup so that it can deal with an argument that is itself an
           alias name:

               alias nohup="nohup "

So its not possible to use an alias as argument for a command. But you can combine aliases before other arguments.

So this wont work:

alias mediaserver="me@192.168.1.xx"

ssh mediaserver

But this will work:

alias mediaserver="me@192.168.1.xx"
alias ssh="ssh "

ssh mediaserver

But as I said above. @andreas85 solution is much better.

1 Like

I really do appreciate your effort to educate me, I comprehend what you are saying now, but I still cannot wrap my head around how alias ssh='ssh ’ works by simply aliasing ssh and adding a space. I will read further and figure out how this works.
In a nutshell, what had me most confused was that one alias was working fine and it was incorrect too. It led me to believe I was doing it correctly when I actually was not. Why that one alias was working I have no clue.
btw, I did use the solution provided by @andreas85 and it worked.