Skip to content

Commit 0fc52fb

Browse files
committed
feat: updated Windows commands to use netsh for IP address management and added new option to re-enable DHCP on an interface
1 parent fc56ac2 commit 0fc52fb

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

changelogs/2026-02-14_03-04-36.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Changelog
2+
3+
## [Unreleased]
4+
5+
### Changed
6+
- Updated Windows commands for adding and deleting IP addresses to use `netsh` instead of `powershell`.
7+
- Modified Windows command for renewing IP address to use `ipconfig` directly instead of `powershell`.
8+
- Changed Windows command for network interface status to use `Get-NetAdapter` and `Get-NetIPAddress` with `Format-List` for better output formatting.
9+
- Replaced `Resolve-DnsName` with `nslookup` in Windows command for DNS test.
10+
- Updated Windows command for connectivity test to use `ping` with `-n` and `-w` options.
11+
12+
### Added
13+
- Added a new option to re-enable DHCP on an interface in the `reset-network.yaml` file.
14+
- Included a new argument `netmask` in the `alias-ip.yaml` file to allow users to specify the subnet mask when adding an IP alias.

repository/network/alias-ip.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ versions:
2929
arch: ip addr add {{ip_address}}/{{prefix}} dev {{interface}} label {{interface}}:{{label}}
3030
alpine: ip addr add {{ip_address}}/{{prefix}} dev {{interface}} label {{interface}}:{{label}}
3131
darwin: ifconfig {{interface}} alias {{ip_address}}/{{prefix}}
32-
windows: powershell -Command "New-NetIPAddress -InterfaceAlias '{{interface}}' -IPAddress '{{ip_address}}' -PrefixLength {{prefix}} -SkipAsSource ([bool]1)"
32+
windows: 'netsh interface ip add address "{{interface}}" {{ip_address}} {{netmask}}'
3333
command: ip addr add {{ip_address}}/{{prefix}} dev {{interface}} label {{interface}}:{{label}}
3434
skip_on_error: false
3535
args:
@@ -40,6 +40,10 @@ versions:
4040
prompt: "Enter the subnet prefix length (e.g., 24 for /24)"
4141
default: "24"
4242
required: false
43+
- name: netmask
44+
prompt: "Enter the subnet mask (e.g., 255.255.255.0)"
45+
default: "255.255.255.0"
46+
required: false
4347
- name: interface
4448
prompt: "Enter the network interface name (e.g., eth0, ens33, Ethernet)"
4549
default: "eth0"
@@ -56,7 +60,7 @@ versions:
5660
rhel: 'cat > /etc/sysconfig/network-scripts/ifcfg-{{interface}}:{{label}} << EOF\nDEVICE={{interface}}:{{label}}\nIPADDR={{ip_address}}\nNETMASK={{netmask}}\nONBOOT=yes\nEOF\necho "Alias IP config created at /etc/sysconfig/network-scripts/ifcfg-{{interface}}:{{label}}"'
5761
fedora: 'nmcli connection modify {{interface}} +ipv4.addresses "{{ip_address}}/{{prefix}}" && nmcli connection up {{interface}}'
5862
arch: 'echo -e "\n[Address]\nAddress={{ip_address}}/{{prefix}}\nLabel={{interface}}:{{label}}" >> /etc/systemd/network/{{interface}}.network && systemctl restart systemd-networkd'
59-
windows: powershell -Command "New-NetIPAddress -InterfaceAlias '{{interface}}' -IPAddress '{{ip_address}}' -PrefixLength {{prefix}} -SkipAsSource ([bool]1); Write-Host 'Windows IP aliases are persistent by default'"
63+
windows: 'netsh interface ip add address "{{interface}}" {{ip_address}} {{netmask}}; Write-Host "Windows IP aliases added via netsh are persistent by default"'
6064
command: 'echo -e "\nauto {{interface}}:{{label}}\niface {{interface}}:{{label}} inet static\n address {{ip_address}}\n netmask {{netmask}}" >> /etc/network/interfaces && echo "Alias IP added to /etc/network/interfaces"'
6165
skip_on_error: true
6266
args:
@@ -125,7 +129,7 @@ versions:
125129
arch: ip addr del {{ip_address}}/{{prefix}} dev {{interface}}
126130
alpine: ip addr del {{ip_address}}/{{prefix}} dev {{interface}}
127131
darwin: ifconfig {{interface}} -alias {{ip_address}}
128-
windows: powershell -Command "Remove-NetIPAddress -InterfaceAlias '{{interface}}' -IPAddress '{{ip_address}}' -Confirm:([bool]0)"
132+
windows: 'netsh interface ip delete address "{{interface}}" {{ip_address}}'
129133
command: ip addr del {{ip_address}}/{{prefix}} dev {{interface}}
130134
skip_on_error: false
131135
args:
@@ -148,7 +152,7 @@ versions:
148152
rhel: 'rm -f /etc/sysconfig/network-scripts/ifcfg-{{interface}}:{{label}} && echo "Removed alias config file"'
149153
fedora: 'nmcli connection modify {{interface}} -ipv4.addresses "{{ip_address}}/{{prefix}}" && nmcli connection up {{interface}}'
150154
arch: 'sed -i "/{{ip_address}}/,+2d" /etc/systemd/network/{{interface}}.network && systemctl restart systemd-networkd'
151-
windows: powershell -Command "Remove-NetIPAddress -InterfaceAlias '{{interface}}' -IPAddress '{{ip_address}}' -Confirm:([bool]0); Write-Host 'Windows IP alias removed (persistent)'"
155+
windows: 'netsh interface ip delete address "{{interface}}" {{ip_address}}; Write-Host "Windows IP alias removed (persistent)"'
152156
command: 'sed -i "/{{interface}}:{{label}}/,+3d" /etc/network/interfaces && echo "Removed alias from /etc/network/interfaces"'
153157
skip_on_error: true
154158
args:

