How to Change Default gateway and subnet mask in PowerShell

Welcome Forums General PowerShell Q&A How to Change Default gateway and subnet mask in PowerShell

This topic contains 3 replies, has 4 voices, and was last updated by

6 months, 1 week ago.

  • Author
  • #133770

    Topics: 1
    Replies: 0
    Points: -9
    Rank: Member


    Pretty much as the title says.

    as it is now there is no default gateway appearing in PowerShell so I guess I'm adding a new one and not changing an old one. The subnet mask needs to change from to . Should this happen automatically when the IP address gets changed or when when the default gateway gets changed?

    there doesn't seem to be a lot of info on subnet mask that's why I'm just assuming it should just change automatically. but I could be wrong


  • #133842

    Topics: 1
    Replies: 1430
    Points: 2,128
    Helping Hand
    Rank: Community Hero

    As far as I know Powershell does not need a separate IP configuration. It uses the existing IP stack of the underlying Windows. You might elaborate more in detail about the reason for your question.

  • #133893

    Topics: 0
    Replies: 78
    Points: 423
    Helping Hand
    Rank: Contributor

    When you are trying to change the IPAddress, SubnetMask/PrefixLength, DefaultGateway and DNSServer using PowerShell, that you need to add the addresses for each, it will not auto-populate.

    PS C:\> New-NetIPAddress -InterfaceIndex 12 -IPAddress -PrefixLength 24 -DefaultGateway
    PS C:\> Set-DnsClientServerAddress -InterfaceIndex 12 -ServerAddresses,
  • #133955

    Topics: 2
    Replies: 990
    Points: 1,895
    Helping Hand
    Rank: Community Hero

    If this is a corporate environment, this is normally handled by your DHCP server.
    Just do a release all on the IPAddress on the host and a renew or restart the computer.

    If you are in a workgroup, then of course you need PSRemoting setup to use the Net-* cmldets to set what you are after, but even that, you need to be on the same IPRange for your workstation and the remote host.
    If you are on your own workstation, just use the GUI to do this, unless you are saying you need to do this a lot then automation would be prudent.

The topic ‘How to Change Default gateway and subnet mask in PowerShell’ is closed to new replies.