RPI setup two IPs

  • Hi

    I'm running LibreElec on Rasbperry Pi 2

    How can i setup static ip and dhcp simultaneously?

    Most of the time my board is connected to router whre it gets ip by dhcp, but sometimes it is connected directly to PC. In this situation i would like to have static IP.

  • you could do static for wired and dhcp for wireless... or vice versa.

    there might be a way to detect context of connection, or revert to static if dhcp doesn't get negotiated by a certain time.

    perhaps the easiest would be to have your pc run a dhcp server on the interface you're using to access the rpi...

  • LE uses connman which stores network setttings using a unique identifier based on the MAC address of the interface. As the network interface does not change between connections, you are forced to manually change the config to change connection.

    One way to work around this is using a USB Ethernet adaptor. As this will have a different MAC the settings will be cached and to change connection all you need to do is swap the Ethernet cable between ports. It will also support both being active at the same time; which device becomes eth0 will be dependent on kernel probe order but the on-board NIC should always be faster so this is probably not an issue.

    An alternative is (as suggested above) to use WiFi and Ethernet, although here the default behaviour is slightly different. You can have both connections active at the same time, but when Ethernet is connected it always becomes the primary (gateway/routed) connection. This can be changed by copying /etc/connman/main.conf > /storage/.config/connman_main.conf and reordering the PreferredTechnologies line and rebooting.