0

I'm writing a custom SSH server. Whenever I connect to it via ssh user@subdomain.example.com, I need to know the value of the subdomain.

Right now I can only get remote and local IP addresses.

2
  • nslookup <ipaddress> – ChuckCottrill May 12 '17 at 23:15
  • If this is just you using the server, then you could export an environment variable that has the name you are connecting to and allow that on the server side. This is completely untrusted data and obviously can be spoofed, but that is one way I have seen it done (to set a prompt based on a cname). – Aaron May 13 '17 at 4:02
4

The SSH protocol knows nothing about the hostname that's used to connect to it. The client merely resolves it to an IP address and then uses that IP to connect.

It sounds like perhaps you've had experience with HTTP servers, and their ability to be made aware of the hostname used to access them. This functionality is possible only because the HTTP client sets a Host header in the HTTP request, whose value is the hostname used to access the server. There is no equivalent functionality in SSH.

Not the answer you're looking for? Browse other questions tagged or ask your own question.