localhost or LAN addresses in /etc/hosts

Derek Broughton news at pointerstop.ca
Mon Dec 15 18:44:28 UTC 2008


Chris G wrote:

> On Mon, Dec 15, 2008 at 09:54:13AM -0400, Derek Broughton wrote:
>> Chris G wrote:
>> 
>> > The whole point is to make things easy to configure, my router
>> > certainly *doesn't* know the names/addresses of machines on my LAN
>> > and I don't really see how it could.
>> 
>> The usual way is by the machine asking for DHCP to send its name, and
>> the router sends back an IP - and updates its local DNS.  This is not
>> implemented in every router, but it's _really_ common.
>> 
> So the *router* decides what the machine's name is?

No, "the machine asking for DHCP" (ie, your computer) "sends"  its own 
name to the DHCP server.

>> > ?? So what's the difference?  :-)  ...
[between "fixed" DHCP and static IP addresses]
>> 
>> Logically, none.  But you can get this effect with the DHCP on any
>> router I've used.
>> 
> I really don't understand this.  I have two printers on my network,
> one is an HP7310 which has its own network interface the other is a
> laser printer which is accessed via an Axis print server.  So, if the
> router is providing DHCP and DNS services how does it get to know
> about the printers? 

Anything connecting to the network should be capable of getting a DHCP 
assigned address.

> Presumably when I turn the Axis print server on
> it gets an IP address from the router but how does the router know
> that it's a printer and/or give it a useful name that I will know
> about and be able to use?

The print server should send its own name.  Just like your computer 
does.

>> > and, if they did change when,
>> > for example, a printer was turned off and then on again (as it
>> > might when using DHCP) how would the rest of the system know the
>> > printer's IP address?
>> 
>> That's the point - it can't change, but that doesn't mean you need to
>> go
>> to this trouble with static addresses.  Use the DHCP on your router,
>> tell it to always assign 192.168.1.44 to the MAC address of your
>> hp7310 printer, and then even if you disconnect and reconnect, your
>> printer will always have the same address - and it _should_ be in
>> your router's DNS, too.
>> 
> How is that any easier than simply giving the printer a static IP?  I
> have to faff about in the router's configuration to tell it to
> associate the MAC addres with the printer, that's just *another* place
> I have to do things.

No, that's just the ONE place you have to do things.  In the time you've 
been asking us how to do this with a piece of software that you had to 
add to your system, I could have done the setup dozens of times on a 
router.

> I'm using dnsmasq to try and minimise that sort of hassle.

How much hassle do you think you've minimized so far?

> How is setting up MAC addresses to match devices in the router any
> easier than editing /etc/hosts?  That's where I really don't follow
> what you're advising.  As it is all I do is:-

You HAVEN'T got it to work with /etc/hosts - specifically because you're 
trying to do something you can't do.  
 
>     Set the printer (for example) to have a fixed IP of 192.168.1.40
> 
>     Put "192.168.1.40  printer" in /etc/hosts on *one* system which
>     runs dnsmasq.

Same on the router.  You don't even _have_ to have the MAC address.
 
> The printer never changes once its IP address is set, computers may
> come and computers may go but that only needs doing once.  Similarly
> if I change the computer where dnsmasq is running all I need to do is
> copy /etc/hosts and everything is done.

So do things the hard way, then, but you'd rather argue with everybody 
who's telling you you simply _can't_ do it the way you want to.  Your 
/etc/hosts can only have ONE (working) IP address for a single host.  
And whether dnsmasq can handle hostnames without domains or not, you 
can't _treat_ "isbd" in a dns lookup from a client with no search 
domains set, the same as a hostname lookup in the local /etc/hosts.  
They're doing different things, that just happen to resolve to the same 
address when isbd _is_ your local host (and then only because local dns 
lookup generally checks your /etc/hosts first).
-- 
derek





More information about the ubuntu-users mailing list