When a Mac picks up a strange DNS server or the wrong gateway, I want to see what the DHCP server actually sent before I start blaming anything. macOS keeps that answer around, and ipconfig getpacket prints it.
ipconfig getpacket en0
Swap en0 for the interface you care about. On a MacBook that is usually Wi-Fi, and a USB or Thunderbolt Ethernet adapter gets a higher number. What you see is the raw DHCP reply: yiaddr is the address you were given, server_identifier is the DHCP server, and under options you find subnet_mask, router, domain_name_server and lease_time.
The DNS line is the one I’d check first. I run AdGuard Home on my Unraid server, so on a home network like mine you’d expect domain_name_server to point at that box (something like 192.168.1.x). If it shows the router or your provider’s resolver instead, the DHCP settings on the router are the problem, and changing things on the Mac won’t fix the other devices.
Need just one value? getoption takes an option name:
ipconfig getoption en0 router
ipconfig getoption en0 domain_name_server
Apple’s man page says getoption prints only the first value when an option has several, so a second DNS server stays hidden there. getpacket shows them all.
The command prints nothing when the interface isn’t using DHCP or never got a lease, so empty output on a manual IP is normal. lease_time is shown in hexadecimal seconds: 0x15180 is 86400, one day. The man page also calls ipconfig a tool for testing and debugging. For reading a lease that’s fine, but I wouldn’t build scripts that change settings on top of it.
Further reading: ipconfig man page (SS64, macOS)