LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (http://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Addressing a machine in a DHCP environment (http://www.linuxquestions.org/questions/linux-networking-3/addressing-a-machine-in-a-dhcp-environment-680369/)

Quakeboy02 10-31-2008 07:11 PM

Addressing a machine in a DHCP environment
 
I've got a couple of Linux machines, a Windows XP machine, and my daughter's Mac here at the house. We get our IPs from an AT&T router/gateway, and of course they're always the same IPs; except when I go experimenting with bridging etc. So, my question is: How can I address all these DHCP clients by name, so that I don't have to just go look to see what address they've gotten? Would I somehow use Windows networking to get to it? Is there some way to tell the DHCP server what my machines names are? What am I missing about a DHCP environment?

Added:
As an example of what I want, suppose I want to rsync to one of the machines. What do I type if I don't want to go take a look a the machine to see what it's address is, but I know it's name?

win32sux 10-31-2008 08:18 PM

One way to approach this could be to forget the DHCP server and just give all the boxes a secondary static IP. Then in the /etc/hosts files you put whatever names you want for the boxes like linux1.example.net, linux2.example.net, windows.example.net, mac.example.net, etc. The /etc/hosts file might look like:
Code:

192.168.1.101 linux1.example.net
192.168.1.102 linux2.example.net
192.168.1.103 windows.example.net
192.168.1.104 mac.example.net


Quakeboy02 10-31-2008 08:28 PM

Yeah, I understand that, but then I have to replicate the /etc/hosts file among all my machines, which of course is why we have DNS. I have no intention of setting up a private DNS for four machines.

Is there a way through a shell script that I could use windows networking to get an ip for a machine in a windows workgroup? example:
Code:

rsync -av quakeboy@`myscript hedgehog`:/fromsomewhere /tosomewhere

win32sux 10-31-2008 08:48 PM

Quote:

Originally Posted by Quakeboy02 (Post 3327808)
Yeah, I understand that, but then I have to replicate the /etc/hosts file among all my machines

Which on four machines would take like two minutes to set and forget.

Quote:

I have no intention of setting up a private DNS for four machines.
Which is why I figured using /etc/hosts instead might be something you would be interested in.

I see now that you're not, that's fine.

Quote:

Is there a way through a shell script that I could use windows networking to get an ip for a machine in a windows workgroup? example:
Code:

rsync -av quakeboy@`myscript hedgehog`:/fromsomewhere /tosomewhere

I'll stand back and let someone familiar with Windows networks answer that.

Regarding the OP, do you know what DHCP daemon the device runs? Knowing that can help someone tell you how to get client IDs to work with it so that your boxes always get the same hostname regardless of IP. BTW, is it giving you public or private IPs?

Quakeboy02 10-31-2008 08:58 PM

Quote:

Regarding the OP, do you know what DHCP daemon the device runs? Knowing that can help someone tell you how to get client IDs to work with it so that your boxes always get the same hostname regardless of IP. BTW, is it giving you public or private IPs?
The device itself? No. All I know about it is that it's a 3800HGV-B. It's giving me private IPs in the 192.168.1.x subnet. Oh, and my daughter has some gaming doohickies attached, so we'd need the DHCP in any case, I think.

win32sux 10-31-2008 09:14 PM

Quote:

Originally Posted by Quakeboy02 (Post 3327820)
The device itself? No. All I know about it is that it's a 3800HGV-B. It's giving me private IPs in the 192.168.1.x subnet. Oh, and my daughter has some gaming doohickies attached, so we'd need the DHCP in any case, I think.

Does it have a DNS daemon on it? What gateway address does its DHCP give you? Is the IP it gives you for DNS servers (look in your /etc/resolv.conf) the same as the gateway address or is it like ISP nameservers? Do you have a control panel on this device?

Telling a DHCP server to always give you a certain client IP and/or hostname should be really easy (unless your ISP has restricted administration options on the device, or if it lacks them). But if the device doesn't come with a DNS daemon then you're gonna have to bind the hostname to the IPs in some other way, such as installing dnsmasq or something.

Quakeboy02 10-31-2008 09:23 PM

I always get the same IP unless I fool it with something I have going on here, such as turning off the wireless card and plugging into a wireless bridge. We wanted to backup some 35GB of data from my daughter's Mac and via wireless just wasn't cutting it, so I strung a wire and then tried to route through her bridge. Other things like that tend to change my IP on this machine. We don't do that stuff on the others so they're stable. I don't see any way into the device, itself. There are some maintenance items when I point firefox at it, but I don't really want to try to get into the thing.

BTW, I've got dbndns (debian vsn of djbdns) running on my Linux machines. I don't try to tell my daughter what to do on her Mac ;), and the XP box is just turned on to serve the printers in the other room. Oh, and the reason I don't want to run DNS is because I'd be compelled to leave one or two machines running to serve it. Not such a good limitation in a home environment.

