หน้าเว็บ

วันพฤหัสบดีที่ 13 สิงหาคม พ.ศ. 2552

เปิด Port Windows Firewall แบบระบุ Range

บน Windows ถ้าต้องการเปิด port firewall ปกตินั้น ก็เข้าไปที่ control panel -> windows firewall
แล้วจัดการเพิ่มที่ exception แต่ปัญหาก็คือเพิ่มได้ทีละ port หรือทีละ program เท่านั้น

แต่ถ้าต้องการเพิ่มทีเดียวหลาย port หรือเพิ่มแบบเป็นช่วง port ก็สามารถทำได้เช่นกัน แต่ทำโดยใช้ script ผ่านทาง command line
1. เข้า command line (Start -> Run -> cmd)
2. สั่งคำสั่ง
for /L %i in (beginport, 1, endport)
do netsh firewall add portopening protocol %i "string"

โดย แทน beginport ด้วย หมายเลข port เริ่มต้น
endport ด้วยหมายเลข port สุดท้าย
protocol ด้วยโปรโตคอลที่ต้องการ คือ TCP หรือ UDP
string ด้วยชื่อที่ต้องการที่ให้ปรากฏใน exception ของ windows firewall
เช่น ผมต้องการเปิด port สำหรับ RPC ที่ port 5000-5100 ซึ่งใช้ TCP ก็สั่งว่า
for /L %i in (5000, 1, 5100)
do netsh firewall add portopening TCP %i "RPC %i"

เป็นต้น

ระบบที่ทดสอบ
OS: Windows Server 2003 R2

ที่มา
http://forums.techarena.in/server-networking/890789.htm

ไม่มีความคิดเห็น: