Am trying to add a script which will get executed on DHCP ip change for a particular interface. for that I have copied the below script at "/etc/dhcp/dhclient.d/dhcp-hook.sh". I need to get router IP whenever dhcp renew/bound happens in order to add route via that ip. Can someone suggest how do I get router ip info in "dhcp4-change" event, $DHCP4_routers_IP_ADDRESS in the below case. The script looks like below, table uplink1 is already populated. Just need to know how to get the router ip.

  1 #! /bin/sh
  3 interface=$1 status=$2
  5 if [ "$status" != "dhcp4-change"  -o
  6      $interface != $UPLINK1 ]; then
  7    return
  8 fi
  9 if  [ $interface = $UPLINK1 ]; then
 10     if [ -n $DHCP4_routers_IP_ADDRESS ]; then
 11        ip route add default via $DHCP4_routers_IP_ADDRESS table uplink1
 12     fi
 13 fi

You could always add echo "$(env)" > change_env.log and trigger the event to see what the environment variables look like then you could hopefully find what you need. A few promising environment variables from a different event include DHCP4_DHCP_SERVER_IDENTIFIER, IP4_GATEWAY, IP4_NAMESERVERS, DHCP4_DOMAIN_NAME_SERVERS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.