View previous topic :: View next topic |
Author |
Message |
solamour l33t
Joined: 21 Dec 2004 Posts: 726 Location: San Diego, CA
|
Posted: Sat Dec 22, 2007 2:03 am Post subject: [Solved] How to access DHCP client with host name, not IP? |
|
|
My test box at work gets its IP dynamically via the DHCP server, and whenever I restart it (I restart it rather frequently due to the nature of the testing), it gets a new, most of the time, different IP.
I'd like to access this test box using its host name (e.g. "testbox"), not the numeric IP address (e.g. "10.xxx.xxx.xxx"). I get absolutely no help from the IT department, because as far as they are concerned, it's not their problem.
Here is what I've been using. It works, but I'm sure there is a better way to handle it.
1) Whenever the test box restarts and gets a new IP, it saves its IP address in a plain text file and uploads it to a shared depository.
2) Before I connect to the text box, I fetch the IP address text file stored in the shared depository and replace the entry in "/etc/hosts" with it.
__
sol
Last edited by solamour on Tue Jan 01, 2008 1:27 am; edited 1 time in total |
|
Back to top |
|
|
scratch n00b
Joined: 21 Dec 2007 Posts: 10 Location: Iowa
|
Posted: Sat Dec 22, 2007 2:17 am Post subject: This could be scripted |
|
|
If you absolutely need to bypass IT you could cron that - if a ping to the hostname fails then automatically reup the hosts file.
But arguably your IT should have their DHCP server keeping DNS up to date so you never need to deal with this.
Sorry that you're stuck with that IT dept! _________________ EOL |
|
Back to top |
|
|
cyrillic Watchman
Joined: 19 Feb 2003 Posts: 7313 Location: Groton, Massachusetts USA
|
Posted: Sat Dec 22, 2007 4:26 am Post subject: |
|
|
If you can't convince your IT department to get a DNS server that works, then you could try multicast DNS instead.
Code: | # emerge mDNSResponder
# rc-update add mdnsd default
# rc |
You can read more about how this works here :
http://developer.apple.com/networking/bonjour/index.html
EDIT : You also need to add "mdns" to your /etc/nsswitch.conf so that it looks like this.
Code: | hosts: files mdns dns |
Last edited by cyrillic on Sun Dec 23, 2007 3:52 am; edited 1 time in total |
|
Back to top |
|
|
padoor Advocate
Joined: 30 Dec 2005 Posts: 4185 Location: india
|
Posted: Sat Dec 22, 2007 5:02 am Post subject: |
|
|
default gateway should remain the same for any dhcp
ping the gateway
in the /etc/resolv.conf you can put search dhcp server address name
mostly the dns will remain the same.
i have almost always got the same ip asigned every time i start the dhcp.
now i have got the ip address and dns specified. no more dhcp now
if the mac address remains the same most times the same ip will be given for regular user. _________________ reach out a little bit more to catch it (DON'T BELIEVE the advocate part under my user name) |
|
Back to top |
|
|
solamour l33t
Joined: 21 Dec 2004 Posts: 726 Location: San Diego, CA
|
Posted: Mon Dec 31, 2007 11:05 pm Post subject: |
|
|
The test box does get the same IP most of the time, but when it is off for a while and boots up, it usually gets a new IP, which doesn't make my job easier.
mDNSResponder does seem promising, so I installed it on both the test box and my main machine (and added the following as described in the installation note).
Code: | /etc/nsswitch.conf
hosts: files mdns dns |
But they still don't know the other exists, and I'm not sure where to go from here. I'd appreciate any help.
__
sol |
|
Back to top |
|
|
Malvineous Apprentice
Joined: 20 Oct 2006 Posts: 281 Location: Brisbane, Australia
|
Posted: Tue Jan 01, 2008 12:27 am Post subject: |
|
|
If you're on the same LAN segment you could try giving your box and the test box a static IP as well, e.g. Code: | testbox# ifconfig eth0:1 192.168.0.1
mybox# ifconfig eth0:1 192.168.0.2 |
Then you should be able to access the test box using 192.168.0.1 all the time. Just make sure the IPs are in a different subnet so you don't conflict with any IPs the DHCP server is likely to give out (and hope that your router won't baulk at seeing traffic in an 'illegal' subnet.)
If it won't route other subnets, you could be a bit rough and just choose IPs in the same subnet that aren't in use (you may find DHCP has been configured to only allocate "upper" IPs, e.g. 192.168.0.x where x > 10) because lower IPs are usually reserved for routers and sometimes servers. If this is the case you could try pinging a low IP and if you don't get a response (and 'arp' shows no MAC address for the IP) then you can assign that one to your box as above, and use it as a static IP.
Failing even that, next time you get an IP from DHCP take that one and assign it as a static IP address. DHCP isn't supposed to issue an address if it's in use, so as long as your PC is on 24/7 (except for the brief restarts) DHCP should see that the address is in use and make sure nobody else gets it. There are also DHCP parameters to inform the DHCP server you're using a particular IP (rather than requesting one), so check the manpages if you go down this track to avoid possible issues. |
|
Back to top |
|
|
solamour l33t
Joined: 21 Dec 2004 Posts: 726 Location: San Diego, CA
|
Posted: Tue Jan 01, 2008 1:27 am Post subject: |
|
|
I tried using a different subnet, but it looks like the router doesn't like that. Assigning a static IP seems slightly risky, but heck, I'm not getting any help from the IT people, so I'll try it out for a while and see how it goes. I hope the DHCP server doesn't hand out the IP I picked. Thanks for the suggestions.
__
sol |
|
Back to top |
|
|
cyrillic Watchman
Joined: 19 Feb 2003 Posts: 7313 Location: Groton, Massachusetts USA
|
Posted: Wed Jan 02, 2008 12:56 am Post subject: |
|
|
solamour wrote: | But they still don't know the other exists ... |
Are you using the right domain name ? (.local)
Assuming you have /etc/init.d/mdnsd started on both machines,
and their names are mymachine and testmachine,
you should be able to get this to work.
Code: | # ping testmachine.local
# ping mymachine.local |
|
|
Back to top |
|
|
solamour l33t
Joined: 21 Dec 2004 Posts: 726 Location: San Diego, CA
|
Posted: Fri Jan 04, 2008 9:56 pm Post subject: |
|
|
"ping testmachine.local" indeed works. Good point.
And I just realized that the static IP I chose conflicts with something on the network, so I'd better stick with mDNS. Thanks everyone for taking time to respond.
__
sol |
|
Back to top |
|
|
|