Welcome! Log In Create A New Profile

Advanced

eth0 and wlan0 on the same lan subnet ?

Posted by DonCharisma 
eth0 and wlan0 on the same lan subnet ?
February 24, 2015 04:36AM
What I was trying to do was to get wlan0 to operate when I unplug eth0. Would be nice to have in the opposite direction too.

I thought it'd be a simple case of setting up eth0 and wlan0 in /etc/network/interfaces with 192.168.1.10 (eth0) and 192.168.1.11 (wlan0) respectively. But it's never that simple, is it ?

When I unplug eth0, wlan0 goes down too. It also seems that pings to wlan0 actually go via eth0.

Has anyone here found a simple solution to this ?

What I'd like to be able to do is to plug in eth0 when I want to transfer files, ie need a fast connection. When I don't I can move the box to a different location, unplugging eth0.

Hours of googling didn't come up with a working solution ... so hoping someone here knows !

Cheers

Don Charisma ... because anything is possible with Charisma

My blog - http://DonCharisma.org
Our commercial site - http://DonCharisma.com
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 08:45AM
You can not have two interfaces in the same machine that belong to the same network.
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 12:45PM
http://forum.doozan.com/read.php?2,17700,17890#msg-17890

Have a look above for explanation why not and a workaround
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 03:45PM
Frederick Grayson Wrote:
-------------------------------------------------------
> You can not have two interfaces in the same
> machine that belong to the same network.
I don't think this is in general true but it looks like the case for dockstar. My "hack," as referred by @Gravelrash, seems the most reliable way that works, from my experience.
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 04:02PM
Are you saying you can have two interfaces active at the same time in the same network in the same machine?
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 04:49PM
Frederick Grayson Wrote:
-------------------------------------------------------
> Are you saying you can have two interfaces active
> at the same time in the same network in the same
> machine?
Why not? For example, Windows PC can certainly do that. I don't this is a restriction on Linux either. For example, I am pretty sure RPi can have both interfaces up at the same time.
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 05:00PM
You're mistaken. And it's both hardware and OS independent.

Plug two network adapters into the same machine and assign them to the same network. You are now in ambiguous configuration. One or the other, or possibly both adapters will not work.

Answer this question: A packet generated by the OS needs to go to another machine on the same network. Which adapter does it go out on? It can't be both.

Google this: "Multiple interfaces on the same subnet"
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 05:09PM
O.K. May be you are right. However, I am always using my Windows PC with two interfaces on the same subnet and have never had any problem (like right now :-)). For RPi, at least I can switching from ethernet to wifi unplug the cable without rebooting it. The problem for Dockstar is that I cannot really do that without using the hacks and restarting it.
Maybe what you said is theoretically true, but at in the PC case, it is not a problem in practice.
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 05:16PM
Kindly explain your configuration in further detail and what tests you have done to show that it works.
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 05:27PM
@Frederick,

Think about this with these plugs: the Pogo Pro V3 and the iConnect both have wifi and ethernet. Their IP are usually dhcp from the same router and on the same subnet.

Gravelrash explained this above.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)



Edited 1 time(s). Last edit at 02/24/2015 05:30PM by bodhi.
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 05:30PM
But not functioning at the same time.
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 05:35PM
Frederick Grayson Wrote:
-------------------------------------------------------
> But not functioning at the same time.

Agree, of course not. The keyword is "functioning". They are "operating" at the same time. And the packet is routed through only one interface. So the issue at hand is: in order to keep wlan0 working when the eth cable is unplugged, we need to tweak the routing table.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 05:39PM
Hi, Bodhi,
Totally agreed.
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 05:39PM
bodhi Wrote:
-------------------------------------------------------
> Frederick Grayson Wrote:
> --------------------------------------------------
> -----
> > But not functioning at the same time.
>
> Agree, of course not.

That point seems to be lost on most.
Re: eth0 and wlan0 on the same lan subnet ?
February 24, 2015 06:24PM
One thing that could be investigated if requiring two or more interfaces in the same machine belonging to the same network at the same time is "bridging interfaces." The bridged interfaces are not numbered but are joined to the numbered interface in the network sense, so both work simultaneously.

Worth a look.
Re: eth0 and wlan0 on the same lan subnet ?
February 25, 2015 11:36AM
i use carp and vrrp on some units and it gets even "better" when you have two interfaces from different machines on the same subnet with there own discrete IP addresses that also share a common one

:) :) Gotta love networking its a minefield and a playground at the same time :) :)

CARP : http://archive09.linux.com/feature/35482
VRRP : http://www.keepalived.org/documentation.html
Re: eth0 and wlan0 on the same lan subnet ?
February 25, 2015 07:56PM
@Gravelrash, thanks my friend, that was helpful ...

As for discussions about whether it's "allowed" or not to have two interfaces on the same box connected to the same subnet ... just meh ! really, I gave a perfectly good explaination of my purpose in my OP ... and Windows handles all of these situations well, as does xfce, gnome and probably just about every other desktop version of Linux ...

ANYHOW ... I've investigated bonding, had to compile a bonding.ko module ... that didn't work, the wlan0 keeps on "deauthing", no idea why, got bored with not finding the answer ... bonding would have been elegant had it worked as there's only one ip address in use.

It's possible there is a solution in bridging, but my networking knowledge already strained ...

So my solution is ... drum roll ...

Call a shell script in the background from rc.local ... the shell script sits there and wakes up every few seconds ... it monitors the status of the wired LAN, if it goes down it switches the default network and gateway to wireless ... if the reverse then it switches default network and gateway to wired.

Here's the shell script - "failover-to-wireless.sh"

#!/bin/bash

# (c) Don Charisma 2015 - Please do give credit and link back to me if you're reusing this script - to
# http://DonCharisma.org and http://DonCharisma.com
# and this post :D

GATEWAY=192.168.1.3
SUBNET=255.255.255.0
NETWORK=192.168.1.0
WIRED=eth0
WIRELESS=wlan0

CURRENT_WIRE_OPERSTATE=up
PREVIOUS_WIRE_OPERSTATE=up

while [ true ] ; do

    CURRENT_WIRE_OPERSTATE=`cat /sys/class/net/$WIRED/operstate`

    echo "Current state : $CURRENT_WIRE_OPERSTATE"
    echo "Previous state : $PREVIOUS_WIRE_OPERSTATE"

    if [[ "${PREVIOUS_WIRE_OPERSTATE}" = "up" && "${CURRENT_WIRE_OPERSTATE}" = "down" ]]
    then
        # when wired network has gone down
       echo "Wired network gone down"

        # “DOWN” the wired network
        route del default $WIRED
        route del -net $NETWORK netmask $SUBNET $WIRED
        # “UP” the wireless network
        route add -net $NETWORK netmask $SUBNET $WIRELESS
        route add default gw $GATEWAY $WIRELESS


    elif [[ "${PREVIOUS_WIRE_OPERSTATE}" = "down" && "${CURRENT_WIRE_OPERSTATE}" = "up" ]]
    then

        # when wired network comes back up
        echo "Wired network is back up"

        # “UP” the wired network
        route add -net $NETWORK netmask $SUBNET $WIRED
        route add default gw $GATEWAY $WIRED
        # “DOWN” the wireless network
        route del default $WIRELESS
        route del -net $NETWORK netmask $SUBNET $WIRELESS

    fi

    PREVIOUS_WIRE_OPERSTATE=$CURRENT_WIRE_OPERSTATE

    sleep 5

done

It's tested as far as I can test, so you're welcome to have a play and break it, or even enhance it if that's possible. Will I be maintaining it or supporting it ? ... not likely !

My /etc/network/interfaces are setup as dhcp, but would work just as well with static ips. I'll be switching to static ones just as soon as I get the chance.

There is also a "carrier" file in /sys/class/net/ that presumably tells whether there's copper in the port or not. I didn't think this was as reliable as the "operstate" so that's what I've used.

