Thứ Năm, 1 tháng 1, 2009

UFW - Ucomplicated Firewall

(important note: UFW is not the firewall. UFW just configures your iptables)

Set the default policy (i.e "mostly open" vs "mostly closed")
$ sudo ufw default allow|deny
Toggle logging
$ sudo ufw logging on|off
To view log
sudo iptables -L -n | grep LOG
Turn on|off the firewall
$ sudo ufw enable|disable
To add deny|allow rules:
1. blocking|allowing a port
$ sudo ufw deny|allow port <port number>
2. blocking|allowing an ip address
$ sudo ufw deny|allow from <ip address>
3. blocking|allowing a specific ip address and port
$ sudo ufw deny|allow from <ipaddress> to port <port number>
4. advanced deny example for denying|allowing access from an ip address range 10.120.0.1 - 10.120.0.255 for SSH port 22
$ sudo ufw deny|allow from 10.0.0.1/24 to any port 22
5. you want to block access to port 22 from 192.168.0.1 and 192.168.0.7 but allow all other 192.168.0.x IPs to have access to port 22
$ sudo ufw deny from 192.168.0.1 to any port 22
$ sudo ufw deny from 192.168.0.7 to any port 22
$ sudo ufw allow from 192.168.0.0/24 to any port 22

if you do the allow statement before either of the deny statements it will be matched first and the deny will not be evaluated.

Full PF-style syntax
$ sudo ufw allow|deny [proto <protocol>] [from <address> [port <port>]] [to <address> [port <port>]]
Accept or drop incoming packets to <service> (can see what services are available with 'status' (see below)). <service> can be specified via service name in etc/services, 'protocol:port', or via package meta-data. 'allow' adds service entry to /etc/ufw/maps and 'deny' removes service entry from /etc/ufw/maps. Basic syntax:
$ sudo ufw allow|deny <service>
Display status of firewall and open ports
$ sudo ufw status
External packages will add application profiles to /etc/ufw/applications.d that describe the service. File will use .INI format, will support pipe-separated values for port/protocol combinations, and multiple entries per file. The 'ports' syntax is the same as for the ufw CLI (eg '80', '22/tcp', '80,8080:8088/tcp'), but must be numeric. The example below is the content of /etc/ufw/applications.d/samba
[Samba]
title=LanManager-like file and printer server for Unix
description=The Samba software suite is a collection of programs that implements the SMB/CIFS protocol for unix systems, allowing you to serve files and printers to Windows, NT, OS/2 and DOS clients. This protocol is sometimes also referred to as the LanManager or NetBIOS protocol.
ports=137,138/udp|139,445/tcp


References
Ubuntu Wiki: https://wiki.ubuntu.com/UbuntuFirewall
Ubuntu Forum: http://ubuntuforums.org/showthread.php?t=823741
GUI for ufw available: http://gufw.tuxfamily.org/

Không có nhận xét nào:

Đăng nhận xét