LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (http://www.linuxquestions.org/questions/linux-general-1/)
-   -   How to access services on LAN using a hostname? (http://www.linuxquestions.org/questions/linux-general-1/how-to-access-services-on-lan-using-a-hostname-4175456608/)

Z038 04-02-2013 08:46 PM

How to access services on LAN using a hostname?
 
I have several servers running on my LAN that I want to be accessible to other LAN systems by hostname. NFS, SSH, FTP, WebDAV, and HTTP are a few. I currently have to enter the local IP address of the system that runs the service to access it from another system. For example, I have to type "ssh username@192.168.1.5" to access the ssh server on that system. I'd like to be able to use a hostname instead of the IP address, like "ssh username@hostname".

What do I need to set up on my LAN to make that possible?

evo2 04-02-2013 09:07 PM

Hi,

you can setup DNS, but how to do that is beyond the scope of this post.
Alternatively, if the number of hosts is sufficiently small (and sufficiently static) you may prefer to maintain the /etc/hosts file on each host. In each /etc/hosts file add a line for each host on your network. Eg

Code:

192.168.1.5 mediapc
192.168.1.6 desktop
192.168.1.7 notebook

For more information
Code:

man 5 hosts
Evo2.

lleb 04-02-2013 10:10 PM

you can do as evo2 suggests or if you are in control over your DNS server, you can add the hosts there as well.

I use a combination of both as i run in a very mixed environment. win7, OSx, and Linux (both CentOS server and F18 laptop). The combination works great for me.

Z038 04-03-2013 01:33 AM

Ok, thank you both. I have six systems on my LAN right now, four Linux (Slackware) and two Windows. I could manage host files on each, but I like the idea of using my DNS server. I am running named (bind) as a cacheing only nameserver on one of my systems. Here is my named.conf file:

Code:

options {
        directory "/var/named";
        /*
        * If there is a firewall between you and nameservers you want
        * to talk to, you might need to uncomment the query-source
        * directive below.  Previous versions of BIND always asked
        * questions using port 53, but BIND 8.1 uses an unprivileged
        * port by default.
        */
        // query-source address * port 53;
};

//
// a caching only nameserver config
//
zone "." IN {
        type hint;
        file "caching-example/named.root";
};

zone "localhost" IN {
        type master;
        file "caching-example/localhost.zone";
        allow-update { none; };
};

zone "0.0.127.in-addr.arpa" IN {
        type master;
        file "caching-example/named.local";
        allow-update { none; };
};

What would it take to make it resolve local hostnames?

allend 04-03-2013 09:09 AM

As you have Windows machines, you may want to add 'wins' to the hosts line in /etc/nsswitch.conf as pointed out in this 5 star thread http://www.linuxquestions.org/questi...-samba-271336/

I cannot help with bind as I use dnsmasq.

Z038 04-03-2013 01:20 PM

allend, thank you for the link to that thread. Adding "wins" to the hosts options in the /etc/nsswitch.conf file did the trick for me.

I've never updated the nsswitch.conf file before today. I'm not really clear what is affected by it, or what uses it. I've been reading about it, but I don't understand why adding the wins (Windows Internet Name Server, apparently) parameter allows my local host names to be resolved on my linux systems. Do you have any idea?

allend 04-03-2013 06:05 PM

'man nsswitch.conf' is more definitive, but adding 'wins' adds an additional service for building the 'hosts' database used by the GNU C library for obtaining name-service information.
i.e. You are telling Linux to also handle the information provided by Windows via wins.

Z038 04-03-2013 08:42 PM

Ok, that makes sense.

Just to see if I could achieve the same thing using bind (named), I removed the wins keyword from nsswitch.conf, verified that name resolution went back to the way it was before (i.e., local host names not resolving on the linux systems), then changed my /etc/named.conf to make my DNS server authoritative for my own domain name (a master server). I also set up a slave DNS server on another system on my network. It worked just as well for the systems on my network that have static IP addresses. So it appears you can get local host name resolution via a bind server or wins.

Now I just have to figure out how to get my bind named server to handle the dynamically assigned IP addresses. The majority of the systems and appliances on my network get an IP address from the DHCP server that I run on the same system that hosts my DNS master server.

I believe I'm going to stick with the bind setup, but it's good to know that adding wins to nsswitch allows a Windows system running a wins server on the local network to resolve local host names too.

Z038 04-03-2013 08:46 PM

I've marked my thread "Solved" because my original question is answered. But if anyone has any insight into how to resolve hostnames for systems with dynamically assigned IP addresses using bind, I'd like to hear.

chrism01 04-03-2013 10:36 PM

I think you want to look at ddns-update-style
http://www.linuxtopia.org/online_boo...ml#config-file
http://linux.die.net/man/5/dhcpd.conf

Z038 04-04-2013 12:18 PM

Chris, thanks for the suggestion. It took me a few tries to get it set up right, but I've now got my dhcp server sending dynamic DNS updates to my master bind server whenever a lease changes. The host names for all of my systems are now resolving correctly from anywhere on my LAN.

I still need to review security settings in both bind and dhcpd, get my secondary DNS server squared away, and maybe set up failover for my dhcp server.


All times are GMT -5. The time now is 10:05 AM.