Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Created February 9, 2024 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilangvperdana/dc4d37de26690968f53e44c188460cfc to your computer and use it in GitHub Desktop.
Save gilangvperdana/dc4d37de26690968f53e44c188460cfc to your computer and use it in GitHub Desktop.
Auto DHCLIENT Spesific interface when Booting

General

If you need dhclient spesific interface every VM booting you can try this workaround

Workaround

for Example spesific interface on this workaround are ens18

  • Create this script
sudo nano /etc/init.d/dhclient-ens18
#!/bin/bash
### BEGIN INIT INFO
# Provides:          dhclient-ens18
# Required-Start:    $network $local_fs
# Required-Stop:     $network $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Run dhclient on ens18
# Description:       Run dhclient on interface ens18 to obtain an IP address
### END INIT INFO

case "$1" in
    start)
        /sbin/dhclient ens18
        ;;
    stop)
        # Add any stop actions here, if necessary
        ;;
    restart)
        $0 stop
        sleep 1
        $0 start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0
sudo chmod +x /etc/init.d/dhclient-ens18
sudo update-rc.d dhclient-ens18 defaults
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment