Linux – Debian/Ubuntu Linux: fixed IP when DHCP fails

debiandhcpiplinuxubuntu-16.04

I'm looking for a solution on this problem:

I have this small industrial pc called UP Board, running some Linux Debian/Ubuntu adopted version:

4.10.0-9-upboard #11~16.04.1 SMP Wed Oct 25 17:10:46 IST 2017 x86_64 x86_64 x86_64 GNU/Linux
(I believe it's Ubuntu 16.04)

With this lil machine I'm offering some services within customer networks.
And here comes the challenge…

Some of the customers run a DHCP server in their network, others don't. Since I am in different networks very often, and usually do not know the network settings regarding DHCP in advance, I had this idea:
How about sending DHCP request on the network and waiting for response. When now response is received from DHCP server within a time frame, configure the respective network interface with a fixed IP and netmask. Then I'd be able to reach the box from my laptop and connect to set the right IP/NM of the network. So simply do some auto configuration of the interface just as Microsoft does it in Windows environment with these obscure 169.254.x.y addresses.

Since my device does not have any screen, manual configuration is not an option here.

Any ideas to develop such auto config feature are really appreciated!

Regards
Olaf

P.S.: I've searched Google with different terms but did not get any valuable results. Hints what to search for are also welcome…

Best Answer

IMHO you can easily create a bridged interface with a static IP address and configure your Ethernet with DHCP

sudo apt install bridge-utils

Edit /etc/network/intefaces:

auto enp0s3 <---- change this to whatever your interface name is
iface enp0s3 inet dhcp

auto br0
iface br0 inet static
  address 10.10.10.10 <--- set this to whatever address you want
  netmask 255.255.255.0
  bridge_ports enp0s3

This way you can always connect to you box via 10.10.10.10 and the physical interface will get a dynamic address if a DHCP server is present

Related Topic