Is there a way to set default eth0 setup in linux. I know I can give it a default static IP at boot up with sudo ip route add default via dev eth0. Is there a way to change it to DHCP at bootup. AND if it's in DHCP but I do NOT have my ethernet cable connected to the network, I want it to be set to an IP address so that it always has a way to be able to connect to it at bootup without any extra commands from the terminal. So.... a default IP address if a DHCP address is not found. Is this possible? and how?

Backstory: I'm writing a c++ console application that is listening from a socket. The end user connects to my linux device (via Windows PC usually) and can then send commands. Everything work as of now, but I want the end user to have the option of setting the default to static of dynamic at startup. They can only connect to the application if there is an IP address present. I want to add this just in case the user forgets to connect to the server if it is in dhcp mode at startup.

  • Related SO Q&A: stackoverflow.com/q/12727175/1531971 – jdv Nov 16 '18 at 18:07
  • Thanks! But is there a way to have dhcp as default if I've already made static my default? A toggle between both that I can add to my code. For static default, I send the command in my question. For dynamic, is there a terminal command to do the same? – miceandmon Nov 16 '18 at 18:28
  • There is a fixed Ask Ubuntu networking page somewhere that may answer that. – jdv Nov 16 '18 at 18:32
  • oh ok. Got it. Thank you!! – miceandmon Nov 16 '18 at 18:48
  • If you find an actual answer to your question (or if it is answered elsewhere) make sure circle back here and let us know so future folks can benefit... – jdv Nov 16 '18 at 19:20

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.