LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Hardware (https://www.linuxquestions.org/questions/linux-hardware-18/)
-   -   Setting a static IP address, but dynamically obtaining DNS config from a router (https://www.linuxquestions.org/questions/linux-hardware-18/setting-a-static-ip-address-but-dynamically-obtaining-dns-config-from-a-router-671955/)

bgoodr 09-24-2008 12:15 AM

Setting a static IP address, but dynamically obtaining DNS config from a router
 
I am trying to do something similar as indicated at post 1187648, but when I do so, I can no longer resolve hosts. Is there a way to enable some of DHCP where I can have a static IP address, but everything else such as the DNS servers are automatically obtained from the gateway (which is my Linksys router)?

For example, when I had this in my /etc/network/interfaces file:

Code:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth1

###iface eth1 inet dhcp
iface eth1 inet static
  address 192.168.1.2
  netmask 255.255.255.0
  gateway 192.168.1.1

ifconfig shows that eth1's ip address is 192.168.1.2 as it should be, but ping www.google.com says unknown host. As far as I know, my router usually sets up the DNS servers for when only "iface eth1 inet dhcp" is in the /etc/network/interfaces file. I want Linux to still get DNS set properly from the gateway, but leave the IP address alone. Is there any way to do that?

Thanks,
bgoodr

jay73 09-24-2008 12:20 AM

You need to put your nameserver IP(s) in /etc/resolv.conf.

billymayday 09-24-2008 12:57 AM

If you really want a static IP, you may be able to tell the router to assign a certain IP based on the MAC address of your NIC.

ifconfig eth1

will give you the MAC (it calls it the HWaddr)

bgoodr 09-28-2008 12:33 PM

Quote:

Originally Posted by jay73 (Post 3289925)
You need to put your nameserver IP(s) in /etc/resolv.conf.

Thanks. That is what I was trying to avoid: I wanted the "system" (Linux plus possibly the router's configuration) to figure out what those name servers are by way of DHCP, but leave the static IP address alone.

But after some tinkering, you are right: In my situation, I want that router to forward certain protocols only, and the only way it can do that without the router changing the target IP address dynamically is if I configure my target machine to not request a possibly varying IP address by way of DHCP.

Quote:

Originally Posted by billymayday (Post 3289955)
If you really want a static IP, you may be able to tell the router to assign a certain IP based on the MAC address of your NIC.

That would be ideal, and seemed the least invasive of the approaches. However, I searched twice through all of the configuration menus for my router, and could not find any such method to assign by MAC address. So I'm back to jay73's suggestion of having to manually modify /etc/resolv.conf with the nameservers.

Thanks to the both of you for your help!

bgoodr


All times are GMT -5. The time now is 12:19 AM.