How to Remove Cached Network Information from Apple Devices

macNetworkwifi

I have a lab set up involving AP and DHCP, I am using my Macbook to connect to the AP and it requests a DHCP lease, however, when I change the network information on the router, the Macbook still keeps the obsolete information and has connectivity issues regarding the Internet.

I have been removing the network manually and this seems to clear the cache and accepts the new lease.

This is too time consuming though, is there a quicker way to clear the cache/lease so it can request a new address without having to 'forget' the network every time?

Best Answer

You have to release the IP address, not just renew it. This is because your DCHP client is going to attempt to request the lease it had previously so long as it hasn't expired. You have to force the client to ask for a new lease.

$ sudo ipconfig set <interface> BOOTP
$ sudo ipconfig set <interface> DHCP

Additionally, you can use the networksetup command

$ networksetup -setdhcp <networkservice> 
$ networksetup -setbootp <networkservice>

You would get the networkservice by issuing the command:

$ networksetup -listallnetworkservices

Of course, you could also do this in Network Preferences

enter image description here