Controlling Network Traffic
A firewall controls incoming and outgoing network traffic based on predefined security rules. Ubuntu uses ufw (Uncomplicated Firewall) as its front-end for managing the powerful netfilter kernel module.
ufw Status
Check if the firewall is active:
bash $ sudo ufw status verbose Status: inactive
Essential Actions
-
Enabling the Firewall: bash $ sudo ufw enable
-
Setting Default Policy: Deny all incoming connections (best practice). bash $ sudo ufw default deny incoming
-
Allowing Specific Traffic (by Port): bash
Allow SSH connections on default port 22
$ sudo ufw allow 22
Allow HTTP traffic
$ sudo ufw allow http
-
Deleting Rules: bash $ sudo ufw delete allow 80