I'll have to research how to get the IP for a samba device. Maybe there's an answer there.

win32sux 10-31-2008 09:29 PM

Have you considered buying something like a WRT54G? I think they're like less than 40 bucks now and you can install a nice firmware GNU/Linux distro on it (Tomato, for example) which will let you handle all of this stuff for your network with great convenience. I think even the stock firmware does what you want.

Quakeboy02 10-31-2008 10:09 PM

I just found "nmblookup" and it kind of does what I want, but the output is noisy. Maybe I could do some awk magic on it and clean it up enough to use.
Code:

nmblookup -B -L hedgehog
returns:

Code:

querying hedgehog on 192.168.0.255
querying hedgehog on 192.168.1.255
192.168.1.69 hedgehog<00>


win32sux 10-31-2008 10:10 PM

What are trying to get it to look like?

Like this:
Code:

192.168.1.69 hedgehog
?

If so, this would do it:
Code:

nmblookup -B -L hedgehog | tail -n 1 | awk '{print $2 $1}' | awk -F"<00>" '{print $2 " " $1}'
BTW, why do you ignore so many of the questions I've asked you?

Quakeboy02 10-31-2008 10:16 PM

I just want a script that I can enter the samba machine name and get the ip address out. If the machine isn't connected or turned on, I suppose null would be appropriate. What I was thinking of was to be able to rsync without having to remember what the ip address was. Something like this:
Code:

rsync -av quakeboy@`myscript hedgehog`:/fromhere  /tothere
would be seen as:
Code:

rsync -av quakeboy@192.168.1.69:/fromhere  /tothere

win32sux 10-31-2008 10:23 PM

Replace the "hedgehog" in the command I posted with a $1 and stick it in a text file.

Edit the awk part so that only the IP is output.
Code:

#!/bin/sh
nmblookup -B -L $1 | tail -n 1 | awk '{print $1}'

Now the nmblookup will be done for whatever you pass as an argument.

Quakeboy02 10-31-2008 10:32 PM

Quote:

BTW, why do you ignore so many of the questions I've asked you?
Sorry, I guess I missed a couple. Didn't mean to. If you're referring to the WRT54G, I started to answer that, but then got sidetracked and never got back to it. I've got a WGT624 here, and I'm waiting for OpenWGT to get around to it.

BTW, I now see that you posted the answer already, but I just didn't see it on the page. Did I forget to scroll down? Dang. Sorry about that.

win32sux 10-31-2008 10:34 PM

Cool, let me know if the script works.

Quakeboy02 10-31-2008 10:37 PM

Quote:

Originally Posted by win32sux (Post 3327879)
Cool, let me know if the script works.

Sweet! I'll have to figure out whether I need to do something different for hosts that aren't there or are typed wrong. But, it gives "name_query" in those cases, so that'll probably work well enough.

Thanks again!

Added:
Yes it works. :)


All times are GMT -5. The time now is 08:40 AM.