Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: How to set DHCP with static DNS

  1. #1
    Join Date
    Aug 2011
    Beans
    7

    How to set DHCP with static DNS

    Recently, I have encountered a problem when setting my network configuration.
    I want to automatically get an IP address through DHCP at system startup, and this can be done by editing /etc/network/interfaces file, adding
    auto eth0
    iface eth0 inet dhcp
    The problem is that I want to set a static DNS, but DHCP will automatically overwritten /etc/resolv.conf file.
    What should I do?

  2. #2
    Join Date
    Aug 2010
    Beans
    22

    Re: How to set DHCP with static DNS

    If your dhcp server doesn't pass it, then write the dns into /etc/resolv.conf and then
    Code:
    # chattr +i /etc/resolv.conf
    You won't be able to modify that file untill you will remove the "+i" attribute.

  3. #3
    Join Date
    Aug 2011
    Beans
    7

    Re: How to set DHCP with static DNS

    Quote Originally Posted by CyberPingU View Post
    If your dhcp server doesn't pass it, then write the dns into /etc/resolv.conf and then
    Code:
    # chattr +i /etc/resolv.conf
    You won't be able to modify that file untill you will remove the "+i" attribute.
    The problem is that I can get DNS from DHCP, but I don't want that, what I need is static DNS...

  4. #4
    Join Date
    Sep 2007
    Location
    Key Largo, FL
    Beans
    75
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to set DHCP with static DNS

    Quote Originally Posted by feihu View Post
    The problem is that I can get DNS from DHCP, but I don't want that, what I need is static DNS...
    Simpy edit your /etc/network/interfaces file. I used sudo nano /etc/network/interfaces to get this done.

    This is how mine looks:
    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
    auto eth0 
    iface eth0 inet static
            address 209.208.24.242
            netmask 255.255.255.240
            network 209.208.24.240
            broadcast 209.208.24.255
            gateway 209.208.24.241
    Of course, your IP will be far different (this is a public server), and you can get your info by executing ifconfig from a command line. Be sure to restart networking (/etc/init.d/networking restart) for the changes to take effect. Here is how it would look for a private IP range:

    Code:
    auto eth0 
    iface eth0 inet static
            address 192.168.1.XXX
            netmask 255.255.255.0
            network 192.168.1.1
            broadcast 192.168.1.255
            gateway 192.168.1.1
    Just replace the XXX with the IP of your choice.
    Last edited by NetDoc; August 2nd, 2011 at 01:44 PM.
    Pete "NetDoc" Murray
    NetDoc@ScubaBoard.com
    www.ScubaBoard.com
    The World's LARGEST Dive Community

  5. #5
    Join Date
    Aug 2010
    Beans
    22

    Re: How to set DHCP with static DNS

    If you do like this, he will set a static IP, that is what he doesn't want to have, since he wants to use dhcp.

    Anyhow I don't get what you mean by saying you want a static dns.
    Do you want to use an external DNS server that is not the one provided by the dhcp server?
    Or do you want to update your internal DNS so every time you get an IP from the dhcp server the DNS is updated automatically so

    test.domain.eu

    will always point to your PC, whatever your IP is?

  6. #6
    Join Date
    Sep 2007
    Location
    Key Largo, FL
    Beans
    75
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: How to set DHCP with static DNS

    Quote Originally Posted by CyberPingU View Post
    If you do like this, he will set a static IP, that is what he doesn't want to have, since he wants to use dhcp.
    I see what you mean... you can't have your DHCP and eat it too! Or can you?

    You can actually bind multiple IPs to the same device:

    Code:
    auto eth0 eth0:1
    iface eth0 inet dhcp
    iface eth0:1 inet static
            address 192.168.1.XXX
            netmask 255.255.255.0
            network 192.168.1.1
            broadcast 192.168.1.255
            gateway 192.168.1.1
    Again, don't forget to change the XXX to a numeric value from 2 to 254. Also, make sure that 192.168.1 is within your range.
    Last edited by NetDoc; August 2nd, 2011 at 01:57 PM.
    Pete "NetDoc" Murray
    NetDoc@ScubaBoard.com
    www.ScubaBoard.com
    The World's LARGEST Dive Community

  7. #7
    Join Date
    Aug 2010
    Beans
    22

    Re: How to set DHCP with static DNS

    Yes it's true, but this doesn't appear to have anything to do with a DNS...

  8. #8
    Join Date
    Aug 2011
    Beans
    7

    Re: How to set DHCP with static DNS

    Quote Originally Posted by CyberPingU View Post
    If you do like this, he will set a static IP, that is what he doesn't want to have, since he wants to use dhcp.

    Anyhow I don't get what you mean by saying you want a static dns.
    Do you want to use an external DNS server that is not the one provided by the dhcp server?
    Or do you want to update your internal DNS so every time you get an IP from the dhcp server the DNS is updated automatically so

    test.domain.eu

    will always point to your PC, whatever your IP is?

    For example, I can get a DNS from DHCP such as 192.168.0.1,
    but what I want is set DNS to 127.0.0.1.
    since DHCP will automatically overwrite /etc/resolv.conf,
    this cannot be done by simply edit /etc/resolv.conf.

  9. #9
    Join Date
    Aug 2010
    Beans
    22

    Re: How to set DHCP with static DNS

    Quote Originally Posted by feihu View Post
    For example, I can get a DNS from DHCP such as 192.168.0.1,
    but what I want is set DNS to 127.0.0.1.
    since DHCP will automatically overwrite /etc/resolv.conf,
    this cannot be done by simply edit /etc/resolv.conf.
    You have 2 choices:
    - passing 127.0.0.1 as parameter of dhcpd if it's a linuxbox that provides it by adding the line

    Code:
    	option domain-name-servers		127.0.0.1;
    in your dhcpd.conf;
    - by editing by hand /etc/resolv.conf and using the chattr +i like I said before. If you do like this, on next reboot, your /etc/resolv.conf will NOT be overwritten since you used the "immutable" attribute. Not even root can modify it untill you remove that.

  10. #10
    Join Date
    Aug 2005
    Location
    South Carolina, USA
    Beans
    26,047
    Distro
    Ubuntu Development Release

    Re: How to set DHCP with static DNS

    It is so easy to do with a static IP. Why not?
    "Oh, Ubuntu, you are my favorite Linux-based operating system" --Dr. Sheldon Cooper, B.Sc., M.Sc., M.A., Ph.D., Sc.D.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •