Set preference for Wifi over Ethernet

I am trying to create a NAS on my RaspberryPi 3B+. I have installed osmc on my Raspberry Pi and connected it to my main router through wifi. Upto this point everything works fine. Now when I connect my NAS drive (Mybook Live) to my ethernet port in Raspberry Pi and reboot then osmc waits for the network to configure. Since my ethernet port gets connected first the Wifi access to my main router is lost. So I am unable to access my RPI from the other computers in the network. Is there a way to enable both the wifi as well as the ethernet or to set a preference for connecting over wifi first and then to the LAN Port

Thanks in advance for any help

No, by default the network stack of OSMC is designed to switch between Wifi and Ethernet as soon as Ethernet is available.

You could check Tethering or other special configs but that would be quite some work. But if you have decent Wifi why not conntect the Mybook Live directly to your main router?

The problem is my router is in a different room and have accessibility issues. Further I have a mix of USB based external hard drive and NAS like MyBook Live which I cannot connect it to my router. Hence I was planning to use my RPI as a media and file server.

Well then you would need to check if one of the existing Tethering options fits your solution or need to read up on internet about connman (the network manager of OSMC) how to configure different technologies.

Now I am able to get my NAS working in this configuration. The only problem is first I have to boot osmc without the ethernet cable so that it connects to wifi and then once it is booted I connect my NAS cable to the ethernet port. This way I am able to get the things working.

Maybe as suggested by you I will read the connman details to see if I can set the priority.

One way suggested is to disable the ethernet programmatically using connmanctl disable ethernet and then after the wifi is up enable it. Anyone can help on how to achieve this.

While acknowledging the reasons you have outlined, I would still suggest that this approach [placing a NAS on the ethernet port] is mistaken and, as a result, you’re going to have to jump through multiple hoops to overcome various issues that will arise.

Just as a FYI, I’m able to get both ethernet and WiFi working simultaneously on my Pi3 after a reboot:

