# Resolving local names without appending .local

## devilheart

Hi. I'm wondering if I really have to append .local after the name i wish to resolve locally through avahi. This is the situation: i have a pc in my network named 'mini' and if i try to ping it with "ping mini" I get an "unknown host" message while "ping mini.local" works. my /etc/nsswitch.conf is configured like this 

```
hosts:       files mdns4_minimal dns
```

So basically i want this:

1)lookup the name in /etc/hosts

2)if not found append automatically a .local string after hostname (if the name provided is not a fqdn) and query avahi

3)if still not found do a standard dns query

Can this be achieved?

I've tried to add a "search local" string to /etc/resolv.conf but this blocked all normal dns queries (ping mini works like ping mini.local but ping google.com does not work anymore)

----------

## causality

Try arranging your /etc/hosts file to look like this:

```

127.0.0.1       localhost.somedomain localhost

192.168.1.2     machine1.somedomain     machine1

192.168.1.3     machine2.somedomain     machine2

192.168.1.4     machine3.somedomain     machine3
```

Using the 192.168.1.2 IP as an example, the name is "machine1.somedomain" and "machine1" is like an alias.

All of the commands below will do the exact same thing:

```

localhost ~ # ping 192.168.1.2

localhost ~ # ping machine1

localhost ~ # ping machine1.somedomain

```

You can use such an alias to get this functionality, so you can just ping "mini".  Your system will fallback to DNS if you try to use any hostname not configured in your /etc/hosts file.  In other words, in those three steps you listed, only Step 1 was failing when you tried "ping mini".

I am not so sure about appending .local to a domain.  I think you can add a line "domain local" to your /etc/resolv.conf to arrange that, at least for DNS.

FYI, I am not familiar with the "mdns4_minimal" line in your nsswitch.conf.  My own does not have such a statement, though I think this issue is basic enough (in that a modification to /etc/hosts alone should fix it) that it won't affect anything.

----------

## devilheart

 *causality wrote:*   

> Try arranging your /etc/hosts file to look like this:
> 
> ```
> 
> 127.0.0.1       localhost.somedomain localhost
> ...

 thank you but i would like to do this without editing /etc/hosts. ip addresses may change due to dhcp

 *Quote:*   

> In other words, in those three steps you listed, only Step 1 was failing when you tried "ping mini".

 i guess all three steps failed

 *Quote:*   

> I am not so sure about appending .local to a domain.

 well, what i want is this: when i type "ping mini" i wany my system to 1)query /etc/hosts for "mini", 2)query avahi for "mini.local" 3)query dns for "mini"

 *Quote:*   

> I think you can add a line "domain local" to your /etc/resolv.conf to arrange that, at least for DNS.

 this works for avahi but breaks dns, same as "search local"

 *Quote:*   

> FYI, I am not familiar with the "mdns4_minimal" line in your nsswitch.conf.  My own does not have such a statement, though I think this issue is basic enough (in that a modification to /etc/hosts alone should fix it) that it won't affect anything.

 AFAIK, mds4_minimal tells avahi to search only in local domain

----------

## causality

Both DNS and /etc/hosts just associate a given IP address with its corresponding hostname(s).  The DNS server doesn't have any more of a clue than the hosts file when it comes to which machine should have which IP.  Both DNS and /etc/hosts assume you've already sorted that out.

You can configure DHCP so that a particular machine always gets a particular IP address.  Most (all?) home routers and all DHCP server daemons can do this.  You'd end up having to do something like that because otherwise you'd have the same objection to hostnames set in DNS that you raise for hostnames in /etc/hosts.  Just like /etc/hosts, DNS will happily map a given IP to a corresponding hostname; it does this with no regard for whether a machine on your network actually has that IP address or whether it's the one that _should_ have that IP address.

Once you have set DHCP up this way, whether you modify /etc/hosts (on each host) or the configuration file of a DNS server really only depends on how many machines you have to keep track of.  I mentioned /etc/hosts first because it's the simpler method.

----------

## devilheart

 *causality wrote:*   

> Both DNS and /etc/hosts just associate a given IP address with its corresponding hostname(s).  The DNS server doesn't have any more of a clue than the hosts file when it comes to which machine should have which IP.  Both DNS and /etc/hosts assume you've already sorted that out.

 this is why multicast dns was introduces. avahi does not need to know any hostname<->ip address association. i don't know how it really works but i guess avahi just sends a broadcast request "who is alive?". now i can ping other hosts if i know their names by typing ping hostname.local

what i want to do is ping hosts without adding that .local because it is something avahi should be able to figure out on his own

 *Quote:*   

> You can configure DHCP so that a particular machine always gets a particular IP address.  Most (all?) home routers and all DHCP server daemons can do this.  You'd end up having to do something like that because otherwise you'd have the same objection to hostnames set in DNS that you raise for hostnames in /etc/hosts.  Just like /etc/hosts, DNS will happily map a given IP to a corresponding hostname; it does this with no regard for whether a machine on your network actually has that IP address or whether it's the one that _should_ have that IP address.
> 
> Once you have set DHCP up this way, whether you modify /etc/hosts (on each host) or the configuration file of a DNS server really only depends on how many machines you have to keep track of.  I mentioned /etc/hosts first because it's the simpler method.

 this is not feasible. i'm not the administrator of the network plus the issue will arise again when i connect to a new network

----------

## Anon-E-moose

cat /etc/resolv.conf 

```

# Generated by don for interface eth0

search localhost home

nameserver 192.168.1.10

nameserver 127.0.0.1

nameserver 192.168.1.1

```

ping martin

```
PING martin.home (192.168.1.11)
```

----------

## devilheart

thank, i'll try

EDIT

nope, that kills dns

----------

