I am trying to provision an EC2 instance with multiple secondary IP address attached to ENI (for IIS binding). After the EC2 instance is provisioned, I would like to execute a powershell script that assigns the current IP as the static IP address and assign the remaining IP address as secondary IP addresses. For this to happen, we have to disable DCHP.
I am trying to automate the entire process that is outlined in the below link
https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/config-windows-multiple-ip.html
I am stuck in step 1 (Static IP addressing). I have tried using New-NetIPAddress cmdlet to assign the current IP but it fails stating that the IP address already exists.
New-NetIPAddress -AddressFamily IPv4 -IPAddress x.x.x.x -PrefixLength 22 -DefaultGateway x.x.x.x -InterfaceIndex 3
I have tried disabling DHCP using Set-NetIPAddress but If I do that, I lose RDP connectivity to the machine.
Note that this can however be achieved manually, as specified in the url above.
Is there any way to automate step 1 (in the link) using powershell?
CodePudding user response:
I am not sure about powershell but I was able to achieve this using netsh command
netsh interface ip set address name="Ethernet0" static <ipaddr> <subnet> <default gateway>