Windows Firewall (Tường lửa) của Windows có thể được bật/tắt từ command line bằng chỉ huy netsh
.
Windows 10/Windows 8/Windows 7/Server 2008/Vista:
Hãy xem cú pháp của netsh advfirewall
để cấu hình tường lửa trên các phiên bản Windows này. Cài đặt tường lửa khác nhau cho từng mạng trong 3 mạng (Domain, private, public). Vì vậy, dựa trên tường lửa mạng nào bạn muốn bật/tắt, lệnh sẽ hiển thị khác nhau.
Bạn có thể bật tường lửa cho cấu hình mạng hiện tại (không quan trọng nếu đó là domain/private/public network) bằng lệnh dưới đây.
netsh advfirewall set currentprofile state on
Tắt tường lửa cho cấu hình hiện tại:
netsh advfirewall set currentprofile state off
Các lệnh này phải được chạy từ Command prompt (as Administrator). Nếu không, bạn sẽ gặp lỗi dưới đây.
C:\>netsh advfirewall set currentprofile state on
The requested operation requires elevation (Run as administrator).
Để bật/tắt tường lửa cho một cấu hình mạng cụ thể, bạn có thể sử dụng các lệnh dưới đây.
Domain network
Bật tường lửa Domain:
netsh advfirewall set domainprofile state on
Tắt tường lửa Domain:
netsh advfirewall set domainprofile state off
Private network
Bật tường lửa private network:
netsh advfirewall set privateprofile state on
Tắt tường lửa private network:
netsh advfirewall set privateprofile state off
Public network
Bật tường lửa public network:
netsh advfirewall set publicprofile state on
Tắt tường lửa public network:
netsh advfirewall set publicprofile state off
Định cấu hình cho tất cả các mạng
Bật tường lửa cho tất cả các mạng
netsh advfirewall set allprofiles state on
Tắt tường lửa cho tất cả các mạng
netsh advfirewall set allprofiles state off
Các phiên bản Windows cũ hơn – XP/Server 2003:
Dưới đây là lệnh bật tường lửa.
netsh firewall set opmode mode=ENABLE
Lệnh để tắt tường lửa là:
netsh firewall set opmode mode=DISABLE
Đặc quyền của quản trị viên (Administrator) được yêu cầu để định cấu hình tường lửa để lệnh trên chỉ có thể được chạy từ tài khoản quản trị.
netsh firewall
không được dùng trong các phiên bản mới.
Trong Windows 10/8/7/Vista/Server 2008, lệnh ‘netsh firewall‘ được hiển thị như thông báo dưới đây.
c:\>netsh firewall set opmode mode=ENABLE IMPORTANT: "netsh firewall" is deprecated;
use "netsh advfirewall firewall" instead. Though the command still works, it's preferable to use the new set of commands provided with netsh command.