Many of us do testing with our Windows systems which inevitably require us to change firewall settings and IP info. While Windows has given us a pretty GUI for performing these tasks, it can be cumbersome to navigate the menu options. In this post I’ll show you how creating a few icons can help you take better control of this problem.
Dealing with the Windows firewall
One of the common tasks I need to perform is disabling and enabling the Windows firewall. I sometimes need to shut it off for testing, but of course want it turned back on again if I’m connected to a potentially hostile network. This introduces the additional problem that I can never remember if I had it turned on or off the last time the system was booted.
Disabling the Windows firewall
Open up a text editor and create a file named disable-firewall.bat. Type the following line into the file:
netsh firewall set opmode disable
Now save the file and create a desktop shortcut that points to it. Whenever you double click the icon, the Windows firewall will shut down.
Enabling the Windows firewall
Open up a text editor and create a file named enable-firewall.bat. The file will contain only a single line:
netsh firewall set opmode enable
Now save the file and create a desktop shortcut that points to it. Whenever you double click the icon, the Windows firewall will turn on.
Checking the Windows firewall status
Open up a text editor and create a file named fw-status.bat. Type the following three lines into the file:
netsh firewall show state
pause
exit
Now save the file and create two shortcuts pointing to it. One on the desktop and one in your startup group. When your system first boots up, a command prompt will open showing the current state of the Windows firewall. It will then pause on the screen until you press a key. Anytime you need to check the current status, simply double click the shortcut you placed on the desktop.
Dealing with IP settings
If every network used DHCP, dealing with IP would be much easier. When we work in a lab however, we typically have to manually configure IP for communications. Obviously we can use the GUI for this, but its easy to streamline the process with a couple of shortcuts.
Manually setting a wired IP address
For the purpose of this exercise I’ll assume the IP address you want to assign is 192.168.1.10. Change this IP address as needed.
Open up a text editor and create a file named 192-168-1-10.bat. The file will contain only a single line:
netsh interface ip set address local static 192.168.1.10 255.255.255.0
Now save the file and create a desktop shortcut that points to it. When ever you double click the icon, the IP address on your wired interface will be changed.
Adding a default gateway
If there is a default gateway you need to specify, we can do that as well. Assuming the gateway is at 192.168.1.1, we would change the above command to read:
netsh interface ip set address local static 192.168.1.10 255.255.255.0 192.168.1.1 1
Specifying a DNS server
If you need to specify DNS servers, we’ll need to add a few extra lines to the batch file. Let’s build on the last example and assume we have two DNS servers, one at 10.1.1.1 and another at 172.30.1.10. In this case our batch file would contain the following:
netsh interface ip set address local static 192.168.1.10 255.255.255.0 192.168.1.1 1
netsh interface ip set dns local static 10.1.1.1
netsh interface ip set dns local static 172.30.1.10
Reverting back to DHCP
Open up a text editor and create a file named reset-dhcp.bat. The file will contain only a single line:
netsh interface ip set address local dhcp
Now save the file and create a desktop shortcut that points to it. When ever you double click the icon, Windows will look to a local DHCP server for the IP info it will use.
What if I use multiple IP addresses?
The above example works great provided you consistently use the same IP address. What if you need a bit more flexibility to change it on the fly? Luckily we can handle that problem through the use of variables.
Open up a text editor and create a file named varip.bat. The file will contain only a single line:
netsh interface ip set address local static %1 255.255.255.0
Now save the file to a directory in your path statement. The Windows directory itself is usually a good last ditch option. If you don’t know which directories are in your path, simply open a command prompt and type the command “path”. This will produce a semi-colon ( ; ) separated list of all directories in your path. This tip will not work if the file is not saved to a directory in your path statement.
Whenever you need to set your IP address simply click Start–> Run and type in:
varip 192.168.50.25
or what ever IP address you wish to use. If you commonly need to change the subnet mask, change the command to read:
netsh interface ip set address local static %1 %2
Now when you click Start–> Run you would type:
varip 192.168.50.25 255.255.255.128
or whatever IP address/subnet mask combination you wish to use.
Exec Summary
While the Windows GUI is relatively easy to navigate, it can be cumbersome for common tasks like changing IP address or firewall settings. This can easily be rectified by creating a few batch files and placing shortcuts to them on the desktop.