3

We want to whitelist a list of IP addresses for a website running on a IIS in windows 2008 server. Since this list of IP addresses would be dynamic we would like to store that in a text file which would be updated using a web service. How do you go about this, We have to avoid any kind of manual intervention such as opening a GUI or restarting the server. We are aware how to this on Linux either via IP Tables Or through dynamically generating rules for Apache or Nginx.

Can somebody help us with this.

1 Answer 1

1

You can use PowerShell and a scheduled task to accomplish this. New firewall rules can be created with the New-NetFirewallRule Cmdlet. Your rule would probably look like this:

New-NetFirewallRule -DisplayName "name" -Direction Inbound -LocalPort 80 -Protocol TCP -RemoteAddress $IPs -Action Allow | Out-Null

You will have to put your allowed IP addresses in an array (see variable $IPs) for this to work. Of course, this part of the script depends on the layout of your text file. If your file looks like this:

8.8.8.8
8.8.4.4

Then the following code snipped should work:

$IPs = Get-Content -Path "Path\to\file.txt"
New-NetFirewallRule -DisplayName "name" -Direction Inbound -LocalPort 80 -Protocol TCP -RemoteAddress $IPs -Action Allow | Out-Null

To update the rule, you can either delete and recreate it with the net set of IP addresses using the Remove-NetFirewallRule Cmdlet, using the display name as identifier.

Remove-NetFirewallRule -DisplayName "name"

Or you can use the Set-NetFirewallRule Cmdlet to modify your existing rule with the same set of parameters.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .