Programmatically create a network bridge in Windows

Publish Date: December 5, 2023

Programmatically create a network bridge in Windows

Did you ever get stuck when creating a network bridge programmatically? You can do that quickly with the graphical user interface (GUI), as shown in the screenshot below.

Create a network bridge with GUI

But what if you want to create a bridge without using the GUI option? Well, it is not possible until you upgrade the operating system to Windows 11 (build 22621.2361). With this build version, Microsoft added the netsh bridge create command that helps you create a bridge. Without this command, your choice was only limited to the GUI.

Using the Netsh command

First, ensure you are running 22621.2361 build version of Windows 11. You can check that by running the winver command. To create a network bridge, launch an elevated PowerShell console and run these commands:

$adapter1 = Get-NetAdapter -Name 'eth0'
$adapter2 = Get-NetAdapter -Name 'eth1'
netsh bridge create $adapter1.name $adapter2.name

These commands will create a new network bridge with two network interfaces (eth0 and eth1), as shown in the screenshot below:

Create a network bridge with PowerShell

Once the bridge is created, run the netsh bridge list command to view it.

View a network bridge with PowerShell

This command shows you the bridge GUID. To add/remove the adapter to/from the bridge, you can use the commands shown below:

netsh bridge add <adapter_id> to <bridge_guid>
netsh bridge remove <adapter_id> from <bridge_guid>

The adapter ID can be a GUID, name, or interface index (IfIndex) and the bridge GUID can be obtained with the “netsh bridge list” command, as shown previously. To remove all network adapters from a bridge and destroys the bridge itself, run the following command:

netsh bridge remove all from <bridge_guid>

You can also delete the bridge by running this command:

netsh bridge destroy <bridge_guid>

That was all for this post. You just learned how to create and manage a network bridge with PowerShell.



Microsoft Certified | Cisco Certified

Leave a Reply