How can I switch seamlessly between wired and wireless network?

2

My laptop is usually connected via wifi (old T61 with Intel WM3945ABG). For most of my work, this is sufficient. Now and then, I'd like to hook up to my fine 1GB wired ethernet. But if I do it naively, nfs mounts start to hang. (If I unmount all nfs before the change, all is fine).

For example, my backup starts via anacron. This involes mounting the backup drive on my server via nfs4. Most likely, I'm on wifi if this happens. If I now plug in my ethernet cable, all access to the backup drive result in a uninterruptible sleep. As the backup takes quite some time (slow wifi, remember?), I'm not able to unmount and remount the backup drive.

This involes blocked dialogues and shells (maybe they scan all mountpoints when opened, I don't know).

I'm with Linux since Kernel 2.0.2 and to be honest, this is the /only/ thing with Linux that really drives me crazy, because I'm not able to solve it.

Is there a way to transparently exchange wired and wireless networking?

Oh, some missing facts: Currently, I'm using WICD, but I tried NetworkManager before. I'm considering a systemd-only approach...

% /sbin/iwconfig wlan0

wlan0     IEEE 802.11  ESSID:"the-grue"
      Mode:Managed  Frequency:2.422 GHz  Access Point: 64:70:02:A2:67:DE
      Bit Rate=54 Mb/s   Tx-Power=15 dBm
      Retry short limit:7   RTS thr:off   Fragment thr:off
      Power Management:off
      Link Quality=70/70  Signal level=-33 dBm
      Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
      Tx excessive retries:0  Invalid misc:476   Missed beacon:0

% mount | grep nfs
zem:/backup on /media/backup type nfs4
(rw,relatime,vers=4.1,rsize=65536,wsize=65536,namlen=255,soft,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.178.63,local_lock=none,addr=192.168.178.2)

Both networks use the same IP and so on...

Please tell me, if you need further information!

Markus

Posted 2017-02-07T17:40:25.497

Reputation: 123

Answers

1

Without some help on the other side, either where your WLAN and GB LAN converge (i.e. your home router), or where the other communication point is, you can't.

And that's really not a Linux issue, it's because networking protocols are the way they are (for historical reasons): Both TCP and UDP don't support fail-over multihoming, i.e. having several interfaces with different IP addresses at one end that can all be used equivalently.

That said, there are a few ways to make something like this work, but none of them are easy, I haven't tried to implement one of them myself, and it will take considerable effort to make them work, if they work at all:

1) Instead of TCP and UDP, use a protocol that allows fail-over multihoming, for example SCTP. While SCTP is natively available in the Linux kernel, not many use it. So you'll have to find an application that does what you want and supports SCTP on both ends, and good luck with that. Or you'll have to modify existing applications like NFS or your backup to support SCTP, and again, good luck with that.

Edit: I found there is a wrapper command called withsctp that makes the wrapped application use SCTP instead of TCP. I tested with nc and socat with two pairs of veth connections to a network namespaces, and failover multihoming works out of the box: shutting down the pair where the connection was initiated doesn't interrupt transmission, which gets moved to the other pair. But it looks like both network interfaces need to be visible when the connection is established, as the available addresses are part of the SCTP handshake.

I didn't test, but this may work for your backup program, or FUSE remote filesystems like SSHFS, or even kernel filesystems like NFS.

2) You can bond several interfaces together, see linux/Documentation/networking/bonding.txt in the kernel sources. This is really just meant to bond e.g. parallel LAN connections in a datacenter. You'll need to do this on both sides, e.g. your PC and your router (which means you might need to recompile the Linux kernel of your firmware for the router), and you'll have to make sure both interfaces are reasonably static (esp. WLAN). If you get this work, I'd be interested in the details.

3) You can try to setup the router so it gives both your WLAN and your LAN interface exactly the same IP address, and disables your WLAN interface as soon as it sees the LAN. That will require quite a bit of fiddling with the router internals, and again, if you get this work, I'd be interested in the details.

There are probably other, equally obscure methods. Writing a script that unmounts/remounts NFS, and checks you're not in the middle of a backup before activating the LAN interface might be easier.

dirkt

Posted 2017-02-07T17:40:25.497

Reputation: 11 627

I see, and thank you very much for your explantion and advice. But there's one thing that I still don't understand, unfortunately it sounds like flamebait which it certainliy isn't: At work, I have a windows 7 laptop in a docking station. Several shares are mounted all the time. When I remove my laptop from the docking station and thus switch from wired to wireless, I notice no problem at all. Since you said "And that's really not a Linux issue", what is the difference? Should I use CIFS instead of NFS? – Markus – 2017-02-08T12:48:32.560

Yes, CIFS uses a very different protocol from NFS (lots of broadcasts, a master who coordinates things, Netbios on top of IP, etc. instead of plain TCP) After all, NFS was made for hosts that have static IP addresses. I haven't tried CIFS on Linux with one host changing IP addresses, but I wouldn't be surprised if it worked out of the box. There are also other, more Unix specific distributed FS which might also work (e.g. AFS).

– dirkt – 2017-02-08T13:52:54.417

Edit: Explained withsctp wrapper. BTW, I do appreciate upvotes. :-) – dirkt – 2017-02-09T09:31:35.517

Thanks again - I'll have a look at withsctp! I upvoted your post, but don't have enough reputation to be counted immediately... – Markus – 2017-02-15T13:30:20.650