I don't want to specify an IP address, since it can change in a DHCP LAN. I tried to connect to the linux server's name, but neither Putty nor Windows' ping.exe could resolve it.
I can see solutions in a couple of categories:
- Static IP:
- Fix the IP on the Linux machine and exclude that IP from the DHCP server.
- Get the DHCP server (your router?) to give the Linux server's MAC address a fixed address.
- For either of these, put the static IP address in your client's hosts file.
- Dynamic IP with DNS.
- Find some way of having the Linux machine send a hostname with it's DHCP request, and having the DHCP server/DNS server expose this name so DNS resolution will work. Depends on DHCP and DNS servers.
- Put the Linux server's current IP on some fixed shared resource (e.g. external web-page). And script something hacky on the client to get that and use it as the server IP address.
You can configure dhcp to send a hostname with the dhcp request. Obviously you would need your dhcpd and nameserver to support this, but lots of routers support this feature so its worth checking if yours does.
Unfortunately, you're rather out of luck. In order to do this you need to use something like mDNS. It is implemented out of the box in OSX, called Bonjour, but hasn't reached critical mass outside of Apple yet. If you control the DHCP server you could set up DHCP Reservations for specific systems. In this scenario a nic with a specific MAC address will always get the same, statically defined, address from the DHCP server.
You won't be albo to resolve the address unless it's in some DNS server. You need to know the IP address or you can use some services like No-IP to update a FQDN to the servers current IP address. Of course this will only work for a server that has a public IP address.
For internal addresses you might want to write a script on the server that will send you the IP that is has at some point in time.
Some things in your question are still unclear, but i'll try to give a broad answer.
In order to connect to the machine via it's hostname, you need a name-resolution service active on the network - that is, a DNS or WINS server. Seeing that you say your machines cannot ping each other by name, it appears that you have no DNS server in the network (or that neither machine is set up with a primary DNS server). Which begs the question - what network enviroment would have DHCP but no DNS?
If there IS a DNS server on the network, then you just have to set both machines up to contact it (network connection properties in windows, god-knows-where.conf in linux) and you're all done.
Let's assume no DNS server then.
Assuming you have control over the DHCP server in your network, the easiest solution would be to set up a static ip mapping in the DHCP server. Make it give the linux server the same ip each time (bind a specific ip to the server's nic's MAC address). Then you can edit the hosts file on the windows workstation (found in %systemroot%\system32\drivers\etc) and map a specific name to the address, and enjoy yourself.
If you don't have control over the DHCP... Well, personally, i would just go bug the people who do (and tell them to get a DNS server in there for god sakes!)
I can think of other wild stuff that could circumvent all around this issue (write a script that pings the whole subnet, runs arp -a into a file, and then scans it to find the MAC address of the server, thereby resolving it's IP.. sheesh, this is sick). Seriously though, I would try to get a decent name resolution service up and running.
I also have Linux server on a DHCP network. The easiest way I've found to use DHCP and still be able to easily connect to the server is to give it a static ip. You can still use DHCP for other clients, but have a static ip for your server.
You don't say what Linux distro you use, but here's the relevant part of my rc.conf from Arch Linux.
lo="lo 127.0.0.1" eth0="eth0 192.168.1.11 netmask 255.255.255.0 broadcast 192.168.0.255" INTERFACES=(lo eth0) gateway="default gw 192.168.1.1" ROUTES=(gateway)
As others have pointed out, the problem is with name resolution, not SSH.
But the best solution is to configure the DNS, DHCP Server and DHCP Client so that a DNS entry is created automtaically for all the DHCP clients. This is easily done with Microsoft's DHCP server (I should be able to provide instructions if that's helpful) but should also be possible with other servers.
Basically you need:
- A DNS server that accepts dynamic updates (you may want to secure this).
- A DHCP server that sends a dynamic update for all clients (MS DHCP server will do this, but doesn't by default).
- A DHCP client that tells the DHCP server its name (most do this automatically, but it may be an option that needs turning on).