Find the answer to your Linux question:
Results 1 to 9 of 9
Hello, I am configuring a network. There is 10 clients and 1 server running on CentOS. The server task is to run a lmgrd license application to allow clients to ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8

    How to configure a server without fixed IP ?


    Hello,

    I am configuring a network. There is 10 clients and 1 server running on CentOS. The server task is to run a lmgrd license application to allow clients to use a microelectronic tool. I tried with a fixed IP for the server that I put in /etc/hosts of each client to communicate with the server. It worked well, but sometimes, the server shows connections fails. Maybe a conflict with other IP in the university. So, I would like to use DHCP for the server. The problem in this case is that the server will not have fixed IP. So, I will have to change /etc/hosts of all clients all the the times that the server will change of IP address. Someone know a solution ?

    Thanks in advance

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    hi,

    if i understand your problem correctly (and i'm not sure that i do...), your 10 clients need to resolve your server's name to an ip address, right so far? Further, this server needs to be assigned an ip address dynamically? I take it the clients do not need to use DHCP...are they on a different (private) subnet or something?

    anyway, what I would do in this case is install dnsmasq on the server. The package is probably already in your distro's software repos. The dnsmasq package is basically a mini-DNS server that can read the /etc/hosts file of the local server. So that means that when your local server gets its new ip address from the DHCP server, it needs to write it to /etc/hosts. i believe you can do that with a dhclient script (that you'd have to write yourself probably, but would be easy). Once the /etc/hosts file has be written to, dnsmasq just needs to be restarted.

    Then on all the clients, you just need to use the server as a DNS server. the file to use is /etc/resolv.conf, and it can look like this:

    Code:
    nameserver x.x.x.x
    where x.x.x.x is the ip address of the server.

    OR, more simple: instead of using dnsmasq, can your 10 clients and your server just use the DNS server that is surely on your university network?

  3. #3
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8
    Thanks for your help atreyu
    My clients could use the DNS server of the university to solve IP address of local server and write it to /etc/hosts of each one ?
    I did not understand how to use /etc/resolv.conf.

  4. $spacer_open
    $spacer_close
  5. #4
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by wighou View Post
    My clients could use the DNS server of the university to solve IP address of local server and write it to /etc/hosts of each one ?
    if you could use the university DNS servers to resolve the name of your server to an ip address, then they wouldn't need the server's ip address in /etc/hosts.

    but perhaps i'm not understanding your problem. please answer these questions, if you can:

    what needs to go in the /etc/hosts files of the 10 clients?

    does the server need to resolve the clients by ip address?

    what is an example ip address of a client pc?

    does the server have multiple network interfaces (eg., ip addresses), and one is for the university, and the other is for the client-specific LAN?

    does the server have DNS settings? (i.e., what is in /etc/resolv.conf). does the server have a default gateway? (e.g., run "route -n").

    I did not understand how to use /etc/resolv.conf.
    that is just the file that is used by Linux to configure your DNS servers. you don't have DNS unless you've got some nameservers in there. i assume you know what DNS is used for.

  6. #5
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8
    Quote Originally Posted by atreyu View Post
    if you could use the university DNS servers to resolve the name of your server to an ip address, then they wouldn't need the server's ip address in /etc/hosts.
    I can not do this. My local server's name is uE5. When I try from a client to do a ping uE5 and there is not uE5 in its /etc/hosts, it does not answer. So the DNS server of the university don't help.

    Quote Originally Posted by atreyu View Post
    but perhaps i'm not understanding your problem. please answer these questions, if you can:

    what needs to go in the /etc/hosts files of the 10 clients?
    I go in /etc/hosts of each client to indicate the local server IP address and name.

    Quote Originally Posted by atreyu View Post
    does the server need to resolve the clients by ip address?
    no, only the client need to resolve the server

    Quote Originally Posted by atreyu View Post
    what is an example ip address of a client pc?
    10.0.55.101

    Quote Originally Posted by atreyu View Post
    does the server have multiple network interfaces (eg., ip addresses), and one is for the university, and the other is for the client-specific LAN?
    no, but maybe this solution would solve my problem. Is it possible to connect the server with multiple network interface ?

    Quote Originally Posted by atreyu View Post
    does the server have DNS settings? (i.e., what is in /etc/resolv.conf). does the server have a default gateway? (e.g., run "route -n").
    Yes, the DNS setting is the IP address of university global server.

    that is just the file that is used by Linux to configure your DNS servers. you don't have DNS unless you've got some nameservers in there. i assume you know what DNS is used for.[/QUOTE]

  7. #6
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by wighou View Post
    I can not do this. My local server's name is uE5. When I try from a client to do a ping uE5 and there is not uE5 in its /etc/hosts, it does not answer. So the DNS server of the university don't help.
    but do the clients have DNS configured? and a default route? on one client do this:
    Code:
    cat /etc/resolv.conf
    route -n
    in other words: if you put the University DNS server and the proper default gateway on a client PC, would it be able to get on the University LAN? is this server using a 10.0.55.x ip address, too? does the server have a default gateway? ("route -n")

    Is it possible to connect the server with multiple network interface ?
    yes, that is definitely the way to go, too. but if you are not doing that already, then how are you getting both to your client PCs and to the University DNS? are all your boxes on the same switch/router, I guess? ideally, you'd have something like in the attached pic.

    (note: ip addresses are just for example)
    Attached Images Attached Images

  8. #7
    Just Joined!
    Join Date
    Feb 2011
    Posts
    8
    hi Atreyu,

    I saw your schematic. In reality, the configuration is different. From the point of view of the university server, there is no local server. Each client connects directly to university server using a switch (as do the local server). But I choosed a client to run the license of my tool (I named it license server or local server). And I want that the others clients in the classroom connect to this especific client to take the license.
    The university server does not use 10.0.55.x.
    route -n on a cleint gives:
    Code:
    10.0.55.0       0.0.0.0         255.255.255.0   U     0      0        0 eth0
    0.0.0.0         10.0.55.254     0.0.0.0         UG    0      0        0 eth0
    I am lost.
    Last edited by atreyu; 08-14-2013 at 01:15 AM. Reason: added CODE tags

  9. #8
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Quote Originally Posted by wighou View Post
    I saw your schematic. In reality, the configuration is different.
    yeah, i kinda figured. just trying to get you thinking about schematics.

    From the point of view of the university server, there is no local server. Each client connects directly to university server using a switch (as do the local server). But I choosed a client to run the license of my tool (I named it license server or local server). And I want that the others clients in the classroom connect to this especific client to take the license.
    The university server does not use 10.0.55.x.
    i still don't fully understand your ip address scheme, but i think we can leave that alone for now. provided that your lic server can get its ip address via DHCP from the University (as it is supposed to, in order to avoid your ip conflict prob) then you can try what i suggested:

    1. install dnsmasq DNS server on your lic server

    2. write a simple script that is called by dhclient which will update your /etc/hosts file whenever it runs (and gets a new ip address)

    3. configure the other clients to use the lic server's ip address as a nameserver

    For Step 1:

    Code:
    yum install dnsmasq
    For Step 2:
    read here about how you can write this script. find documentation specific to your distro, if possible. on my Fedora 17 box, i created a script named "test.sh" and put it this dir:

    Code:
    /etc/dhcp/dhclient.d/
    in this test.sh script must be a function named "test_config", where the "test" portion of the "test_config" comes from the script name (test.sh). so if the script where named "foo.sh", it would have to contain a function named "foo_config". make sure it does end in ".sh" though. and make sure it is executable:

    Code:
    chmod +x /etc/dhcp/dhclient.d/test.sh
    now in this test_config function you put the logic that updates the /etc/hosts file with the new ip address. you can determine the ip address received by dhclient by looking at a special environmental var that gets set; conveniently named new_ip_address.

    so you'd want to see if the name-to-ipaddress in /etc/hosts is already current, also see if the hostname appears in /etc/hosts at all, and then swap out the old ip for the new one, if necessary. then, if changes were made to /etc/hosts, restart the dnsmasq daemon.

    here is an example of such a script, which worked on my F17 box:

    Code:
    #!/bin/bash
    
    test_config() {
      echo "i am $0, called by $PPID"
      echo new ip address: $new_ip_address
      if [ -z "$new_ip_address" ]; then
        echo "Failed to read the new ip address from the env"
        return 1
      fi
    
      local hostname=$(/bin/hostname -s)
      if [ -z "$hostname" ]; then
        echo "Failed to get system hostname"
        return 1
      fi
    
      # look for hostname & ip address in /etc/hosts
      while read line; do
        echo $line|egrep -q ^[0-9\.]*[[:space:]]$hostname[[:space:]]* || continue
        foundip=$(echo $line|sed -e 's|[[:space:]].*$||')
    
      done < <(cat /etc/hosts)
    
      # see if hostname is already in /etc/hosts
      if [ -n "$foundip" ]; then
        if [ "$foundip" == "$new_ip_address" ]; then
          echo "Hostname \`$hostname' is already $foundip in /etc/hosts - quitting"
          return 0
        else
          echo "Hostname \`$hostname' is in /etc/hosts ($foundip), but is wrong!"
          sed -i.bak "s|^$foundip[[:space:]]*\($hostname[[:space:]]*.*\)$|$new_ip_address \1|" /etc/hosts
        fi
      else
        echo "Hostname \`$hostname' not found in /etc/hosts, adding..."
        echo "$new_ip_address $hostname" >> /etc/hosts
      fi
    
      # if we got here, /etc/hosts was changed, so restart dnsmasq
      /sbin/service dnsmasq restart
      return $?
    }
    
    test_config > /tmp/dhclient-script.log 2>&1 || exit 1
    
    exit 0
    you'll notice that for convenience, i'm writing all STDOUT/STDERR generated by the script to a log file (/tmp/dhclient-script.log) for debugging purposes.

    There might very well be a way to do this updating of /etc/hosts directly from dnsmasq, btw...i don't know. i'm not very up to snuff on it - i use it for the bare minimum, but this solution works for me.

    For Step 3:

    on all clients, just put the ip address of your lic server in /etc/resolv.conf like this:

    Code:
    nameserver 10.1.1.1
    use the actual ip address of your lic server, not my example ip.

  10. #9
    Banned
    Join Date
    Aug 2013
    Posts
    0
    This is really useful thread. thanks for sharing your valuable information with me.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •