Setting a static IP address, but dynamically obtaining DNS config from a router
Linux - HardwareThis forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.