bacon kitty
Posts: 2
Joined: Fri Jul 28, 2017 9:08 pm

[SOLVED] Prioritize Wifi over Ethernet in Raspbian

Fri Jul 28, 2017 10:15 pm

Hello, Raspberry Pi forums. I'm trying to be as precise as possible. I'm a bit green when it comes to Linux and the Linux CLI, but I'll do my best.

The Problem
It occurred to me that my laptop is using entirely too much power. So, I'm trying to use my Raspberry Pi as a remote Wake-on-LAN server to send a magic packet to my computer. I want to leave it at home and be able to boot it up at will. Therefore, I need a wired connection to the computer and a wireless connection to the Internet since running a cable up the stairs is inconvenient, to say the least. I've established both connections, but the wireless connection to the Internet only seems to work when I unplug the wired connection. I got this to work on my Kali Linux box simply by checking a few boxes in the Kali Linux network manager, but Raspbian doesn't seem to use the same network manager. How do I get my R-Pi to route through my Wifi connection instead of my ethernet when it comes to the Internet?

My Setup
Note: Obviously I can't list everything on my network. I don't think it's possible for any of my other devices to be interfering, but I can provide a list if it is a possibility and needed.

I get Internet from Verizon. This goes through the Verizon gateway router, which is necessary for the Internet to work but is utter trash. I disabled the 2.4 GHz, but the 5Ghz network is still running.

Because that router is a piece of shit and doesn't reach upstairs, I've connected another router through a wired connection. This is a WRT1200AC using the factory firmware. This broadcasts both a 2.5 GHz connection and a 5GHz connection. It's internet comes from an ethernet cable connected from the Verizon router to the WRT1200AC. Both of these routers are downstairs.

Connected to the second router is my laptop and Raspberry Pi. The Pi connects via the 2.4GHz and the laptop though the 5Ghz. The Raspberry Pi is a Raspberry Pi 3 that was just updated yesterday so I have the latest OS installed.

Now, there's a second router. This router is for me to be able to locally work on my other computers and my Raspberry Pi. I disabled the wireless connection so it's just a wired router. Both computers are connected to it.

Supporting documents:
/etc/network/interfaces

Code: Select all

# interfaces(5) file used by ifup(8) and ifdown(8)

# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'

# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

auto lo
iface lo inet loopback

iface eth0 inet manual

allow-hotplug wlan0
iface wlan0 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
/etc/dhcpcd.conf:

Code: Select all

# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU.
# Some interface drivers reset when changing the MTU so disabled by default.
#option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# A hook script is provided to lookup the hostname if not set by the DHCP
# server, but it should not be run by default.
nohook lookup-hostname

ifconfig

Code: Select all

eth0      Link encap:Ethernet  HWaddr b8:27:eb:68:6c:20  
          inet addr:10.0.0.100  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::77c4:e53d:f2c8:6442/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:140 errors:0 dropped:0 overruns:0 frame:0
          TX packets:171 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:10670 (10.4 KiB)  TX bytes:18357 (17.9 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:988 errors:0 dropped:0 overruns:0 frame:0
          TX packets:988 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:236564 (231.0 KiB)  TX bytes:236564 (231.0 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:0f:60:03:cb:b4  
          inet addr:10.240.28.156  Bcast:10.240.28.255  Mask:255.255.255.0
          inet6 addr: fe80::ea6f:722c:a4f0:3f2b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3346 errors:0 dropped:4 overruns:0 frame:0
          TX packets:1331 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:610452 (596.1 KiB)  TX bytes:300299 (293.2 KiB)
route:

Code: Select all

default via 10.0.0.1 dev eth0  metric 202 
default via 10.240.28.35 dev wlan0  metric 303 
10.0.0.0/24 dev eth0  proto kernel  scope link  src 10.0.0.100  metric 202 
10.240.28.0/24 dev wlan0  proto kernel  scope link  src 10.240.28.156  metric 303 
Last edited by bacon kitty on Fri Sep 01, 2017 10:13 pm, edited 1 time in total.

drgeoff
Posts: 9205
Joined: Wed Jan 25, 2012 6:39 pm

Re: Prioritize Wifi over Ethernet in Raspbian

Sat Jul 29, 2017 8:36 am

If you have connected an ethernet cable between a LAN port on the first router and the WAN port on the second router you are making things unnecessarily complex. Instead, use the second router as a switch and Wi-Fi Access Point by running the cable between LAN ports on both routers. (Nothing plugged in to the WAN port of the second router. ) Disable the DHCP server on the second router and if both routers have the same IP address you'll need to change one of them. Any devices you configure with static address should use the parameters of the first router.

The above gives you a single subnet and avoids the double NAT and other issues you will have if the second router is acting as a router.

bacon kitty
Posts: 2
Joined: Fri Jul 28, 2017 9:08 pm

Re: Prioritize Wifi over Ethernet in Raspbian

Sun Jul 30, 2017 4:18 am

I actually worked it by putting the second router into a DMZ on the first router in order to bypass the NAT, although I'll be trying your solution.

However, I just realized I made an error. There's actually 3 routers. One for the Internet, one for the extender, and the wired-only no-internet network for my Raspberry Pi(s) and Linux box.

Milliways
Posts: 386
Joined: Fri Apr 25, 2014 12:18 am
Location: Sydney, Australia

Re: Prioritize Wifi over Ethernet in Raspbian

Sun Jul 30, 2017 7:34 am

You appear to be operating your routers on different networks. You can have as many routers as you like, but you should only have a single DHCP server.

drgeoff
Posts: 9205
Joined: Wed Jan 25, 2012 6:39 pm

Re: Prioritize Wifi over Ethernet in Raspbian

Sun Jul 30, 2017 9:33 am

bacon kitty wrote:
Sun Jul 30, 2017 4:18 am
I actually worked it by putting the second router into a DMZ on the first router in order to bypass the NAT,
With every router I have used, that does not bypass the NAT. The device in the DMZ still has a private IP address.

SurferTim
Posts: 1769
Joined: Sat Sep 14, 2013 9:27 am
Location: Miramar Beach, Florida

Re: Prioritize Wifi over Ethernet in Raspbian

Sun Jul 30, 2017 12:00 pm

Have you tried using a static IP on the ethernet connection and omitting the gateway (routers) setting?

edit: You could also try the metric parameter. Lowest metric has priority.
In /etc/dhcpcd.conf

Code: Select all

interface eth0
metric 300

interface wlan0
metric 200

doppler
Posts: 30
Joined: Mon May 25, 2015 5:53 pm

Re: [SOLVED] Prioritize Wifi over Ethernet in Raspbian

Tue Nov 28, 2017 5:14 pm

Thank-you so much. Exactly what I looking for forever!

Can also confirm works.

pavn varyani
Posts: 1
Joined: Sun Jun 24, 2018 6:07 pm

Re: Prioritize Wifi over Ethernet in Raspbian

Sun Jun 24, 2018 6:09 pm

SurferTim wrote:
Sun Jul 30, 2017 12:00 pm
Have you tried using a static IP on the ethernet connection and omitting the gateway (routers) setting?

edit: You could also try the metric parameter. Lowest metric has priority.
In /etc/dhcpcd.conf

Code: Select all

interface eth0
metric 300

interface wlan0
metric 200
thanks dude u solved my age old problen

Return to “Beginners”