0

I am working on linux environment and c language. I can not use python,perl,PHP and apache. What my exact need is I want to give a same host name to each device connected in the network. I know that we can't give same host names to all the devices. But Can it be done through cnmae?

For example:

There are 3 devices connected in a local network Device-A,Device-B and Device-C. The IP address will be 192.168.0.4,192.168.0.5 and 192.168.0.6. Each device contain one httpd server from which I can access the web pages of that device in my PC. Let say if I type 192.168.0.4 in the browser then it will open the web page of that device. Now My PC is directly connected to one device. And I will write device.local in the browser so it should open local device's web page. Is it possible? If yes then how?

Research which I have made:

  1. I have used dnsmasq but it fails to run. I have just turned on the cname in dnsmasq.conf file. It gives me following error: dnsmasq: bad option at line 529 of /etc/dnsmasq.conf
  2. I am using avahi for zero conf networking. In that avahi-daemon is there. So I can give the host name to each device. But it gives the name like device.local,device-2.local and device-3.local. After that I have followed this link also but it did not work for me.

    http://www.mail-archive.com/avahi@lists.freedesktop.org/msg01907.html

Thank in advance. It is really important for me to solve this problem.

Malay
  • 1
  • 1

2 Answers2

3

You can use Round Robin DNS to make a single DNS entry give out one IP address in a pool of multiple IP addresses. So a query for device.local will reply with 192.168.0.4, and then the next query for device.local will be replied to with 192.168.0.5 and etc. until the pool of addresses is finished. Once the pool of addresses has been given out in succession, the DNS server will start back at the top of the list of IP addresses and give them out in the same order again. It's a poor man's load balancing, in essence.

A CNAME record is not what you are looking for. Stop using them - you want to use A records and round robin.

Let say I have connected my 1st laptop to Device-A and 2nd laptop to Device-B. In browser of both the laptops I write device.local. Then In first laptop it should show me web page of Device-A and in the second laptop it should show me web page of Device-B. Is it possible?

Now that's a different scenario. In the first scenario I talked about above, all devices (deviceA, deviceB, deviceC and any PCs / laptops that want to access them) are all on the same network, or at least have a clear route to deviceA, B and C.

If you directly connect a laptop to DeviceA, but have no ability to connect to Device B or C. You have two problems:

  1. You have no access to the DNS server that hosts the round robin records. Your only option is to then host a DNS server service of some kind on the laptop itself or use gulp the hosts file.
  2. If you do host the round robin DNS service on your laptop, you have only a fraction of a chance of having the right IP address given to you. If DeviceC's IP address is next in the round robin queue, but you're only connected to DeviceA, then you're out of luck.

If direct connection between two devices is necessary, you're only hope is broadcast name resolution like what SAMBA / NetBIOS provides. However, that doesn't work across subnets (without great pain and suffering) and certainly doesn't work across public networks like Yon Grande Internet.

At this point, I believe you need to seriously consider:

  1. What you are trying to engineer
  2. Why you are trying to engineer it this way
  3. The purpose and limitations of the protocols and standards involved. (Namely DNS and name resolution in general)
Wesley
  • 32,320
  • 9
  • 80
  • 116
  • Let say I have connected my 1st laptop to Device-A and 2nd laptop to Device-B. In browser of both the laptops I write device.local. Then In first laptop it should show me web page of Device-A and in the second laptop it should show me web page of Device-B. Is it possible? – Malay Mar 31 '13 at 07:21
  • in which case, you're better off using the hosts.txt file – Journeyman Geek Mar 31 '13 at 07:28
  • @Malay No - that's a different scenario altogether. I've updated my answer. – Wesley Mar 31 '13 at 07:33
  • I am using zero-conf(avahi) network for the devices. The device does not have any kind of display on it so it can not show the IP address of its own. Now Let say there are 3 devices in a network and also my laptop. I turned on the network and device will get the IP addresses by avahi. Now I want to know the ip address of all the devices. Laptop is connected to device-A. So Device-A would be local to that laptop.I don't want to use any kind of softwares like angry-ip-scanner. – Malay Mar 31 '13 at 07:46
  • In my previous comment I said that laptops are directly connected to the device. Here let me clarify that the device which I am using has two ethernet ports. so they can connect to other device also and also to the PC. So all the devices will be in the network with laptops. – Malay Mar 31 '13 at 07:50
  • There is not any dhcp server running in my devices. – Malay Mar 31 '13 at 07:57
  • If you're using avahi, you might be able to use netstat or maybe ping to work out the IP address of the individual systems – Journeyman Geek Mar 31 '13 at 09:37
  • Please close this issue if required. Thanks again. – Malay Mar 31 '13 at 10:49
  • @Malay I think you'll need to rely on broadcast name resolution like NetBIOS or SAMBA. – Wesley Apr 01 '13 at 00:42
  • @WesleyDavid I have compiled the samba server for my architecture. I can find two apps named as smbd and nmbd. Should I have to run them both smbd and nmbd? Will only nmbd serve my purpose? – Malay Apr 17 '13 at 06:57
1

You're using the totally wrong approach. You want each device to resolve names differently - the whole point of DNS is not to have different devices resolve names seperately. You'd either want a different DNS server per device, which means having a local DNS server set up per machine, or... the smart answer, just use the hosts file for the system itself, which would be simpler.

Journeyman Geek
  • 6,969
  • 3
  • 31
  • 49