If you've used the Network Locations feature on your Mac and are wondering how to set it up on Linux - you've come to the right place.

Working as a systems administrator I did use the "Locations" functionality on my Mac. We use VLANs both in our office and data center. This functionality was really helpful if I was in the data center and had to quickly switch the network profile and access DC VLANs without re-configuring network connections. After switching to Linux it was a bit annoying to change settings every time I went into data center. Searching on the Internet for a possible solution got no results, so one day I took a deeper look on possible configurations and finally found how to set it up. It's still not that easy and beatiful like in MacOS, but it works (even if you have to do some additional steps to switch the network profile).

I'll go with following example setup for wired connection:

  • Two physical locations: Office and Datacenter
  • Network in office: 10.0.0.0/24
  • Network in DC: 10.1.0.0/24
  • VLANs in office:
  • 10: Management VLAN
  • 20: VoIP VLAN
  • 30: Clients VLAN
  • ...
  • VLANs in DC:
  • 10: Management VLAN
  • 20: iDRAC VLAN
  • 30: Database VLAN
  • ...

Setting up profile for Office

  1. Head into Network Settings (Menu -> System Settings -> Network).
  2. Select Wired connection in the left pane and click on the wheel in lower right corner to get into profile settings.
  3. Under Identity change the name for this profile (e.g. Office) and select your as MAC Address your NIC (probably something like enp0s31f6).
  4. (!) Remove the tick Connect automatically.
  5. Save settings by clicking on Apply.

Setting up profile for Datacenter

  1. In Network Settings select Wired in the left pane and klick on Add Profile.
  2. Select Identity in the left pane and give this profile a name, e.g. Data center.
  3. Select the same MAC address as for the first (office) profile.
  4. (!) Remove the tick Connect automatically.
  5. Save settings by clicking on Apply.

After that you'll have two profiles in your _Wired_ setup.

Adding VLANs to the Office profile

  1. Head to Network Connections menu.
  2. Click on the + symbol and select VLAN.
  3. Give this connection a name (e.g. Clients VLAN).
  4. (!) As Parent interface select your office profile. You can recognize it by the NIC name and addition via Office.
  5. Set the VLAN id (in our example it's 30).
  6. Set the VLAN interface name (optional, but will be easier to recognize it later in Network Settings menu).
  7. Set IP settings as needed and save the configuration.
  8. Repeat for other VLANs.

Adding VLAN to the DC profile

  1. Same procedure as for the office profile, but select the DC profile (via Data center) as Parent interface.

Switching profiles

Since we removed the ticks Connect automatically for profiles, it won't connect to any profile (that's what we need, because it would be a hassle if switching profiles). However, if you activate the profile once, system saves the state and will reconnect automatically until you deactivate it again.

To connect to specific network profile, just head to the Network Settings > Wired and click on the profile you want to connect. You'll recognize the active connection on the appearing tick.

That's it.

To summarize important steps:

Do no let profiles connect automatically!
  • If you activate it for both profiles, system will mess it up and try to connect to random profile.
  • If you activate it just for your main profile (e.g. office), you have to remove the tick every time you want to switch the profile. It's annoying.
Always assign VLANs to parent interfaces.
  • Especially if you have same VLAN IDs it's necessary to assign them to different interfaces.
Do not missclick while choosing parent interface.
  • If you choose another VLAN instead of physical interface - the network manager will crash so hard you have to reboot the system and fix it manually by removing network definitions from the system in command line. Try it, it's actually fun :)

Happy networking!