Can I assign any static IP address to a device on my network? Or does it have to be within the DHCP servers (or routers) defined subnet?
Currently, my DHCP server is handing out IPs in the 192.168.0.1/24 range. What would happen if I set a static IP on a device of e.g. 192.168.1.10?
The DHCP server's configuration is irrelevant – what matters is the subnet that the router itself is configured to use. Often the DHCP range is actually narrower than the whole /24 subnet – e.g. even though a /24 goes from .0 to .255, the DHCP server only gives out the addresses .100-.199.
In short, the you wouldn't be able to communicate with anything, as other devices wouldn't know where to send packets meant for you:
Your other devices wouldn't recognize the address as belonging to a local subnet, and would send the packets through their "default gateway", which is your router.
Your router also wouldn't recognize the address as belonging to any of its local subnets, and would send the packets through its "default gateway", which is your ISP (who will just discard the packet).
However, if you configured two devices to be in the same 192.168.1.0/24 subnet, they would be able to communicate with each other, because packets between devices in the same subnet are directly switched, not routed. (In other words, the router trusts the devices themselves to know which MAC to send the packets to, and won't look at their IP addresses.)
And just out of curiosity, what would happen if I set the IP to (1) something that exists elsewhere (e.g. on the www),
Actually the same thing as above. If the routing table says it doesn't belong to a local subnet, then it doesn't belong to a local subnet, and the packets addressed to "you" will be sent elsewhere. (In this case, they might eventually reach the real owner of that IP address.)
or (2) something that the DHCP server has been asked to assign to another MAC?
If that other device remains offline, then nothing special. It would work.
Note that DHCP servers only issue information for devices to configure themselves with that address. The DHCP service doesn't really tell the router what to do with that address – the router still uses ARP to translate IP addresses to MAC addresses every time, no matter if that address is DHCP-issued or not.
(You may be thinking of a different feature called "static ARP" which some routers have, such as pfSense, and its configuration is often tied to the DHCP lease table for convenience. In pfSense, enabling this feature would actually tell the router to not use ARP for these IP addresses – as long as the DHCP server's database says the address belongs to this MAC address, the router always sends packets to that MAC address too.
But most routers do not implement "static ARP", so trying to use the IP address from a different device will always work regardless of what DHCP says.)
It might depend on your router, but generally assigning a static IP address will work regardless of whether or not it is in the range set aside for dynamic allocations - provided it is in the subnet range for that segment/network. In your example, setting 192.168.1.10
won't work on a /24
subnet but will on a /16
subnet.
If you set the IP address to something that has a static IP elsewhere, it depends on the client OS (i.e. it might check and not accept the assignment) - but it is likely that it will work and an IP address conflict will result with complex and undefined results leading to all kinds of weird behaviour/reachability issues for both systems.
I skimmed through the existing answers and didn't see this specified.
If you are setting an IP address manually on the device itself you not only can, but should assign an address that's outside the DHCP pool. Otherwise the DHCP server might give another device the same IP address.
Usually you should think up some loose convention, e.g. let DHCP assign three digit addresses (.100-.254) and leave the others for manual assignment.