Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Managing Firewall Ports on Linux with iptables, firewalld, and ufw

Tech May 13 1

Managing Ports on CentOS

Control the firewalld service daemon:

# Activate the firewall service
systemctl start firewalld.service

# Deactivate the firewall service
systemctl stop firewalld.service

# Check current service status
systemctl status firewalld

Using iptables (CentOS/RHEL 6)

To permit traffic on ports 80 and 443:

iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -p tcp --dport 443 -j ACCEPT
service iptables save

List the current filterign rules:

iptables -L -n

Using firewalld (CentOS/RHEL 7+)

Add permanent rules for specific ports and reload the configuration:

# Open port 80
firewall-cmd --zone=public --permanent --add-port=80/tcp

# Open port 443
firewall-cmd --zone=public --permanent --add-port=443/tcp

# Apply changes
firewall-cmd --reload

Utility commands for firewalld:

# Check if the firewall is active
firewall-cmd --state

# List all currently open ports
firewall-cmd --list-ports

# List available zones
firewall-cmd --get-zones

# Manage services (example with ftp)
firewall-cmd --query-service ftp
firewall-cmd --add-service=ftp --permanent
firewall-cmd --remove-service=ftp --permanent

Managing Ports on Ubuntu and Debian

Using ufw (Uncomplicated Firewall)

Check the current status of the firewall:

sudo ufw status verbose

Alow traffic on ports 80 and 443:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload

Common ufw operational commands:

# Enable the firewall
sudo ufw enable

# Disable the firewall
sudo ufw disable

# Reset all rules to default
sudo ufw reset

# Deny specific traffic
sudo ufw deny 22/tcp
Tags: Linux

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.