Search This Blog

Sunday, July 29, 2012

learning some new tricks

When configuring my network interfaces i usually use netsh to configure them. When being accustomed to using netsh it is pretty simple. To find the name of your interfaces you would use "netsh int ip show interfaces." To configure the ip addresses you would use the following syntax "Netsh Int Ip set address "local area connection" static 10.10.10.1 255.255.255.0 10.10.10.254 10. Adding DNS servers would be done with the following Synctax: Netsh int ip set dnsserver "Local Area Connection" static 10.10.10.10, adding a dns could be done by netsh int ip add dnsserver "Local Area Connection" 10.10.10.20.


Now i was playing with Windows Server 2012, and wanted to challenge myself into configuring the interface through powershell. I guessed it was possible as I saw some NetIP commandlets in previous encounters. 


The first thing i did was trying to find the right cmdlets, the best to search them i used following synctax:
Get-Command "Set*NetIP*" 
This gave me a few hints to continue my search: In the same manner as with NETSH i need to find out the name of the interface i am willing to configure. Set-NetIpInterface, suggest that there would also exist an Get-NetIpInterface cmdlet. Putting my thinking into practice showed me the configured interfaces on the server.
Get-NetIpInteface
 This showed that the interface we are trying to configure is called "Ethernet", the second cmdlet we where interested in was the Set-NetIPAddress cmdlet. Now we need to find out how we link the IpAddess that is specified in the Set-NetIpAddress is linked to the correct interface. To Find out i checked the help file of the Set-NetIpAddress: Get-Help "Set-NetIpaddress"
 This showed me the new-netipaddress cmdlet, which led me to the following string:
New-NetIpAddress -Ipaddress 192.168.0.3 -DefaultGateway 192.168.0.254 -InterfaceAlias Ethernet -AddressFamily IPv4 -PrefixLength 24
The new-NetIpAddress Cmdlet does not allow DNS or WINS to be set. Setting the DNS server would be done by the Set-DNSClientServerAddress cmdlet.
To set the DNS server we need to have the Interface Index number of the interface where we want to link the DNS servers settings to. The interface index number is shown by the Get-NetIpInterface cmdlet.
Setting the DNS Server is done with following Syntax:
Set-DNSClientServerAddress -Address IP First Server, IP Second Server -InterfaceIndex 'Indexnumber'

To Check your configuration afterwards you can use Get-netipconfiguration -InterfaceAlias Ethernet | fl
For all the netsh diehards, netsh still runs under Windows Server 2012.

No comments:

Post a Comment