# SSH: Route conn. to different machine based on hostname?

## Tatsh

I have one IP and several machines behind it. One router and a few switches.

So basically it would be cool if from outside the network, I could do the following with no ~/.ssh/config for the Port option:

ssh a.somedomain.com -> a.internal:22

ssh somedomain.com -> main.internal:22

a.somedomain.com and somedomain.com point to the same IP.

Is it possible for iptables to recognise the hostname before any SSH negotiation sequence and reroute before that? Is there any tool similar to HTTP proxying (squid, nginx) but works for SSH or almost any connection?

From what I've seen on it seems most say that there is no concept of hostname (other than for resolving IP via DNS) compared to HTTP/S protocol, which means you can definitely do something based on IP but not hostname   :Sad:  ? I am wondering if anyone here has any information contrary to that.

----------

## szatox

iptables uses IPs, not names. However, you can redirect connection by protocol and by port as well.

So, it is possible to match incoming packet against router's external IP and some arbitrarly chosen port and route it to some host (And port) in your local network. Check out iptables DNAT target for details

----------

