netrefresh.sh
#!/usr/bin/env bash
# FUNCTION: __network_restart
__network_restart() {
if command -v systemctl &> /dev/null; then
# For systems using systemd
systemctl restart systemd-networkd
systemctl restart NetworkManager
systemctl restart networking
elif [ -f /etc/init.d/networking ]; then
# For systems using init.d
/etc/init.d/networking restart
elif [ -f /etc/init.d/network-manager ]; then
/etc/init.d/network-manager restart
elif [ -f /etc/init.d/network ]; then
/etc/init.d/network restart
fi
# Renew DHCP lease
if command -v dhclient &> /dev/null; then
dhclient -r
dhclient
elif command -v dhcpcd &> /dev/null; then
dhcpcd -k
dhcpcd
elif command -v pump &> /dev/null; then
pump -r
fi
}
__network_restart