title: Changing network ip in a bash script started from a NFS-mounted folder
body: <p>I wrote a simple Bash script to change the network address of a Linux Host:</p>
  
  <pre><code>#!/bin/sh
  REMOTE_HOST=192.168.2.127   # Default Host address
  NEW_IP=192.168.30.33        # New IP I want to set
  NEW_GW=192.168.30.1         # New Gateway I want to set
  
  sudo ifconfig eth0 192.168.2.1     # Moving to the right network...
  #ping $REMOTE_HOST -c 3            # I can correctly ping the host here...
  
  ssh-copy-id root@${REMOTE_HOST} &gt; /dev/null   # ...for my comfort...
  
  # Setting the network with new values for the IP addr and the GW...
  COMMAND="sed -i 's@address *\\([0-9.]\\+\\)@address ${NEW_IP}@' /etc/network/interfaces\
        &amp;&amp; sed -i 's@gateway *\\([0-9.]\\+\\)@gateway ${NEW_GW}@' /etc/network/interfaces"
  
  ssh root@${REMOTE_HOST} $COMMAND
  # done!
  
  # Now restart the network services:
  ssh root@${REMOTE_HOST} "/etc/init.d/networking restart &amp;" &amp;   # (Note the 2nd '&amp;' !!!)
  
  # Come back to my old IP
  sudo ifconfig eth0 192.168.30.10
  sudo route add default gw 192.168.30.1
  </code></pre>
  
  <p>This script works almost perfectly but:</p>
  
  <p>1) If I run it from my home folder, no problems; if I run it from a NFS shared folder the script hangs for a minute or two before to end correctly</p>
  
  <p>2) If I omit the second '&amp;' when restarting the network on the host the command never returns...</p>
  
  <p>The questions are:</p>
  
  <p>1) What causes the long wait (NFS, different IP address, different gateway)? And is it possible to workaround it?</p>
  
  <p>2) Why it happens? How could I avoid it?</p>
  
  <p>Thanks for any kind of help and sorry for my bad English!</p>