4

I'm looking for a way to switch On/Off IPv4 or IPv6 network from command line on macOS.

Like the description here:

Can I turn off IPv4 and just use IPv6 on my Mac?

one can turn On/Off IPv4 on macOS using the GUI.

However, I'm trying to manage multiple Mac mini remotely, and therefore, would like to do the task from command line.

In my case particularly, I'm able to access the macOS client via VNC viewer, which only support IPv4. Therefore, after disable the IPv4 from GUI via VNC session, I only have access to the client via IPv6 by using SSH. So, if this cannot be done via command line, I'll not able to recover the IPv4 unless I have access to that machine locally.

So, I am looking forward for the command line that I can use to enable IPv4 on Mac, or even further, switch On/Off IPv6 network as well.

1 Answer 1

3

What you're looking for is the "networksetup" command. You need to use it for each network service/interface though, because these settings are service/interface dependent.

To turn off IPv4 network:

sudo networksetup -setv4off <networkservice>

To turn back on the IPv4 network (assume DHCP is used):

sudo networksetup -setdhcp <networkservice> On

Some samples from the command help prompt relative to IPv6 network :

Usage: networksetup -setv6off <networkservice> 
    Turn IPv6 off on <networkservice>. 

Usage: networksetup -setv6automatic <networkservice> 
    Set the service to get its IPv6 info automatically. 

Usage: networksetup -setv6LinkLocal <networkservice> 
    Set the service to use its IPv6 only for link local. 

Usage: networksetup -setv6manual <networkservice> <address> <prefixlength> <router>
    Set the service to get its IPv6 info manually.
    Specify <address> <prefixLength> and <router>.

And if you need to find out the list of services/interface :

networksetup -listallnetworkservices

You can also check networksetup manual specifically with your remote desktop usage by going to this page : https://support.apple.com/fr-fr/guide/remote-desktop/apdd0c5a2d5/mac

2
  • 1
    Thanks for your hint, Pierre, and I've found out the switch for IPv4 will be like: sudo networksetup -setv4automatic Ethernet sudo networksetup -setdhcp Ethernet On and those commands works perfect for me. Commented Apr 30, 2025 at 13:06
  • Great ! Thanks for your feedback and additional information. Just corrected a grammar error from my initial post... Commented May 1, 2025 at 15:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.