Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 14
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,454

    How do I make 2 computers with dhcp addresses talk to each other?


    I'm still playing about with this laptop and you'll probably get a lot of newbie-type questions as a result.

    My computers can ping each other by ip address, but not so far by name. Neither name nor name.localdomain works. And as the addresses are allocated dynamically and are unknown until I check them with ifconfig, that's not very practical.

    The traditional solution would be to put each computer's name and address in the other's /etc/hosts file. When I do this experimentally, it works, but again it isn't a practical solution because the addresses are not constant between sessions.

    I was hoping that my router (which is also my dhcp and dns server) would do the resolving but it doesn't seem to.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  2. #2
    Linux Engineer
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    818
    Hello Hazel,

    You might have to "mac lock" the machines on your router. This is a way of naming the machine and assigning an IP address outside the DHCP range of IPs on the same sub-network. Not all DHCP servers except the desired host name (such as my ISP) and uses an internal generated hostname.

    This change would be done on your router via its web interface.

  3. #3
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Posts
    1,472
    Hi.

    We've been using dnsmasq for a few years, transitioning from /etc/hosts for static addresses to DHCP:
    Code:
    Description-en: Small caching DNS proxy and DHCP/TFTP server
     Dnsmasq is a lightweight, easy to configure, DNS forwarder and DHCP
     server. It is designed to provide DNS and optionally, DHCP, to a
     small network. It can serve the names of local machines which are
     not in the global DNS. The DHCP server integrates with the DNS
     server and allows machines with DHCP-allocated addresses
     to appear in the DNS with names configured either in each host or
     in a central configuration file. Dnsmasq supports static and dynamic
     DHCP leases and BOOTP/TFTP for network booting of diskless machines.
    We have a lot of VMs, so it's useful to be able to combine our old method of /etc/hosts with DHCP. ( We'll convert everything over to this real soon now ) For names that are not in /etc/hosts, it passes along requests to an outside DNS server. We disabled the router DHCP when we fired up dnsmasq.

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Enthusiast sgosnell's Avatar
    Join Date
    Oct 2010
    Location
    Baja Oklahoma
    Posts
    739
    As you can see, there are multiple ways to do this, as with almost anything in Linux. The quick and easy way would probably be to have the router assign static IP addresses to your computers. I do this with printers and other peripherals, so they always show up at the same place. Dnsmasq might do the job also, but I've never used it, and it appears to require slightly more work. Whether it's worth the effort is your call.

  6. #5
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,454
    Another possible solution. After a bit of googling, I wrote this script

    Code:
    #!/bin/bash
    #Script to put littleboy's hostname into bigboy's hosts file
    
    #Find our address
    ipaddr=$(/sbin/ifconfig eth0|grep 'inet addr'|cut -d: -f2|awk '{print $1}')
    
    # Now work out littleboy's address
    bigboy=$(echo $ipaddr|rev|cut -b1-3|rev)
    if [ $bigboy = "100"]; then
    other_address="192.168.2.101"
    else
    other_address="192.168.2.100
    fi
    
    #Write it into /etc/hosts
    sed -i 'littleboy/d' /etc/hosts
    echo "$other_address littleboy" >> /etc/hosts
    exit
    The code for getting bigboy's address was borrowed, the rest is my own. It's a bit of a bodge but it seems to work.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  7. #6
    Linux Engineer
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    818
    The script is a workable solution for only two devices on the network; however, it does not scale well.

    You did not say which "DHCP" client your were using; however, they allow the passing of a host name to the the DHCP server (some honor the host name such as dnsmasq and others do not). I would check to make sure that you are sending a host name in your configuration for the DHCP client.

  8. #7
    Linux Enthusiast sgosnell's Avatar
    Join Date
    Oct 2010
    Location
    Baja Oklahoma
    Posts
    739
    I'm not sure Hazel needs to worry about scaling for her home network. Sometimes doing things the proper way is more trouble than it's worth. Not often, but sometimes, and this may be one of those times. If this solution ceases to work, then it may be time to go another route.

  9. #8
    Linux Engineer
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    818
    Quote Originally Posted by sgosnell View Post
    I'm not sure Hazel needs to worry about scaling for her home network. Sometimes doing things the proper way is more trouble than it's worth. Not often, but sometimes, and this may be one of those times. If this solution ceases to work, then it may be time to go another route.
    My home network has more the 2 computer, it has 4 computers, 4 cell phones, a radio, dvd, and 2 video streamers. At least one of the computers is running virtual machine (bridged) this means that there are at least 12 devices that are allocating DHCP addresses. The script method would make it hard to find the correct IP address with the script. Currently my router is showing 27 dhcp assignments to be active.

  10. #9
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,454
    Quote Originally Posted by alf55 View Post
    My home network has more the 2 computer, it has 4 computers, 4 cell phones, a radio, dvd, and 2 video streamers. At least one of the computers is running virtual machine (bridged) this means that there are at least 12 devices that are allocating DHCP addresses. The script method would make it hard to find the correct IP address with the script. Currently my router is showing 27 dhcp assignments to be active.
    Yours is a typical modern family! I'm always amazed at the number of devices people, especially young people, own these days. But Sgosnell obviously knows me better than you do. I don't own a smart phone or a dvd player, my TV is not Internet-capable, and my old Fujitsu-Siemens computer is just an occasional print server with no network connection. I can't imagine ever having more devices than I do at the moment. Even having a laptop is a novelty for me.

    I did check to make sure that all my systems (Crux, Debian and LFS on Bigboy, and Mint on Littleboy) send their hostnames up to the dhcp server. The problem is that the server doesn't seem to do anything with those names.
    "I'm just a little old lady; don't try to dazzle me with jargon!"
    www.hrussman.entadsl.com

  11. #10
    Linux Guru
    Join Date
    Dec 2013
    Location
    Victoria, B.C. Canada
    Posts
    2,103
    -->
    The router probably won't name serve so you need the names in your hosts file, along with the ip address. As someone has mentioned that means configuring your router to always give the same ip address to those computers. I find it simplest to use what Lynksys routers call DHCP reservation but assigning static IP addresses is another solution.

Posting Permissions

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