How to restart networking without DHCP RELEASE on Ubuntu

On Ubuntu systems, there is no more networking service restart option, so users are forced to do ifdown and ifup. But ifdown by default do a DHCPRELEASE causing systems to potentially change IPs on ifup. This would not be a very appreciated sideaffect with automated systems where IPs could change during the lifetime of the system.

Following script allows you to restart networking without actually do a DHCPRELEASE, (to avoid the DHCPRELEASE create temporary interfaces with all interfaces set to static and  bring down interfaces using that file, but use the original file to do the bring up the interfaces)

# cat ifdownup.sh
pkill dhclient && \
sed 's/dhcp/manual/' /etc/network/interfaces > /tmp/interfaces && \
for intf in `cat /etc/network/interfaces | grep inet | cut -d ' ' -f 2`; \
do ifdown $intf -i /tmp/interfaces && ifup $intf; done​

Comments

Popular posts from this blog

Multiple repeat error when the regex has multiple wildcards in python re module

Weakref proxy is for instance only ...

To speed up accessing files on nfs shares on a ubuntu machine ...