How to get knife to connect using the IP instead of hostname

I’m using AWS with EC2 instances in a private subnet meaning they have no public facing IP/hostname. When I install and run chef-client on the node, it’s registered on the Chef Server using it’s private hostname and ip, e.g.


When I try to run knife ssh "role:web" "sudo chef-client" -x ubuntu -i key.pem from my local machine, it tries to connect to the nodes using the private hostname. This hostname doesn’t actually exist and it doesn’t connect. I would like knife to connect using the private ip instead. Is this possible?

You can use the -a or --attribute switch for knife ssh. I believe giving that a value of ipaddress should use the ohai ipaddress to connect.

1 Like

Thanks @Matt_Wrock - I literally just typed knife help ssh and saw that. :flushed: