script that will copy a hosts file

Posted on 2006-04-12
Last Modified: 2008-01-09
I need a script that will copy a hosts file I maintain on my Linux (SAMBA PDC) server to my XP clients. Instead of reinventing I'm just looking to see if anyone has already done this and if so could send me the .bat file.
Question by:infinityit
    LVL 22

    Assisted Solution

    Just add the following line to the logon.bat file:

    copy N:\hosts C:\windows\hosts

    There are a couple of problems here in that the user copying the file must have administrative rights to do this, and also windows XP home, and professional seem to use the aforementioned direcory, and C:\ if someone would like to expand on the concept.

    You need to have created the samba share:
    [ netlogon]
      comment = Network Logon Share
      path = /home/netlogon
      guest ok = yes
      writable = no
      share modes = no
      browseable = no

    Note that this is the samba 3.x version.


    Author Comment

    The command
    copy N:\hosts C:\windows\hosts

    looks to me like it's copying from a windows mapped drive (N:) to the windows system drive.

    My hosts file will be in /home/netlogon on the Samba server and from there I want the script to copy the file to the Windows system drive (which is actually c:\windows\system32\drivers\etc)

    My [netlogon] in smb.conf is exactly as you've written.
    LVL 3

    Expert Comment

    Why don't you just setup a DNS (bind, djbdns) server on the Linux box, and add the linux box as a secondary (or tertiary) to the windows machines? It'll be much easier in the long run. It'll also get you around the problems of the users needing to be Administrator etc etc.

    I guess you want the login script to look like this:

    net use N: \\sambaserver\netlogon
    copy N:\hosts c:\windows\system32\drivers\etc

    also you'd want to add a cron job on the linux box that copys the /etc/hosts file to one in the /home/netlogon folder (using the example above)


    Author Comment

    The DNS idea sounds like a good one. Do you know of a resource I can refer to that will guide me through that process?
    LVL 2

    Accepted Solution

    I have to disagree that DNS is a good way to solve this problem. First, it`s a service that was crackers favorite for some time in the past. It`s better nowdays, yet it is a service meant for bigger, more complex networks. Yet host file coppying should be quite a mess. I`ve solved the problem, using samba. Just by adding thease lines

    wins support = yes
    name resolve order = wins hosts lmhosts bcast

    Will  enable you to read the contant of the hosts file on every XP computer on the net.
    LVL 2

    Expert Comment

    Oh, one more thing

    If you wish to enbale a DNS after all, a good guide is

    Have a nice day

    Author Comment

    OK I already have "wins support = yes" in my conf file. If I follow it with "name resolve order = wins hosts lmhosts bcast" does that mean every XP box on my network will use the hosts file on the Samba box after it tries wins to resolve providing the XP boxes use wins?
    LVL 2

    Expert Comment

    I belive so. And I`m quite sure that trying it won`t blow any computer :)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
    Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now