Let's say that I have a computer plugged in to a local network using a dhcp connection, so it will get a different IP every time. Is there a way to find this computer (so the IP) from a different computer on the same local network?

Both computers run Linux. I can set up the "lost" computer a'priori before it gets restarted (and gets a different IP), but I would prefer a solution that just works out of the box (if it exists).

6 Answers
6

If you can configure the dhcp daemon, a good transparent solution would be binding a specific ip address to the computer network card MAC address — that way when the computer requests an address via dhcp, the daemon will hand out the very same address.

Some dhcp servers let computers propose hostnames (I'm unsure of the internals, and whether this is actually common behavior or not) - you may want to check whether this works with your router or not. Even if it works, you need to have your dhcp client send the hostname (the --hostname option in dhcpcd). It's a shot in the dark, but it's worth a try — if it works, you can just use the computer hostname instead of the ip address (or use it to find the numeric address).

Since you tagged your question "Debian", here's a quick recipe that should solve your problem.

On your lost and finder computers run the following (as root, or use sudo as/if necessary):

# apt-get install avahi-utils

Then, as long as the lost and finder computers are on the same broadcast domain (i.e. the same physical network), you should be able to use avahi-resolve to resolve the IP address (either v4 or v6) of each host from the other.

Obviously, I have glossed over a lot, and a few little details could go wrong that prevent avahi from working correctly out of the box, but from my own experiments on a few different occasions, there's a good chance that it should all Just Work (tm).

If you have some control over the DHCP server, arrange that it always provides the same IP address to your machine. Most DHCP servers out there can reserver IP addresses to a machine with a given MAC address or to a particular client name.

Otherwise, the next best thing is to use a dynamic DNS service: a small program running on your computer sends an update to a DNS server whenever your computer's IP changes. You can set up your own dynamic DNS server inside or outside your LAN, or piggyback on an existing DNS server, or use one of the dynamic DNS services out there (there are free ones, at least for personal use).

If that's not an option either, you can have a script that accesses a web page under your control and leaves your IP address there. Crude, but works through most firewalls.

An alternative that doesn't require knowing the IP address of your computer is to establish a tunnel (a VPN) between your computer and another computer with a known IP address. Run the VPN client on the computer with the changing address and the VPN server on the fixed-IP machine. Once the tunnel is established, you can open connections in either direction.