dhcpcd-discuss

Re: Replace DHCP default gateway with static route

Roy Marples

Tue Apr 03 23:28:18 2018

Hi Alex

On 04/04/2018 00:05, Alex K. wrote:
I've been looking for days to achieve the following - replace the default gateway DHCPCD got from the network, with a static route (toward a particular subnet only), using the router IP address we got within the basic DHCP offer, as that route next hop.

Basically, replacing the "regular" default route DHCP put, with a static route. Obviously keeping the rest of information DHCP got (our IP address and such).

After digging for days, I haven't been able to make working configuration/hook. Therefore, any suggestion will be gladly appreciated.

dhcpcd does not offer such functionality. Assumning you're using Linux, I would script a dhcpcd.exit-hook like so.
(This is untested and just typed here, hopefully enough for an idea)

if $if_up; then
	ip r d default dev $interface
	set -- $routers
	while [ -n "$1" ]; do
		ip r a 1.2.3.4/16 via $1 dev $interface && break
		shift
	done
elif $if_down; then
	ip r d 1.2.3.4/16 dev $interface
fi

Good luck

Roy

Follow-Ups:
Re: Replace DHCP default gateway with static routeAlex K.
References:
Replace DHCP default gateway with static routeAlex K.
Archive administrator: postmaster@marples.name