On my openSUSE 13.2, I have a case to set and get DNS and server addresses. I managed to get the DNS address by parsing /etc/resolv.conf, my concern now is setting DNS and DHCP.

Does changing the addresses requires any other configurations ? I mean is there a way to change only the DNS or DHCP address ?


Yes, you can manually edit both informations.

To modify only your DNS, you should edit the file /etc/resolv.conf and modify the lines which begin with nameserver. Like this (here, it's with google's DNS) :


What do you mean by modifying your DHCP address ? You mean the IP address the DHCP which has been given to you ?

If so, there are two steps :

  • Disable the DHCP to avoid overriding of your parametters
  • Modify the address itself

These depends on your system settings (do you use NetworkManager, on which distribution are you, ...).

EDIT : You cannot set the DHCP server IP (or choose which DHCP server you want), because when you connect to a network and want an address via DHCP, you send a broadcast query.There should be at most one DHCP server in a subnetwork (I don't know what happens if there are more than one and there is a conflict).

  • Thanks for the help, I have openSUSE 13.2. I'm asking because I want to do it programmatically, either by using command line or parsing files. Regarding the DHCP, I need to only set the address of the DHCP server only.
    – 3bdalla
    Mar 5 '15 at 10:03
  • Answer edited for the second part. Can you explain what you mean by "wanting to do //it// programmatically" ? You mean fixing your DNS address ? Mar 5 '15 at 10:22
  • No, I want to do all the above in C as part of an application. Regarding the DHCP, is logical to change it after I connect to a network ?
    – 3bdalla
    Mar 5 '15 at 10:33
  • If you want to change your DNS in C, you should still edit /etc/resolv.conf (fwrite if my C isn't too rusty). I still don't understand what you mean by "changing your DHCP" ? Do you mean changing which DHCP server to use, or the IP address it has given to you ? Mar 5 '15 at 11:09
  • I mean, the PC connected to a network, got an IP address from a DHCP server on address a.b.c.d, Now the PC connected to DHCP server which has address a.b.c.d, now does it make sense to change the DHCP address now after it is connected already to one and took an IP address from it ?
    – 3bdalla
    Mar 5 '15 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.