You are not logged in.

#1 2009-08-05 12:31:55

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Possible to associate one local hostname with two local addresses?

I'm trying to set up a backup system for our LAN. Several of the programs involved (e.g., rsnapshot) have their configuration based around what they recognize as the hostname of the other end. It's easy enough to set the local hostnames as I like, either in /etc/hosts or in /etc/ssh/ssh_config.

BUT the issue is that some of my machines might have different IP addresses depending on whether they're connected over wire or wifi. (Sometimes both connections are up; then wire should take precedence.) And some of the services I'm setting up (again, rsnapshot is an example) have the server initiate the connection to the client. (At least, it's what I think of as the server: the machine with the static wired LAN connection that the backup storage is kept on. The machines being backed up are the ones whose numeric IP isn't stable.)

Again, this is all inside a LAN. The IPs involved are all 192.168.*.* stuff.

How do I get the server to know what IP a given host, e.g., "wifeslaptop", has? If it were just a matter of a single network card, e.g., only wifi connections, then the router is already able to assign it a fixed local IP. But wifeslaptop might (instead or additionally) be connected by wire, too.

I see five possible strategies for solving this.

1. Is it possible to get the server to associate two numeric addresses with a single hostname? So that it recognizes both as instances of "wifeslaptop", and I guess if it wants to initiate a connection to that host, it tries the first numeric address then the second if that fails? Is it possible to do this simply, or does it require installing some kind of extra server/daemon?

2. Failing that, I guess I need to wrestle with our router to try to get it to assign the same numeric address to the wired or the wifi connection, and ensure that both connections are never active at the same time.

3. Or I've got to set up some kind of local dynamic dns system, so that my server can look up "wifeslaptop" and discover what LAN IP address it has.

4. Failing all of that, maybe I need to instead dynamically generate the config files for the services I'm trying to use. E.g., before running rsnapshot, the server could ping the two numeric addresses wifeslaptop might have, then generate a rsnapshot config file on the fly associating the address which is present with the (single) backup store it keeps for wife's laptop.

5. Or maybe simplest yet, if it works, I could (either with symlinks or with mount -o bind) let rsnapshot THINK there are two backup stores, one for each version of wifeslaptop, but have them point to the same place on disk.

I'm listing all these strategies so that you can say "Forget about 1, 4 or 5 are much easier." But for the moment, what I'm thinking about is 1. Is this easy to do?

Offline

#2 2009-08-05 12:39:46

scio
Member
From: Buffalo, NY
Registered: 2008-08-05
Posts: 366

Re: Possible to associate one local hostname with two local addresses?

I would say 2 or 3 would be the ideal ways.  You are basically describing what a router/DNS server should do, route traffic.
If you wanted to do 4, I would look at arp or route (but those require root).

Offline

#3 2009-08-05 15:04:38

majiq
Member
Registered: 2009-03-06
Posts: 259

Re: Possible to associate one local hostname with two local addresses?

I'd avoid 2, because messing with routers is just irritating. 4 is what I would have done, after of course, being told that I can't do one. I know that it is possible to register multiple IPs to a host because of posts like this, but from jumping around man pages (hosts, host, 5 resolver, gethostbyname) it seems that the solution is 3.

Offline

#4 2009-08-05 23:09:41

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Possible to associate one local hostname with two local addresses?

I've got around this problem by getting my laptops (which could be wired or wireless) spoof the same MAC address for both interfaces. That way, my DHCP server hands out the same address lease regardless, and then it's up to the client to bring up the correct interface (wireless only if wired is unavailable).

Offline

#5 2009-08-06 00:21:15

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Possible to associate one local hostname with two local addresses?

Thanks for the responses.

Offline

#6 2009-08-06 13:47:12

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Possible to associate one local hostname with two local addresses?

There's some promising text in "man -s7 hostname" which says env variable HOSTALIASES can point to a file which expands simple hostname aliases (with no periods) to whatever you want (I think the expansion has to be to a hostname not a numeric address, but not sure). One could then just manipulate the alias file dynamically. However, this doesn't seem to work with any of the utilities I tried (ping, host).

I guess I could try manipulating /etc/hosts or /etc/ssh_config, since I'm going to be using rsnapshot on top of ssh. But given the potential downsides of messing up either of those files, I'm now inclined to just generate rsnapshot's config file dynamically instead. And hope that similar workarounds can be found for other utilities...

Offline

#7 2009-08-06 21:40:20

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Possible to associate one local hostname with two local addresses?

Another solution might be to have the remote machines make ssh-tunnels to the backup server---either they could initiate the tunnels every time they come onto the network (in either a wired or wireless guise), or the server could probe for them and create the tunnels itself before it runs the backup jobs. Then the backup job can just point to localhost:the_port_that_leads_into_the_tunnel, which will always be the same, no matter what numeric address the other end of the tunnel leads to.

This may be the most elegant solution. I don't know whether it will have any negative impact on performance; the backups were going to be rsync over ssh anyway.

Offline

#8 2009-08-06 23:03:14

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Possible to associate one local hostname with two local addresses?

Spoofing the MAC address would be more elegant than that IMHO.

If you're using netcfg, add this to the PRE_UP config for both your Wired and Wireless configurations:

ip link set eth0 address 00:16:ea:d7:8b:a6

Replace eth0 with the appropriate interface of course.

Offline

#9 2009-08-07 02:12:31

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: Possible to associate one local hostname with two local addresses?

OK thanks for the instructions!

Offline

Board footer

Powered by FluxBB