# NFS and changing network interface [Solved]

## Nicias

I have a laptop that I often use at my desk. When it is there I use a wired ethernet connection. When I am not at the desk, I use wifi.

I have it setup to turn off the wifi when the ethernet cord is plugged in. I manage this by adding a couple of lines in /etc/ifplugd/ifplugd.action

```
#!/bin/sh

# Copyright 1999-2004 Gentoo Foundation

# Distributed under the terms of the GNU General Public License v2

#

# Gentoo-specific ifplugd.action

#

# This file gets called by ifplugd when it wants to bring an interface

# up or down.

#

if grep -q initng /proc/1/cmdline 

then

    EXEC="/sbin/ngc"

    INITNG="yes"

else

    EXEC="/etc/init.d/net.$1"

    INITNG="no"

fi

case "$2" in

    up)

   if [ "${INITNG}" = "yes" ]

   then

       ARGS="-u net/$1"

   else

       /etc/init.d/net.wifi --quiet stop   # this line is new

       ARGS="--quiet start"

   fi

   ;;

    down)

   if [ "${INITNG}" = "yes" ]

   then

       ARGS="-d net/$1"

   else

       ARGS="--quiet stop"

       /etc/init.d/net.wifi --quiet start   # this line is new

   fi

   ;;

    *)

   echo "$0: wrong arguments" >&2

   echo "Call with <interface> <up|down>" >&2

   exit 1

   ;;

esac

export IN_BACKGROUND=true

if [ -x "${EXEC}" ]

then

    ${EXEC} ${ARGS}

    exit 0

else

    logger -t ifplugd.action "Error: Couldn't configure $1, no ${EXEC} !"

    exit 1

fi
```

However, some times changing network interfaces screws up my nfs mounts, and the only fix seems to be to restart.

I'm mounting the nfs mounts with this in my fstab

```

192.168.98.2:/export/media      /mnt/eridu/media        nfs      user,rw,_netdev,bg,auto,intr,soft,retry=10

```

Should I be doing this differently?Last edited by Nicias on Wed Jun 03, 2015 10:15 pm; edited 1 time in total

----------

## massimo

Would AutoFS fit your needs?

----------

## charles17

 *Nicias wrote:*   

> Should I be doing this differently?

 Maybe you might want to have a look at https://forums.gentoo.org/viewtopic-p-7611984.html#7611984 and https://wiki.gentoo.org/wiki/Network_dependent_services

----------

## Nicias

I don't think either of those work. 

I suppose it boils down to what to do if the directory is in use. Mostly just a shell being open somewhere in the mount. If the connect interface changes, none of those solutions seem to fail gracefully. My best solution seems to be a restart.

----------

## szatox

Something doesn't fit here.

Behaviour you report would be typical if it was NFS host that changes interface. Is it the case?

NFS goes dumb when server's IP changes after it's mounted. Even if the name reported is the same, there is IP specified in mount options and if that IP is unreachable connection fails and NFS client hangs.

To fix it you can ensure IP of NFS host doesn't vanish when you change connection. You can team or bridge those interfaces or just keep some script around that will assign static IP to your interface. 

If it's client's interface that changes and hangs NFS it's really really weird, NFS server is almost stateless. Almost, because it does track mounts, but if a new machine requests data it could have mounted, server performs "internal" mount operation and carries on.

So, which setup is it?

----------

## Nicias

Host is always the same:

```

$ mount

....

192.168.98.2:/export/media on /mnt/eridu/media type nfs (rw,noexec,nosuid,nodev,bg,intr,soft,retry=10,vers=4,addr=192.168.98.2,clientaddr=192.168.98.6,user,_netdev)

$ ifconfig

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 71  bytes 3976 (3.8 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 71  bytes 3976 (3.8 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wifi: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.98.16  netmask 255.255.255.0  broadcast 192.168.98.255

        inet6 fe80::1e4b:d6ff:fe7f:f7e9  prefixlen 64  scopeid 0x20<link>

        ether 1c:4b:d6:7f:f7:e9  txqueuelen 1000  (Ethernet)

        RX packets 26345  bytes 2753141 (2.6 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 43  bytes 5325 (5.2 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wired: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.98.6  netmask 255.255.255.0  broadcast 192.168.98.255

        inet6 fe80::e2cb:4eff:fefd:710b  prefixlen 64  scopeid 0x20<link>

        ether e0:cb:4e:fd:71:0b  txqueuelen 1000  (Ethernet)

        RX packets 577993  bytes 565661534 (539.4 MiB)

        RX errors 0  dropped 11  overruns 0  frame 0

        TX packets 429500  bytes 64016889 (61.0 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 1  collisions 0

$ cd /mnt/eridu/media

nrobbins@kish /mnt/eridu/media $ ls

<works fine>

<unplug ethernet>

<wait a moment>

$ ifconfig

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536

        inet 127.0.0.1  netmask 255.0.0.0

        inet6 ::1  prefixlen 128  scopeid 0x10<host>

        loop  txqueuelen 0  (Local Loopback)

        RX packets 71  bytes 3976 (3.8 KiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 71  bytes 3976 (3.8 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wifi: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 192.168.98.16  netmask 255.255.255.0  broadcast 192.168.98.255

        inet6 fe80::1e4b:d6ff:fe7f:f7e9  prefixlen 64  scopeid 0x20<link>

        ether 1c:4b:d6:7f:f7:e9  txqueuelen 1000  (Ethernet)

        RX packets 26406  bytes 2758745 (2.6 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 46  bytes 5601 (5.4 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wired: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500

        inet6 fe80::e2cb:4eff:fefd:710b  prefixlen 64  scopeid 0x20<link>

        ether e0:cb:4e:fd:71:0b  txqueuelen 1000  (Ethernet)

        RX packets 578135  bytes 565710547 (539.5 MiB)

        RX errors 0  dropped 11  overruns 0  frame 0

        TX packets 429603  bytes 64034440 (61.0 MiB)

        TX errors 0  dropped 0 overruns 0  carrier 2  collisions 0

nrobbins@kish /mnt/eridu/media $ mount

<hang> 

<new shell>

$ mount

<...>

192.168.98.2:/export/media on /mnt/eridu/media type nfs (rw,noexec,nosuid,nodev,bg,intr,soft,retry=10,vers=4,addr=192.168.98.2,clientaddr=192.168.98.6,user,_netdev)

$ cd /mnt/eridu/media

<hang>

<new shell>

$ dmesg

[86922.464063] nfs: server 192.168.98.2 not responding, timed out

[86965.568092] nfs: server 192.168.98.2 not responding, timed out

[87023.920110] nfs: server 192.168.98.2 not responding, timed out

```

I can umount -f it, but then I can't mount it back.

----------

## szatox

 *Quote:*   

> (rw,noexec,nosuid,nodev,bg,intr,soft,retry=10,vers=4,addr=192.168.98.2,clientaddr=192.168.98.6,user,_netdev) 

 NFSv4, clientaddr in mount options... I guess that's the culprit. 

What about fixing that IP on client side? NFS4 uses TCP so you might not be able to remove that option completly, but you can still "restore" old IP upon iface switch

----------

## Nicias

That fixed it. I think.

I first tried to get my router to give me the same IP to both interfaces. It didn't want to do that. 

Then I worked out how to change the MAC address of my wifi card to match the ethernet MAC. The router does ip's by MAC's, and is too stupid to notice that who used to be connected over wifi is now connected over ethernet with the same MAC. It gives me the same address.

----------

