1

Is there a way to set a static IP, without stopping breaking DHCP default gateway/route setting?

I normally use dhcpcd.conf to set static IP's, but any static IP configuration on the interface will stop automatic DNS/default route/subnet mask setting.

I have an Android Hotspot that changes its NAT IP erratically, so I can't set the default gateway statically, but I need the Raspberry PI to have a static IP in the Hotspot network.

After running dhcpcd -T, which tests dhcp.conf settings, it appears DHCP is practically disabled when a static IP is set. Perhaps there is a post DHCP apply hook that would allow me to set my config after dhcpcd has done it's magic.

Update with info from comment:
Problem with using mac address on the DHCP server is I don't have access to the Android hotspot DHCP server configuration. It's fairly hard coded from what I know.

2

In general if you decide to use a static ip address then a DHCP server either does not see the static client because it doesn't broadcast DHCPRECOVER packages, or the DHCP server recover the client by ICMP (ping) and then it will remove the static ip address from its address pool and never touch it again. That's by definition. So there is no way to mix a static ip address with other managed options getting from the DHCP server, e.g. the default gateway.

But on the DHCP server you can bind the MAC address of the RasPi to a fix ip address so it will get always the same. That is like defining a static ip address on the client side but the DHCP server can also give the other dynamic options (default gateway) together with the fix ip address to the client as usual.

| improve this answer | |
  • I was hoping for a solution involving a reliable post DHCP apply hook. Or systemd event. Problem with using mac address on the DHCP server is I don't have access to the Android hotspot DHCP server configuration. It's fairly hard coded from what I know. – Ray Foss Jan 2 at 19:11
1

By definition Dynamic Host Configuration Protocol (DHCP) configures IP, Netmask, and default gateway. It usually also configures DNS, although it is acceptable to set DNS statically even if the rest are dynamic. For more info on DHCP than you probably want, you could check out https://www.lifewire.com/what-is-dhcp-2625848.

Is there a way you could run two wlans so that one was static and one was dynamic? One option would be adding a USB WiFi adapter so you could have the one set with DHCP and the other set static. Of course that assumes that the Hotspot isn't changing the network, just changing its IP address within the network. If it is changing the network number, then the static IP would have to route the packets between the adapters rather than just communicating on both.

| improve this answer | |

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.