Skip to main content
deleted 6 characters in body
Source Link
Eduardo Trápani
  • 14.2k
  • 1
  • 21
  • 38

dhcp does not change the local configuration directly, it calls a script once it gets the lease (by default /sbin/dhclient-script in Debian).

You can specify your own script with -sf and use the $new_ip_address to find out the leased IP. There is a dedicated manpage for this type of script.

dhcp will keep on running once it gets the lease, so you need to stop it. By default the pid is stored in /var/run/dhclient.pid but you can change it with -pf.

An example script:

#!/bin/sh

case $reason in
BOUND|RENEW|REBIND|REBOOT)
    echo "MY IP IS " $new_ip_address
    kill $(cat /var/run/dhclient.pid)
    ;;
*)
    ;;
esac

Then, if you run:

dhclient -sf /path/to/your_script -d  wlxd037455928c0interface 2>&1 | grep "MY IP"

You'll get the value.

Be sure to avoid interaction with other DHCP client processes (dhclient, NetworkManager, ...) since in that case the results could be different.

dhcp does not change the local configuration directly, it calls a script once it gets the lease (by default /sbin/dhclient-script in Debian).

You can specify your own script with -sf and use the $new_ip_address to find out the leased IP. There is a dedicated manpage for this type of script.

dhcp will keep on running once it gets the lease, so you need to stop it. By default the pid is stored in /var/run/dhclient.pid but you can change it with -pf.

An example script:

#!/bin/sh

case $reason in
BOUND|RENEW|REBIND|REBOOT)
    echo "MY IP IS " $new_ip_address
    kill $(cat /var/run/dhclient.pid)
    ;;
*)
    ;;
esac

Then, if you run:

dhclient -sf /path/to/your_script -d  wlxd037455928c0 2>&1 | grep "MY IP"

You'll get the value.

Be sure to avoid interaction with other DHCP client processes (dhclient, NetworkManager, ...) since in that case the results could be different.

dhcp does not change the local configuration directly, it calls a script once it gets the lease (by default /sbin/dhclient-script in Debian).

You can specify your own script with -sf and use the $new_ip_address to find out the leased IP. There is a dedicated manpage for this type of script.

dhcp will keep on running once it gets the lease, so you need to stop it. By default the pid is stored in /var/run/dhclient.pid but you can change it with -pf.

An example script:

#!/bin/sh

case $reason in
BOUND|RENEW|REBIND|REBOOT)
    echo "MY IP IS " $new_ip_address
    kill $(cat /var/run/dhclient.pid)
    ;;
*)
    ;;
esac

Then, if you run:

dhclient -sf /path/to/your_script -d  interface 2>&1 | grep "MY IP"

You'll get the value.

Be sure to avoid interaction with other DHCP client processes (dhclient, NetworkManager, ...) since in that case the results could be different.

Source Link
Eduardo Trápani
  • 14.2k
  • 1
  • 21
  • 38

dhcp does not change the local configuration directly, it calls a script once it gets the lease (by default /sbin/dhclient-script in Debian).

You can specify your own script with -sf and use the $new_ip_address to find out the leased IP. There is a dedicated manpage for this type of script.

dhcp will keep on running once it gets the lease, so you need to stop it. By default the pid is stored in /var/run/dhclient.pid but you can change it with -pf.

An example script:

#!/bin/sh

case $reason in
BOUND|RENEW|REBIND|REBOOT)
    echo "MY IP IS " $new_ip_address
    kill $(cat /var/run/dhclient.pid)
    ;;
*)
    ;;
esac

Then, if you run:

dhclient -sf /path/to/your_script -d  wlxd037455928c0 2>&1 | grep "MY IP"

You'll get the value.

Be sure to avoid interaction with other DHCP client processes (dhclient, NetworkManager, ...) since in that case the results could be different.