I have function like this in python:
def test_ssh(host, username, password):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(host, username=username, password=password)
Problem is:
test_ssh('127.0.0.1', 'root', 'hello') works
But test_ssh('localhost', 'root', 'hello') doesn’t work
Error I get is:
ssh: Could not resolve hostname localhost: Name or service not known
What’s causing this? Thanks
Since my comments werent making much sense (putting them all together) (assuming your OS is Linux) –
Reason for your error –
Is – DNS resolution of HOSTNAME is not providing proper IP (comment#1)
Test with this command (terminal)-
What you can try –
Edit /etc/hosts file, put in the IP and Hostname in this file. That ought to resolve your Hostname and IP
Like This –
Lastly an awesome link – http://bit.ly/IHhA1R
EDIT
Possible workflow –
Always use the same workflow to get Latest IP of the HOSTNAME provided by the user, connect using IP instead of HOSTNAME