This is a discussion on How to setup /etc/hosts to lookup DHCP client in the same subnet within the Linux Networking forums, part of the Linux Forums category; Hello, I have two machines (myboxA & myboxB) in the same subnet, and both are assigned IP addresses by a ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello,
I have two machines (myboxA & myboxB) in the same subnet, and both are assigned IP addresses by a DHCP router. MyboxA is installed RedHat 9.2. Since the IP addresses are dynamicly assigned, I'm wondering how to config /etc/hosts (or any other files) in myboxA, to make it connect to myboxB by its name instead of IP address? Thanks. Wonder |
|
|||
|
> Hello,
> > I have two machines (myboxA & myboxB) in the same subnet, and both are > assigned IP addresses by a DHCP router. MyboxA is installed RedHat 9.2. > > Since the IP addresses are dynamicly assigned, I'm wondering how to > config > /etc/hosts (or any other files) in myboxA, to make it connect to myboxB > by > its name instead of IP address? The way I do it is to have my DHCP server tell my DNS server about its leases and hostnames, then configure DNS to try to answer queries from DHCP (as well as /etc/hosts) before resolving from the WAN. This is especially easy to do if you use dnsmasq for your DHCP and DNS servers. dnsmasq is both servers, so DNS automatically knows all of the DHCP leases, and resolves hostnames from them. You're done. Good luck, Andrew. -- To reply by email, change "deadspam.com" to "alumni.utexas.net" |
|
|||
|
Andrew Schulman wrote:
> > The way I do it is to have my DHCP server tell my DNS server about its > leases and hostnames, then configure DNS to try to answer queries from DHCP > (as well as /etc/hosts) before resolving from the WAN. > > This is especially easy to do if you use dnsmasq for your DHCP and DNS > servers. dnsmasq is both servers, so DNS automatically knows all of the > DHCP leases, and resolves hostnames from them. You're done. > > Good luck, > Andrew. > > -- > To reply by email, change "deadspam.com" to "alumni.utexas.net" Andrew, thank you. Actually, I don't have a DNS server in this home network. It's just a Belkin 4-port wireless router, which is DHCP server for the two machines, and it gets the DNS and IP settings automatically from my ISP. So, from my understanding, you don't need to add any lines in /etc/hosts of your myboxA (for example), with the DHCP and DNS configged correctly, am I right? |
|
|||
|
> Andrew Schulman wrote:
> > > > The way I do it is to have my DHCP server tell my DNS server about its > > leases and hostnames, then configure DNS to try to answer queries from DHCP > > (as well as /etc/hosts) before resolving from the WAN. > > > > This is especially easy to do if you use dnsmasq for your DHCP and DNS > > servers. dnsmasq is both servers, so DNS automatically knows all of the > > DHCP leases, and resolves hostnames from them. You're done. > > > > Good luck, > > Andrew. > > > > -- > > To reply by email, change "deadspam.com" to "alumni.utexas.net" > > Andrew, thank you. > > Actually, I don't have a DNS server in this home network. It's just a > Belkin 4-port wireless router, which is DHCP server for the two > machines, and it gets the DNS and IP settings automatically from my > ISP. > > So, from my understanding, you don't need to add any lines in > /etc/hosts of your myboxA (for example), with the DHCP and DNS > configged correctly, am I right? Right. But since you don't have that option with your router, maybe just a simple static setup is best for you. You can configure your router to assign fixed IP addresses to each of your two hosts, and then set up /etc/hosts on each. That will work just fine, although you have to update all of the /etc/hosts files if you ever add hosts to your LAN. If you still want your hosts to get their IP addresses by DHCP (e.g. because they're laptops and you want them to be able to grab IP addresses when you take them on the road), then maybe you can configure your router's DHCP server to assign some fixed IP addresses by DHCP. dnsmasq can do that, and I don't know about the Belkin routers, but the Linksys routers run dnsmasq under the hood. -- To reply by email, change "deadspam.com" to "alumni.utexas.net" |
|
|||
|
Andrew Schulman wrote:
> > Right. But since you don't have that option with your router, maybe just a > simple static setup is best for you. You can configure your router to > assign fixed IP addresses to each of your two hosts, and then set up > /etc/hosts on each. That will work just fine, although you have to update > all of the /etc/hosts files if you ever add hosts to your LAN. > > If you still want your hosts to get their IP addresses by DHCP (e.g. because > they're laptops and you want them to be able to grab IP addresses when you > take them on the road), then maybe you can configure your router's DHCP > server to assign some fixed IP addresses by DHCP. dnsmasq can do that, and > I don't know about the Belkin routers, but the Linksys routers run dnsmasq > under the hood. > > -- > To reply by email, change "deadspam.com" to "alumni.utexas.net" Yeah, as you said, I have to use DHCP on the router, since one of the laptops is always moved. There is no dnsmasq on Belkin routers, it sucks! Fortunately, I find that I can set the lease period on the router to "Forever", to keep the IP addresses "static". Then I can set up /etc/hosts on each as you said. Thanks. |