Re: How to ignore a default route for one of the dhclient-ed interface?
- In reply to: Anton Yudin : "How to ignore a default route for one of the dhclient-ed interface?"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 08 Apr 2024 08:23:21 UTC
---- On Mon, 08 Apr 2024 04:16:47 +0100 Anton Yudin wrote --- > I'm running a FreeBSD 14 with two interfaces that use DHCP. I would like to make one of the interfaces to never set the default route. Right now the first interface to be fully up sets the default route. > > I tried to set the following in /etc/dhclient.conf > ---------------8 interface "wan1" { ignore routers; }---------------8 but the default route still gets set. > I ended up creating a /etc/dhclient-enter-hooks with a very hacky code that overrides the "route" command:---------------8<------------------------ > route() { > if [ "X$interface" = "Xwan1" -a "X$2" = "Xdefault" ]; then > echo "ignore route $1 $2 $3 $4" | logger -t "enter-hooks" > else > /sbin/route $1 $2 $3 $4 > fi > }---------------8 > Is there a better way of doing this? Yes there is. You can use dhcpcd (available in ports) instead where you can prefer an interface by metric. When both interfaces have a DHCP lease, dhcpcd will prefer the lowest metric and adjust routing and everything else accordingly. Assuming you have wan0 and wan1 and are ignoring wan1 the chances are that dhcpcd will just work for you out of the box. Otherwise you can tell dhcpcd your preference like so: interface eth0 metric 1 Here, eth0 will take preference other any other interface. OR You can also remove the option from the DHCP packet before processing interface wan1 nooption routers Hope this helps Roy