From nobody Mon Apr 8 08:23:21 2024 X-Original-To: freebsd-net@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VChtl4nlDz5GWd4 for ; Mon, 8 Apr 2024 08:23:27 +0000 (UTC) (envelope-from roy@marples.name) Received: from sender-of-o58.zoho.eu (sender-of-o58.zoho.eu [136.143.169.58]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4VChtl16BJz4L44 for ; Mon, 8 Apr 2024 08:23:26 +0000 (UTC) (envelope-from roy@marples.name) Authentication-Results: mx1.freebsd.org; none ARC-Seal: i=1; a=rsa-sha256; t=1712564603; cv=none; d=zohomail.eu; s=zohoarc; b=fZdM9X+FLudS167JH/RvbQP4RL3sz08rMV/ZVSW/p06Dn6Uh1b81KLBn/1FsiUzCSMvM7OnePji+BqQIOHfG3cCMcTaU7XPeMIwiV86UrYU+6uMY43U4hytRlKdIEZAHqyV5cdWRPBiYipSLStd481r8rwSKq7Gcn7SdmUaB4Es= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1712564603; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=5R1w0LInmTp1SRasaFDYFeIPSxFjZMheLh3Ae6Dsn6U=; b=FgC4oHRXA7mJz+iFrrT93ONRzufIvszW7GV+aDDdTd8d7RoNERKr1ODhIvJDjkFQ+X1O/0zjX1yDY+FvGmGpjvs5WxQIzibuE8g4gMBg5mddmd2YlmzSdJ2dinxN/nzt8H0gVMt9BhwFZ+U5De+1+DfQ1QNax2p143+00W155iA= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=marples.name; spf=pass smtp.mailfrom=roy@marples.name; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1712564603; s=zmail; d=marples.name; i=roy@marples.name; h=Date:Date:From:From:To:To:Cc:Cc:Message-ID:In-Reply-To:References:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Reply-To; bh=5R1w0LInmTp1SRasaFDYFeIPSxFjZMheLh3Ae6Dsn6U=; b=aDMUU4Dln8wxAWs2Us9ULTuilnPM5DFG+Q0SeTDF9jflKDO4tNDiIH3speXm0D5l bn1PyIL774WqSBv6TOdNmonZG8KAt1dWlD5VubjSc5QasKhWNSQ+cnkO/rckpSl8zbL QLW+X5eyvPcotz4eC/XzrGPMWL9Gyo/st+mu33O0= Received: from mail.zoho.eu by mx.zoho.eu with SMTP id 171256460135357.460271678040385; Mon, 8 Apr 2024 10:23:21 +0200 (CEST) Date: Mon, 08 Apr 2024 09:23:21 +0100 From: Roy Marples To: "Anton Yudin" Cc: "freebsd-net" Message-ID: <18ebcce010c.c4bc5178125082.198975928787124826@marples.name> In-Reply-To: References: Subject: Re: How to ignore a default route for one of the dhclient-ed interface? List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Importance: Medium User-Agent: Zoho Mail X-Mailer: Zoho Mail X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:41913, ipnet:136.143.168.0/23, country:CH] X-Rspamd-Queue-Id: 4VChtl16BJz4L44 ---- On Mon, 08 Apr 2024 04:16:47 +0100 Anton Yudin wrote ---=20 > =C2=A0 I'm running a FreeBSD 14 with two interfaces that use DHCP.=C2=A0= I would like to make one of the interfaces to never set the default route.= =C2=A0 Right now the first interface to be fully up sets the default route. >=20 > =C2=A0 I tried to set the following in /etc/dhclient.conf > ---------------8=C2=A0 interface "wan1" {=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 = ignore routers;=C2=A0 }---------------8=C2=A0 but the default route still g= ets set. > =C2=A0 I ended up creating a /etc/dhclient-enter-hooks with a very hacky= code that overrides the "route" command:---------------8<-----------------= ------- > route() { > =C2=A0 =C2=A0 =C2=A0 =C2=A0 if [ "X$interface" =3D "Xwan1" -a "X$2" =3D = "Xdefault" =C2=A0]; then > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 echo "ignore rou= te $1 $2 $3 $4" | logger -t "enter-hooks" > =C2=A0 =C2=A0 =C2=A0 =C2=A0 else > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /sbin/route $1 $= 2 $3 $4 > =C2=A0 =C2=A0 =C2=A0 =C2=A0 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 int= erface by metric. When both interfaces have a DHCP lease, dhcpcd will prefer the lowest metri= c 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