Script for disabling ipv6 over ethernet

DaveB1
New Contributor II

Hello.

Does anybody have a  script that disables ipv6 over ethernet connections that works.

Thanks 

D

1 ACCEPTED SOLUTION

sdagley
Esteemed Contributor III

@DaveB1 This script will do it for all active interfaces:

#!/bin/bash

# Sets any network interface to IPv6 Link-Local Only mode

SAVEIFS=$IFS
IFS=$'\n'
interfaceList=($(networksetup -listallnetworkservices | grep -v -i -E "\*"))
interfaceCount=${#interfaceList[@]}
IFS=$SAVEIFS

for (( i = 0; i < interfaceCount; i++ ));
do
		echo "Working on interface ${interfaceList[$i]}"
		/usr/sbin/networksetup -setv6linklocal "${interfaceList[$i]}"
		/bin/sleep 1
done

exit 0

View solution in original post

6 REPLIES 6

sdagley
Esteemed Contributor III

@DaveB1 This script will do it for all active interfaces:

#!/bin/bash

# Sets any network interface to IPv6 Link-Local Only mode

SAVEIFS=$IFS
IFS=$'\n'
interfaceList=($(networksetup -listallnetworkservices | grep -v -i -E "\*"))
interfaceCount=${#interfaceList[@]}
IFS=$SAVEIFS

for (( i = 0; i < interfaceCount; i++ ));
do
		echo "Working on interface ${interfaceList[$i]}"
		/usr/sbin/networksetup -setv6linklocal "${interfaceList[$i]}"
		/bin/sleep 1
done

exit 0

AJPinto
Esteemed Contributor

Does this work on all interfaces or all active interfaces? I have also been poking at this myself for some time as a backlog thing and keep getting stuck on needing the network interface to be active and each dongle having its own interface. 

sdagley
Esteemed Contributor III

That will do all active interfaces (the filter for anything with an * excludes inactive interfaces)

DaveB1
New Contributor II

Thanks for your thoughts.

When I run the script in terminal directly on the mac. I get the below output and when I check the network settings ipv6 is still set to Automatically. I know I can change manually but I have 100+ macs to change this setting for so trying to avoid the personal touch. 

DaveB1_0-1746631467634.png

 



Last login: Wed May  7 16:15:31 on ttys000

DaveB1 ~ %

DaveB1 ~ % SAVEIFS=$IFS

IFS=$'\n'

interfaceList=($(networksetup -listallnetworkservices | grep -v -i -E "\*"))

interfaceCount=${#interfaceList[@]}

IFS=$SAVEIFS

 

for (( i = 0; i < interfaceCount; i++ ));

do

    echo "Working on interface ${interfaceList[$i]}"

    /usr/sbin/networksetup -setv6linklocal "${interfaceList[$i]}"

    /bin/sleep 1

done

 

exit 0

zsh: command not found:     echo

zsh: no such file or directory:     /usr/sbin/networksetup

zsh: no such file or directory:     /bin/sleep

zsh: command not found:     echo

zsh: no such file or directory:     /usr/sbin/networksetup

zsh: no such file or directory:     /bin/sleep

zsh: command not found:     echo

zsh: no such file or directory:     /usr/sbin/networksetup

zsh: no such file or directory:     /bin/sleep

 

Saving session...

...copying shared history...

...saving history...truncating history files...

...completed.

 

[Process completed]

 

 

sdagley
Esteemed Contributor III

You can't simply paste the script into Terminal. Save it as a file named SetIPv6Mode.sh (use an editor like BBEdit) then in Terminal type the command "sudo " (include the space after sudo) then enter the path to the saved script file (dragging the the file from a. Finder window into the Terminal window sill do that for you) and hit return. When prompted for your password enter it (it won't echo the characters) and hit return.

Or just add the script to Jamf Pro and run it as a Script payload in Policy.

DaveB1
New Contributor II

You rock.
Thank you for your help.