Last login: Mon Apr 20 10:33:30 2020 from
osmc@osmc:~$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast
        inet6 fe80::ba27:ebff:fe00:bef9  prefixlen 64  scopeid 0x20<link>
        ether b8:27:eb:00:be:f9  txqueuelen 1000  (Ethernet)
        RX packets 112863  bytes 139879586 (133.3 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72133  bytes 16186655 (15.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet  netmask
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=-28605<UP,BROADCAST,RUNNING,MULTICAST,DYNAMIC>  mtu 1500
        inet  netmask  broadcast
        ether b8:27:eb:55:eb:ac  txqueuelen 1000  (Ethernet)
        RX packets 7  bytes 1133 (1.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 18  bytes 4735 (4.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Here’s my connman.conf:

osmc@osmc:~$ cat /etc/connman.conf 

So, as you can see, it is possible to get the two interfaces working together at the same time. Your problem might be something to do with the NAS getting a link-local IP address (169.254.x.x), which can sometimes take a while. AFAIK, a link-local IP address will be randomly selected within the 169.254.x.x range, creating a further hoop to jump through…

Yes. You are right. I have a local link IP address starting with 169.254.x.x for the eth0 port. How did you get the IP address with 192.168.x.x for the eth0 port in your case. Is there any special settings to make.

I have the same /etc/connman.conf as yours.

Thanks in advance for your help

Finally I was able to solve by changing the order for PreferredTechnologies in /etc/connman.conf file. Now the file reads as


This solved my problem, but I still would like to know how I could set the ip address in the same range as the router instead of local link IP address.

You can create a bridged interface (br0) and bind the physicals to it. Good luck :slight_smile:

There is no way I can connect a bridged interface using connman. I tried googling around, but no luck. It would be great if you can provide me a pointer on creating the bridged interface in osmc

It’s those hoops again. I don’t think you’ll have much success with bridging ethernet to WiFi in client mode – though if you do succeed, let us know how you did it. (Any bridging would almost certainly require the bridge-utils package to be installed.)

If you do find the (169.254) IP address of the NAS, what do you propose to do with it that couldn’t be done if it were connected to the router?

This seems a bit laborious. Could you not connect the drive to the router using power line adapters?

EDIT: Or even buy a cheap 4-port Ethernet switch and connect the Pi and the drive directly to the switch, and then the switch to the router via power line adapters - that gives you full speed Ethernet between the drive and the Pi (and indeed between the drive and any other device you connect to the switch).

I was able to mount the NAS drives in OSMC using NetBios ID and not the IP address. Once I have mounted it I am able to make a samba share and use it in other places. Now the setup is working fine.

Yes. I can do that and I was doing it earlier with some spare router, but the problem is I need to deal with multiple power adapters one for Pi and one for router, one each for the NAS etc., So I wanted to get rid of the router and the associated power adapters. With Pi I thought I could achieve both my objective.

Now with this configuration I am able to connect my NAS to Pi and also make it as a Upnp/DLNA server and I am able to access my external USB drive and NAS anywhere in the network.

Rather than bridge I have used dnsmasq and iptables to achieve the same effect.

Thanks for all your inputs

1 Like

Would you like to share what you did, for the benefit of the community?

Yes, Definitely I would like to do it.

Should I add it in this thread itself or is it possible to add it in the wiki.

Since it’s rather specific to your situation, I’d suggest you add it to this thread.

  1. Update using
    sudo apt-get update

  2. Disabled tethering by editing the connman.conf. I had removed the line

  3. Modified the preferred technologies order to start wifi first and then the ethernet

    This is my modified connman.conf file

  1. Get the Connman service name for the ethernet port using
    sudo connmanctl services
*AO srinivasanb7         wifi_b827ebb6f691_7372696e69766173616e6237_managed_psk
*AR Wired                ethernet_b827ebe3a3c4_cable

The ethernet service is shown by the line Keyword *AR at the beginning of the line. This service name should be used in step 5 to set the static IP

  1. Set a static IP address to the ethernet port using the following command

    sudo connmanctl config ethernet_b827ebe3a3c4_cable --ipv4 manual

  2. Install dnsmasq using the following command
    sudo apt-get install dnsmasq

  3. Copy the original dnsmasq.conf file before making any modification
    sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig

  4. Edit the dnsmasq.conf
    sudo nano /etc/dnsmasq.conf

  5. Clear the contents of /etc/dnsmasq.conf and add the following lines to the file

    interface=eth0 # Use interface eth0
    listen-address= # Specify the address to listen on
    bind-interfaces # Bind to the interface
    server= # Use Google DNS
    domain-needed # Don’t forward short names
    bogus-priv # Drop the non-routed address spaces.
    dhcp-range=,,12h # IP range and lease time

    Do not add the comments in your file(# and the following character). They are given here for explanation only.
    Note: Sometimes you may have and issue in starting the dnsmasq service as the eth0 may not be available. In such a scenario remove the third line and reboot.

  6. Check the syntax of the dnsmasq.conf file using
    dnsmasq --test

    If it is ok you can proceed to the next steps.

  7. Configure RPI’s firewall to forward all the eth0 connection our wlan0 connection. To do this we must enable ipv4p IP forwarding by editing sysctl.conf
    sudo nano /etc/sysctl.conf

  8. Within this file you need to find the following line and edit it
    Replace with:

  9. Run the following command to enable port forwarding immediately without requiring a reboot
    sudo sh -c “echo 1 > /proc/sys/net/ipv4/ip_forward”

  10. Reconfigure the firewall so that traffic is forwarded from eth0 port to wlan0 port

    sudo iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
    sudo iptables -A FORWARD -i wlan0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
    sudo iptables -A FORWARD -i eth0 -o wlan0 -j ACCEPT

  11. Save the iptables using
    sudo sh -c “iptables-save > /etc/iptables.ipv4.nat”

    If you do not do this the iptables will be flushed on every reboot

  12. Reload the saved iptables file on every reboot. For this edit the /etc/rc.local file using
    sudo nano /etc/rc.local

  13. Add the line below in the /etc/rc.local file. Make sure this line appears above exit 0. This line basically reads the settings out of our iptables.ipv4.nat file and loads them into the iptables.

    exit 0
    Add Above:
    iptables-restore < /etc/iptables.ipv4.nat

    Save the file and exit from nano by pressing Ctrl+X the pressing Y and then Enter

  14. Now start the dnsmasq service using
    sudo systemctl start dnsmasq

  15. Finally reboot the system
    sudo reboot

With this you should have a fully operational Wifi Bridge.


1 Like