repository/network/reset-network.yaml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ versions:
1919
windows: 'powershell -Command "Clear-DnsClientCache; Write-Host ''DNS cache flushed''"'
2020
command: systemd-resolve --flush-caches 2>/dev/null || resolvectl flush-caches 2>/dev/null; echo "DNS cache flushed"
2121
skip_on_error: true
22+
- description: Re-enable DHCP on interface
23+
platforms:
24+
ubuntu: dhclient {{interface}} && echo "DHCP re-enabled on {{interface}}"
25+
debian: dhclient {{interface}} && echo "DHCP re-enabled on {{interface}}"
26+
centos: dhclient {{interface}} && echo "DHCP re-enabled on {{interface}}"
27+
rhel: dhclient {{interface}} && echo "DHCP re-enabled on {{interface}}"
28+
fedora: dhclient {{interface}} && echo "DHCP re-enabled on {{interface}}"
29+
arch: dhclient {{interface}} 2>/dev/null || systemctl restart systemd-networkd; echo "DHCP re-enabled on {{interface}}"
30+
alpine: udhcpc -i {{interface}} && echo "DHCP re-enabled on {{interface}}"
31+
darwin: ipconfig set {{interface}} DHCP && echo "DHCP re-enabled on {{interface}}"
32+
windows: 'netsh interface ip set address "{{interface}}" dhcp; Write-Host "DHCP re-enabled on {{interface}}"'
33+
command: dhclient {{interface}} && echo "DHCP re-enabled on {{interface}}"
34+
skip_on_error: true
35+
args:
36+
- name: interface
37+
prompt: "Enter the network interface name (e.g., eth0, ens33, Ethernet, en0)"
38+
default: "eth0"
39+
required: true
2240
- description: Release and renew IP address
2341
platforms:
2442
ubuntu: dhclient -r {{interface}} && sleep 2 && dhclient {{interface}} && echo "IP address renewed"
@@ -29,7 +47,7 @@ versions:
2947
arch: dhclient -r {{interface}} 2>/dev/null && sleep 2 && dhclient {{interface}} 2>/dev/null || (systemctl restart systemd-networkd && echo "Network service restarted")
3048
alpine: udhcpc -R -i {{interface}} && echo "IP address renewed"
3149
darwin: ipconfig set {{interface}} DHCP && echo "IP address renewed"
32-
windows: 'powershell -Command "ipconfig /release ''{{interface}}''; Start-Sleep -Seconds 2; ipconfig /renew ''{{interface}}''; Write-Host ''IP address renewed on {{interface}}''"'
50+
windows: 'ipconfig /release "{{interface}}"; Start-Sleep -Seconds 2; ipconfig /renew "{{interface}}"; Write-Host "IP address renewed on {{interface}}"'
3351
command: dhclient -r {{interface}} && sleep 2 && dhclient {{interface}} && echo "IP address renewed"
3452
skip_on_error: true
3553
args:
@@ -78,7 +96,7 @@ versions:
7896
arch: echo "=== Interface Status ===" && ip -br addr show {{interface}} && echo "" && echo "=== DNS Test ===" && nslookup google.com 2>/dev/null | head -4 && echo "" && echo "=== Connectivity ===" && ping -c 2 -W 3 8.8.8.8 && echo "Network OK"
7997
alpine: echo "=== Interface Status ===" && ip -br addr show {{interface}} && echo "" && echo "=== Connectivity ===" && ping -c 2 -W 3 8.8.8.8 && echo "Network OK"
8098
darwin: echo "=== Interface Status ===" && ifconfig {{interface}} | head -5 && echo "" && echo "=== DNS Test ===" && nslookup google.com 2>/dev/null | head -4 && echo "" && echo "=== Connectivity ===" && ping -c 2 -W 3 8.8.8.8 && echo "Network OK"
81-
windows: 'powershell -Command "$a = Get-NetAdapter ''{{interface}}''; Write-Host (''=== Interface Status ===''); Write-Host ('' Name: '' + $a.Name + '' Status: '' + $a.Status + '' Speed: '' + $a.LinkSpeed); Write-Host ''''; $ip = Get-NetIPAddress -InterfaceAlias ''{{interface}}'' -AddressFamily IPv4 -ErrorAction SilentlyContinue; Write-Host (''=== IP Configuration ===''); if ($ip) { Write-Host ('' IP: '' + $ip.IPAddress + ''/'' + $ip.PrefixLength) } else { Write-Host '' No IPv4 address assigned'' }; Write-Host ''''; Write-Host (''=== DNS Test ===''); $dns = Resolve-DnsName google.com -ErrorAction SilentlyContinue; if ($dns) { Write-Host ('' google.com -> '' + ($dns | Select-Object -First 1).IPAddress) } else { Write-Host '' DNS resolution failed'' }; Write-Host ''''; Write-Host (''=== Connectivity ===''); if (Test-Connection 8.8.8.8 -Count 2 -ErrorAction SilentlyContinue) { Write-Host '' Network OK'' } else { Write-Host '' Network FAILED - try restarting your computer'' }"'
99+
windows: 'powershell -Command "Write-Host ''=== Interface Status ===''; Get-NetAdapter ''{{interface}}'' | Format-List Name, Status, LinkSpeed; Write-Host ''=== IP Configuration ===''; Get-NetIPAddress -InterfaceAlias ''{{interface}}'' -AddressFamily IPv4 -ErrorAction SilentlyContinue | Format-List IPAddress, PrefixLength; Write-Host ''=== DNS Test ===''; nslookup google.com 2>&1 | Select-Object -First 4; Write-Host ''''; Write-Host ''=== Connectivity ===''; ping -n 2 -w 3000 8.8.8.8 | Select-Object -Last 3"'
82100
command: echo "=== Interface Status ===" && ip -br addr show {{interface}} && echo "" && echo "=== DNS Test ===" && nslookup google.com 2>/dev/null | head -4 && echo "" && echo "=== Connectivity ===" && ping -c 2 -W 3 8.8.8.8 && echo "Network OK"
83101
skip_on_error: true
84102
args:

0 commit comments

Comments
 (0)