Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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).

share|improve this question

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).

share|improve this answer

If you are in the same network you are in the same broadcast domain. How big is the network? Class C or more?

If class C you could simply ping all 253 IPs and look into your arp-cache if you find "your" MAC-adress.

share|improve this answer

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.

For example, any user on finder can resolve lost, as follows:

$ avahi-resolve -4 -n lost.local
lost.local      192.168.56.102
$ avahi-resolve -6 -n lost.local
lost.local      fe80::a00:27ff:fea7:4900

Similarly, on lost:

$ avahi-resolve -4 -n finder.local
finder.local    192.168.56.101
$ avahi-resolve -6 -n finder.local
finder.local    fe80::a00:27ff:fe72:804

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).

share|improve this answer

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.

share|improve this answer

You can use tcpdump to capture the response to a broadcast ping from your finder pc. For example if your network is 192.168.1.0/24 and the mac address of your "lost" computer is a1:25:de:1f:00:12

ping -c 20 192.168.1.255 &> /dev/null & tcpdump -n -c 1 ether host a1:25:de:1f:00:12

Adjust the ping count higher if you're not getting any responses

share|improve this answer

edit the file: /etc/nsswitch.conf

change the line: hosts: files .... to: hosts: files wins ......

then at the commandline: sudo apt-get install winbind

now you can refer to the computer by hostname: ping computername,ftp computername

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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