The scripting in /etc/networking/interfaces, eg post-up post-down just doesn't work for this purpose ... why? ... because the interface is still "up" when one unplugs the RJ45 connector ... doh ! ... you'd need to ifdown it or physically disconnect the network card in order to put it properly down (I think). Unplugging a USB would do it ...

The echo messages were for debugging .... so unimportant really ... bash if statements, well lets just say they are picky ... so much so that many hours elapsed between starting writing the script and having a working one. But hey-ho, I learnt plenty along the way, so it's all good :D

It's been said before - I'm sure there's a more elegant method to do this. But no one or no where could I find an already working solution.

Cheers

Don Charisma ... because anything is possible with Charisma

My blog - http://DonCharisma.org
Our commercial site - http://DonCharisma.com
Re: eth0 and wlan0 on the same lan subnet ?
February 25, 2015 08:09PM
@Don,

It looks pretty fine and going to work to me. That's all it matters.

As a more elegant solution, iirc, there is one in that you would perform all these routing table logics inside /etc/network/interfaces.

-bodhi
===========================
Forum Wiki
bodhi's corner (buy bodhi a beer)
Re: eth0 and wlan0 on the same lan subnet ?
February 26, 2015 04:30AM
@bodhi, agreed, it's a working and relatively simple solution ... I'm sure it doesn't cater for every scenario, more testing would highlight any changes needed :D ... and it certainly could be enhanced to be more generic ... and so on ...

I tried the /etc/network/interfaces with the post-up / post-down, but unplugging the RJ45 isn't enough for the adapter to be consided "down" ... it still shows in ifconfig and route, as if linux is hoping it'll get plugged back in ... there may be other stanzas in that file that would work, (maybe "operstate-up" and "operstate-down") and I agree that would be a more elegant method. ........ I'm quite happy for some bright spark to do it and post how here - A better solution is a better solution at the end of the day !

Another passing thought was some kind of trigger based on the /sys/class/net file, that automagically did something when the state changed ... but at the moment it's beyond my knowledge :D

Anyway - It works, and provides a solution for A) me and others now and B) searchers later who're trying to do the same thing ...

Cheers

Don Charisma ... because anything is possible with Charisma

My blog - http://DonCharisma.org
Our commercial site - http://DonCharisma.com
Re: eth0 and wlan0 on the same lan subnet ?
February 26, 2015 07:45AM
@Don

there is also the option of using file sysem event monitoring -

http://linuxaria.com/article/incron-cron-inotify?lang=en

i use this when i want to trigger TOR on my TOR box.
Re: eth0 and wlan0 on the same lan subnet ?
April 05, 2016 02:19PM
furriephillips
Re: eth0 and wlan0 on the same lan subnet ?
August 13, 2016 05:09PM
I understand that this is a year-old thread, but I do have both eth0 AND wlan0 working on my Backbox Linux laptop.

Both interfaces are set to DHCP and I've configured my IPFire gateway to automatically assign specific IPs to each interface; 10.0.0.50 (eth0) and 10.0.0.51 (wlan0).

This means my laptop is on either .51, or .50 & .51, simultaneously & works seamlessly in each mode. Outbound traffic just works perfectly, no thought required. Remotely, I can SSH into it, via whichever IP is up and responsive.

There's only one annoyance and it's based around my OCD tendencies. The kernel doesn't much like seeing ARP traffic spanning the interfaces & fills the syslog with this sort of crap (useful if you're being hacked, but annoying, if it's just your config): -

kernel: IPv4: martian source 10.0.0.255 from 10.0.0.51, on dev eth0
kernel: ll header: 00000000: ff ff ff ff ff ff 60 57 18 56 a7 11 08 00        ......`W.V....
kernel: IPv4: martian source 255.255.255.255 from 10.0.0.50, on dev wlan0
kernel: ll header: 00000000: ff ff ff ff ff ff 74 e6 e2 36 ea 6b 08 00        ......t..6.k..
kernel: IPv4: martian source 10.0.0.255 from 10.0.0.10, on dev wlan0
kernel: ll header: 00000000: ff ff ff ff ff ff 00 08 9b d3 15 64 08 00        ...........d..

I can live with that, but it is a trifle annoying.
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: