The networking module for Windows based systems
Disable an interface
iface (str) -- The name of the interface to manage
CLI Example:
salt -G 'os_family:Windows' ip.disable 'Local Area Connection #2'
Enable an interface
iface (str) -- The name of the interface to manage
CLI Example:
salt -G 'os_family:Windows' ip.enable 'Local Area Connection #2'
Return IP configuration for all network interfaces using the legacy
netsh-compatible data format.
Each interface is keyed by its alias and contains ip_addrs,
ipv4_gateway, dns_servers, and related fields mirroring the
structure formerly produced by netsh interface ip show config.
Prefer list_interfaces() with full=True for richer, always-
English output.
A dictionary keyed by interface name. Each value is a
dict with the legacy netsh-style fields.
CLI Example:
salt -G 'os_family:Windows' ip.get_all_interfaces
Get the Default Gateway on Windows.
iface (str, optional) -- The name or alias of the interface to query (e.g., 'Ethernet').
If provided, the function returns the default gateway specific
to that interface. If None (default), it returns the
system-wide primary default gateway based on the lowest route
metric.
The IP address of the default gateway.
CommandExecutionError -- If no default gateway is found.
CLI Example:
# Get the system's primary default gateway
salt 'minion' ip.get_default_gateway
# Get the gateway for a specific interface
salt 'minion' ip.get_default_gateway iface='Local Area Connection'
Return the IP configuration of a single network interface
iface (str) -- The name of the interface
CLI Example:
salt -G 'os_family:Windows' ip.get_interface 'Local Area Connection'
Return the integer ifIndex for the named interface.
iface (str) -- The interface name or alias (e.g., 'Ethernet').
session (PowerShellSession, optional) -- An existing PowerShellSession to reuse. If None (default),
a new session is opened for this call only.
The interface index.
CommandExecutionError -- If the interface cannot be found.
CLI Example:
salt -G 'os_family:Windows' ip.get_interface_index 'Ethernet'
Retrieves the current configuration of a network interface on Windows.
This function gathers comprehensive data about a network adapter, including
administrative status, protocol bindings, IP addresses, DNS servers,
gateways, and WINS configuration. The returned dictionary is structured
to be directly compatible with the parameters of set_interface.
Data Structures and Round-trip Logic:
Addresses: IPs are returned in CIDR notation (e.g., 10.0.0.5/24)
to ensure the setter can accurately recreate the subnet mask.
Gateways: Returned as a list of dictionaries containing both the
IP (ip) and the route-specific metric (metric).
Metrics: A value of 0 indicates that the interface is
configured for 'Automatic Metric' calculation by Windows.
iface (str) -- The name or alias of the interface (e.g., 'Ethernet'). This is used
for the initial hardware lookup to find the permanent InterfaceIndex.
A dictionary keyed by the interface name containing:
alias (str): The friendly name of the adapter.
description (str): Human-readable adapter description (e.g.,
"Microsoft Loopback Adapter").enabled (bool): Administrative status (
True= Up).index (int): The stable
InterfaceIndexused internally by all CIM/PowerShell cmdlets.link_status (str): Current link state reported by the driver (e.g.,
"Up","Disconnected").mac_address (str): The physical (MAC) address of the adapter.
mtu (int): MTU in bytes; defaults to
1500when the adapter reports no value (4294967295orNone).dns_register (bool):
Trueif the adapter registers its addresses in DNS using the computer's primary DNS suffix.dns_suffix (str): Connection-specific DNS suffix, or
Noneif not set.ipv4_enabled (bool): Status of the IPv4 protocol binding.
ipv4_dhcp (bool):
Trueif IPv4 DHCP is enabled.ipv4_metric (int): The IPv4 interface metric (
0= Auto).ipv4_address (list): List of IPv4 addresses in CIDR format.
ipv4_gateways (list): List of dicts, each with
ipandmetrickeys, for IPv4 default routes. Always a list — even when only one gateway is configured — because_normalize_gateway_fields()corrects the PowerShell 5.1 behavior of unwrapping single-element arrays.ipv4_dns (list): List of IPv4 DNS server addresses.
ipv4_forwarding (bool | None):
Trueif IPv4 forwarding is enabled,Noneif the IPv4 stack is not bound.ipv4_wins (list): Primary and secondary WINS server addresses (empty list if none configured).
ipv4_netbios (str): NetBIOS configuration —
"Default","Enable", or"Disable".ipv6_enabled (bool): Status of the IPv6 protocol binding.
ipv6_dhcp (bool):
Trueif IPv6 stateful config is enabled.ipv6_metric (int): The IPv6 interface metric (
0= Auto).ipv6_address (list): List of IPv6 addresses in CIDR format.
ipv6_gateways (list): List of dicts, each with
ipandmetrickeys, for IPv6 default routes. Always a list for the same reason asipv4_gateways.ipv6_dns (list): List of IPv6 DNS server addresses.
ipv6_forwarding (bool | None):
Trueif IPv6 forwarding is enabled,Noneif the IPv6 stack is not bound.
CommandExecutionError -- If the specified interface cannot be found.
CLI Examples:
# Get details for a specific interface
salt-call --local win_ip.get_interface_new "Ethernet"
# Get details for the loopback test adapter
salt '*' win_ip.get_interface_new "Test-Iface"
Convenience function to convert the netmask to the CIDR subnet length
mask (str) -- A netmask
CLI Example:
salt -G 'os_family:Windows' ip.get_subnet_length 255.255.255.0
Returns True if interface is disabled, otherwise False
iface (str) -- The name of the interface to manage
CLI Example:
salt -G 'os_family:Windows' ip.is_disabled 'Local Area Connection #2'
Returns True if interface is enabled, otherwise False
iface (str) -- The name of the interface to manage
CLI Example:
salt -G 'os_family:Windows' ip.is_enabled 'Local Area Connection #2'
Lists the available network interfaces on the system.
full (bool, optional) -- If True, returns a dictionary keyed by
interface names with detailed configuration for each adapter.
If False, returns a list of interface names only.
Defaults to False.
When full=False, a list of interface name strings.
full=True, a dictionary keyed by interface name.Each value has the same structure as the per-interface dict
returned by get_interface_new() — see that function for
the full field reference (alias, description, enabled,
index, link_status, mac_address, mtu,
dns_register, dns_suffix, ipv4_*, ipv6_*).
The entire dataset is collected in a single PowerShell
invocation rather than one session per adapter, so it is
significantly faster than calling get_interface_new()
in a loop.
CLI Example:
salt -G 'os_family:Windows' ip.list_interfaces
salt -G 'os_family:Windows' ip.list_interfaces full=True
Return raw configs for all interfaces as returned by netsh. This command is localized and will return different text depending on the locality of the operating system.
CLI Example:
salt -G 'os_family:Windows' ip.raw_interface_configs
Set both IP Address and DNS to DHCP
iface (str) -- The name of the interface to manage
{"Interface": <name>, "DNS Server": "DHCP", "DHCP enabled": "Yes"}
CommandExecutionError -- If either the IP or DNS cannot be switched to DHCP.
CLI Example:
salt -G 'os_family:Windows' ip.set_dhcp_all 'Local Area Connection'
Set DNS source to DHCP on Windows
iface (str) -- The name of the interface to manage
{} if DNS was already set to automatic (no static servers
configured), otherwise {"Interface": <name>, "DNS Server": "DHCP (Empty)"}.
CommandExecutionError -- If the DNS reset cannot be verified.
CLI Example:
salt -G 'os_family:Windows' ip.set_dhcp_dns 'Local Area Connection'
Set Windows NIC to get IP from DHCP
iface (str) -- The name of the interface to manage
{} if DHCP was already enabled, otherwise
{"Interface": <name>, "DHCP enabled": "Yes"}.
CommandExecutionError -- If DHCP cannot be enabled.
CLI Example:
salt -G 'os_family:Windows' ip.set_dhcp_ip 'Local Area Connection'
Configures a network interface on Windows.
This function provides a context-aware interface for managing adapter properties, protocol bindings, and IP configurations. It utilizes the InterfaceIndex to ensure stability during renames.
Understanding Metrics on Windows: Windows calculates route priority by summing the Interface Metric (protocol level) and the Route Metric (gateway level).
Interface Metric: Set via ipvX_metric. A value of 0
enables 'Automatic Metric', where Windows assigns priority based on link
speed.
Route Metric: Set within the ipvX_gateways objects.
Total Cost: Interface Metric + Route Metric. The lowest total cost determines the primary route.
Context-Aware Behavior: The function identifies the current state of protocol bindings (IPv4/IPv6) before applying settings.
If a protocol is disabled and ipvX_enabled is not passed as True,
configuration for that stack (IPs, DNS, etc.) is skipped to prevent
errors.
If ipvX_dhcp is enabled, static IP and gateway configurations are
ignored by the OS; therefore, this function skips applying static
addresses unless DHCP is False.
iface (str) -- The current name or alias of the interface (e.g., 'Ethernet').
alias (str, optional) -- A new name for the interface.
enabled (bool, optional) -- Administrative status of the adapter.
ipv4_enabled (bool, optional) -- Whether the IPv4 protocol is bound to this adapter. If None, the
function discovers current state.
ipv4_address (list, optional) --
An IPv4 address or list of addresses in CIDR notation
(e.g., ['192.168.1.5/24']).
Note
If a CIDR prefix is not provided, it will default to /24.
ipv4_dhcp (bool, optional) -- Set to True to enable DHCP, False for static.
ipv4_dns (list, optional) -- A list of IPv4 DNS server addresses. Passing an empty list []
resets DNS to automatic.
ipv4_forwarding (bool, optional) -- Enables or disables IP Forwarding for the IPv4 stack. When
True, this allows the Windows machine to act as a router,
passing traffic between this interface and others.
Default is None (no change).
ipv4_gateways (list, str, dict) --
The default gateway(s). Accepts multiple formats:
String: A single IP address (e.g., '192.168.1.1').
List of Strings: Multiple gateways (e.g., ['1.1.1.1', '1.0.0.1']).
Dictionary: A single gateway with a specific route metric
(e.g., {'ip': '192.168.1.1', 'metric': 5}).
List of Dictionaries: Multiple gateways with individual metrics
(e.g., [{'ip': '1.1.1.1', 'metric': 2}, {'ip': '1.0.0.1', 'metric': 10}]).
If a metric is not specified within a dictionary, or if a string/list
of strings is provided, the function falls back to ipv4_metric.
ipv4_metric (int, optional) -- The IPv4 interface metric. Use 0 for Automatic.
ipv4_wins (list, optional) -- A list of up to two WINS server addresses.
ipv4_netbios (str, optional) --
Configures NetBIOS over TCP/IP behavior via the MSFT_NetIPInterface CIM class.
Default (0): Defer to DHCP server settings.
Enable (1): Explicitly enable NetBIOS.
Disable (2): Explicitly disable NetBIOS.
ipv6_enabled (bool, optional) -- Whether the IPv6 protocol is bound.
ipv6_address (list, optional) --
An IPv6 address or list of addresses in CIDR notation
(e.g., ['2001:db8::1/64']).
Note
If a CIDR prefix is not provided, it will default to /64.
ipv6_dhcp (bool, optional) -- Set to True for IPv6 stateful configuration.
ipv6_dns (list, optional) -- A list of IPv6 DNS server addresses.
ipv6_forwarding (bool, optional) -- Enables or disables IP Forwarding for the IPv6 stack. When
True, this allows the Windows machine to act as a router,
passing traffic between this interface and others.
Default is None (no change).
ipv6_gateways (list, optional) --
The default gateway(s) for IPv6. Accepts multiple formats:
String: A single IPv6 address (e.g., '2001:db8::1').
List of Strings: Multiple gateways (e.g., ['2001:db8::1', 'fe80::1']).
Dictionary: A single gateway with a specific route metric
(e.g., {'ip': '2001:db8::1', 'metric': 5}).
List of Dictionaries: Multiple gateways with individual metrics
(e.g., [{'ip': '2001:db8::1', 'metric': 2}, {'ip': 'fe80::1', 'metric': 10}]).
If a metric is not specified within a dictionary, or if a string/list
of strings is provided, the function falls back to ipv6_metric.
Note that link-local gateways (starting with fe80::) are fully
supported as Windows scopes them via the interface index.
ipv6_metric (int, optional) -- The IPv6 interface metric. Use 0 for Automatic.
dns_register (bool, optional) --
Controls whether the interface's IP addresses are registered in DNS using the computer's primary DNS suffix.
True (Default in Windows): Corresponds to "Primary only" in
legacy output. The computer will attempt to dynamically update
its DNS record (A/AAAA) on the DNS server.
False: Corresponds to "None". The computer will not attempt
to register its name for this specific connection.
dns_suffix (str, optional) -- Sets the Connection-Specific DNS Suffix (e.g.,
corp.example.com). This value is used in DNS registration and
resolution but does not change the global primary DNS suffix of the
computer.
mtu (int, optional) -- Configures the Maximum Transmission Unit size for the physical
adapter. Accepts values between 576 and 9000. Common uses
include setting 9000 for Jumbo Frames in iSCSI/Storage networks
or lower values for VPN compatibility.
append (bool) --
If True, the provided IPv4 and IPv6 addresses will be added
to the interface without removing existing ones. If False (default),
all existing IPv4/IPv6 addresses on the interface will be removed
before applying the new configuration.
Note
This flag only applies to IP addresses. Gateways (Default Routes) are always replaced if a new gateway is provided to ensure routing stability.
True if successful, otherwise raises an exception.
CLI Examples:
# Set static IPv4 with a specific metric
salt-call --local win_ip.set_interface "Ethernet" ipv4_dhcp=False \
ipv4_address="['192.168.1.10/24']" ipv4_metric=10
# Set multiple gateways with different route priorities
salt-call --local win_ip.set_interface "Test-Iface" \
ipv4_gateways="[{'ip': '10.0.0.1', 'metric': 2}, {'ip': '10.0.0.2', 'metric': 100}]"
# Reset DNS to automatic/DHCP
salt '*' win_ip.set_interface "Wi-Fi" ipv4_dns="[]"
# Rename an interface and enable IPv6
salt-call --local win_ip.set_interface "Ethernet 2" alias="Production" \
ipv6_enabled=True ipv6_dhcp=True
Set static DNS configuration on a Windows NIC
A dictionary containing the new DNS settings
CLI Example:
salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.1'
salt -G 'os_family:Windows' ip.set_static_dns 'Local Area Connection' '192.168.1.252' '192.168.1.253'
Set static IP configuration on a Windows NIC
iface (str) -- The name of the interface to manage
addr (str) -- IP address with subnet length (ex. 10.1.2.3/24). The
ip.get_subnet_length
function can be used to calculate the subnet length from a netmask.
gateway (str, optional) -- If specified, the default gateway will be set to this value.
Default is None.
append (bool, optional) -- If True, the address will be added as a secondary IP to the
interface. If False, all existing IPv4 addresses are cleared
first. Defaults to False.
A dictionary with the applied settings, e.g.:
{"Address Info": ["192.168.1.5/24"], "Default Gateway": "192.168.1.1"}
Default Gateway is only present when the gateway argument is
provided.
SaltInvocationError -- If addr or gateway is not a valid IPv4
address.
CommandExecutionError -- If the address already exists on the interface.
CLI Example:
salt -G 'os_family:Windows' ip.set_static_ip 'Local Area Connection' 10.1.2.3/24 gateway=10.1.2.1
salt -G 'os_family:Windows' ip.set_static_ip 'Local Area Connection' 10.1.2.4/24 append=True