Create virtual network interfaces (vlans) via script

Hello, I am new to macOS scripting, so please be gentle.

I am trying to create/delete some VLANs (Virtual Network Interfaces) from a script.

image

Can anyone point me in the right direction please?

I found some vconfig instructions (networking - How to setup VLAN from Mac OS Mojave using terminal - Super User) and was able to add an interface, but it did not persist a reboot, so looking for something more reliable.

Thanks in advance.

vconfig is the Linux tool for creating VLANs, so isn’t relevant here.

The link you provide points towards using ifconfig to create a VLAN - that’s valid, but ifconfig changes are transient, and therefore lost on reboot (as you’ve noticed).

Instead, MacOS includes the command line networksetup which creates persistent configuration changes that will survive a reboot. Specifically:

networksetup -createVLAN <VLAN name> <parent device name> <tag>

and the corresponding

networksetup -deleteVLAN <VLAN name> <parent device name> <tag>

So as far as your script is concerned, you probably need something like:

do shell script "networksetup -createVLAN myvlan en0 123" with administrator privileges