How to configure network connection IP and DNS with script

The following commands are to be ran in administrator command prompt.

  • To change IP, the command syntax is::

netsh interface ip set address "interface name" "dhcp/static" "IPv4 address" "IPv4 mask" "gateway IPv4 address"

Let say, my local IP 10.0.0.5, gateway 10.0.0.1, subnet mask 255.0.0.0, the command will be::

netsh interface ip set address "Ethernet" static 10.0.0.5 255.0.0.0 10.0.0.1

  • To change DNS, the command syntax is::

netsh int ipv4 add dnsserver "interface name" "DNS IPv4 address" "index=integer" "yes/no"

Let say, my DNS servers will be 208.67.222.222 and 208.67.220.220, the command will be::

netsh int ipv4 add dnsserver "Ethernet" address=208.67.222.222 index=1 netsh int ipv4 add dnsserver "Ethernet" address=208.67.220.220 index=2