How to create TCP proxy that supports multiple hosts?

Solution 1:

TCP works over IP and IP has no notion of host(names) but only of IP addresses.

As such, TCP knows also only about IP addresses, not hostnames.

If you want to have something handling hostnames you need a protocol on top of TCP (ex: HTTP, SSH, etc.) or translate names to IP addresses before using TCP, as the DNS is typically providing.

Or you need your "TCP" proxy to listen on separate ports and proxy things depending on which port is accessed. However you still have the problem of mapping names to now not only an IP address (of the proxy) but its port too, which is possible but more difficult with DNS (if you control the client, you can do that using SRV records or in the future SVCB ones).