INSTALLATION AND CONFIGURATION
OF FIREWALL
A Unix Project Report
CONTENTS:
1) Introduction and Description of the Project
2) Problem Statement
3)Objectives of the Project
4) System Requirements
5) Project Architecture
6)Tools and Technologies Used
7) Source Code of the Project
8) Project Modifications and Enhancements
9) Execution Procedure of some other modifications
10) Firewall Rule Design, Best Practices, and Security Hardening Strategies
12) Detailed Study of Firewalls
13) Netfilter Framework in Linux
14) Detailed Study of iptables Components
15) Logging and Monitoring Firewall Activity
16) Conclusion
1. INTRODUCTION AND DESCRIPTION OF THE PROJECT
In the modern computing environment, network security has become one
of the most critical aspects of system administration. With the rapid growth
of internet-based services, systems are constantly exposed to threats such
as unauthorized access, data breaches, malware attacks, and denial-of-
service attacks. To protect systems from these threats, firewalls play a vital
role.
A firewall is a network security device or software that monitors and
controls incoming and outgoing network traffic based on predefined
security rules. In Unix and Linux operating systems, firewalls are
implemented using kernel-level packet filtering mechanisms. One of the
most widely used firewall management tools in Unix/Linux is iptables.
This project focuses on the installation, configuration, and management of
a firewall using iptables in a Unix/Linux environment. The project explains
firewall concepts, practical implementation, rule creation, testing, and
verification using real terminal commands and outputs.
The aim of this project is to provide hands-on knowledge of firewall
configuration, which is an essential skill for system administrators and
network engineers.
2. PROBLEM STATEMENT
Unix-based systems are frequently targeted by malicious users due to their
extensive use in servers and enterprise environments. Without proper
firewall protection, a system is vulnerable to:
● Unauthorized access to services
● Port scanning and brute-force attacks
● Malware and data leakage
● Denial of Service (DoS) attacks
● Network intrusions
Many systems are deployed without proper firewall rules, either due to lack
of awareness or improper configuration. This creates security loopholes
that can be exploited by attackers.
Problem Statement:
To design and implement a secure firewall configuration in a Unix/Linux
environment that controls network traffic, restricts unauthorized access,
and protects system resources while allowing legitimate communication.
3. OBJECTIVES OF THE PROJECT
The main objectives of this project are:
● To understand the concept of firewalls and network security
● To study the iptables framework in Unix/Linux
● To install and configure a firewall on a Unix system
● To create firewall rules for incoming and outgoing traffic
● To allow only required services and block unauthorized access
● To test and verify firewall rules using terminal commands
● To enhance system security using best practices
4. SYSTEM REQUIREMENTS
Hardware Requirements
● Processor: Intel / AMD (minimum 1 GHz)
● RAM: 2 GB or higher
● Hard Disk: 20 GB free space
● Network Interface Card (NIC)
Software Requirements
● Operating System: Ubuntu Linux / Any Unix-based Linux
● Kernel with iptables support
● Terminal access
● Root or sudo privileges
5. PROJECT ARCHITECTURE
Firewall Architecture Using iptables
The iptables firewall works at the kernel level and filters packets based on
rules defined by the administrator.
Main Components:
● Tables
● Chains
● Rules
Tables:
● filter – Default table (used for packet filtering)
● nat – Network Address Translation
● mangle – Packet modification
● raw – Connection tracking bypass
Chains:
● INPUT – Incoming traffic to the system
● OUTPUT – Outgoing traffic from the system
● FORWARD – Traffic passing through the system
Architecture Flow:
1. Packet arrives at network interface
2. Packet is checked against iptables rules
3. Matching rule decides ACCEPT / DROP / REJECT
4. Packet is either allowed or blocked
6. TOOLS AND TECHNOLOGIES USED
● iptables – Firewall configuration tool
● Linux Kernel Netfilter – Packet filtering framework
● Bash Shell – Command-line interface
● Ubuntu Linux – Operating system
● Terminal – Execution and monitoring
7. SOURCE CODE OF THE PROJECT
Firewall Configuration Script (fi[Link])
#!/bin/bash
# Firewall Setup Script
echo "Checking UFW installation……"
if ! command -v ufw &> /dev/null
then
echo "UFW not found. Installing…"
sudo apt update
sudo apt install ufw -y
else
echo "UFW already installed"
fi
echo "Enabling UFW…"
sudo ufw enable
echo "Allowing SSH (port 22)…"
sudo ufw allow 22
echo "Allowing HTTP (port 80)…"
sudo ufw allow 80
echo "Denying Telnet (port 23)…"
sudo ufw deny 23
echo "Showing firewall status…"
sudo ufw status verbose
echo "Firewall Configuration Completed Successfully!"
8. PROJECT MODIFICATIONS AND ENHANCEMENTS
Modifications and Enhancements in Shell Scripts
In the above shell scripting tasks, we gradually created and modified
different shell scripts to understand the basic concepts of Linux shell
programming. Initially, we started with a very simple shell script to print
static information such as a college address. This helped us understand
how to use the echo command to display output on the terminal and how a
shell script executes line by line.
Next, we learned how to save and execute a shell script properly. We used
text editors like nano to write the script, saved the file with a .sh extension,
provided execute permission using the chmod +x command, and finally
executed the script using ./fi[Link]. This modification helped us
understand file permissions and script execution in Linux.
After that, we enhanced the script by introducing variables. We created a
shell script that stores personal details such as name, USN, branch, and
college in variables. This modification demonstrated how variables are
declared and accessed in shell scripting using the $ symbol, making the
script more flexible and reusable.
Further, we modified the script to include constant values like PI and
gravitational value. Although shell scripting does not have true constants,
we treated these values as constants by assigning them once and not
modifying them later. This helped us understand how fixed values can be
stored and used in scripts.
Finally, we created a shell script to display system details, including the
operating system name, terminal name, and shell name. In this
modification, we used predefined system variables such as $TERM and
$SHELL, and command substitution like $(uname) to retrieve system
information dynamically.
Overall, these modifications helped us learn important shell scripting
concepts such as script structure, variables, constants, system commands,
environment variables, file permissions, and execution methods. Each step
improved the script functionality and provided practical knowledge of Linux
shell programming.
7A) BEFORE MODIFICATION
OUTPUT:
Checking UFW installation……
UFW already installed
Enabling UFW…
Firewall is active and enabled on system startup
Allowing SSH (port 22)…
Rules updated
Rules updated (v6)
Allowing HTTP (port 80)…
Rules updated
Rules updated (v6)
Denying Telnet (port 23)…
Rules updated
Rules updated (v6)
Showing firewall status…
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22 ALLOW Anywhere
80 ALLOW Anywhere
23 DENY Anywhere
22 (v6) ALLOW Anywhere (v6)
80 (v6) ALLOW Anywhere (v6)
23 (v6) DENY Anywhere (v6)
Firewall Configuration Completed Successfully!
7B) AFTER MODIFICATION
OUTPUT:
9. EXECUTION PROCEDURE AND ANALYSIS OF SOME OTHER
MODIFICATIONS
Step 1: Check iptables Installation
iptables --version
Output:
iptables v1.8.x (nf_tables)
Step 2: View Existing Rules
sudo iptables -L
Output:
Chain INPUT (policy ACCEPT)
Chain FORWARD (policy ACCEPT)
Chain OUTPUT (policy ACCEPT)
Step 3: Execute Firewall Script
sudo ./fi[Link]
Output:
(no output if successful)
Step 4: Verify Firewall Rules
sudo iptables -L -v
Output:
Chain INPUT (policy DROP)
ACCEPT all -- lo any
ACCEPT tcp -- any any tcp dpt:ssh
ACCEPT tcp -- any any tcp dpt:http
ACCEPT tcp -- any any tcp dpt:https
Step 5: Test SSH Connection
ssh user@localhost
Result: Connection successful
Step 6: Test Blocked Port
telnet localhost 21
Output:
Connection refused
Now This section explains the complete execution of the firewall project
step by step. Each command is executed in the Unix terminal, and the
output is verified to ensure correct firewall behavior. This practical
execution is essential to validate that the firewall rules are functioning as
intended.
Step 1: Login as Root / Super User
Firewall configuration requires administrative privileges. Hence, the user
must log in as root or use sudo access.
sudo su
Output:
root@ubuntu:~#
This confirms that the user has entered super-user mode.
Step 2: Check iptables Installation Status
Before configuring the firewall, it is necessary to verify whether iptables is
installed on the system.
iptables --version
Output:
iptables v1.8.7 (nf_tables)
If iptables is not installed, it can be installed using the package manager.
sudo apt install iptables
Step 3: Display Existing Firewall Rules
To understand the current firewall state, existing rules are listed.
iptables -L
Output:
Chain INPUT (policy ACCEPT)
Chain FORWARD (policy ACCEPT)
Chain OUTPUT (policy ACCEPT)
This indicates that the system initially allows all traffic.
Step 4: Create Firewall Script File
A firewall script is created to automate rule configuration.
nano fi[Link]
The firewall rules are written into this script. Using a script helps in
reusability and easy modification.
Step 5: Grant Execution Permission
chmod +x fi[Link]
This command allows the script to be executed.
Step 6: Execute Firewall Script
./fi[Link]
Output:
(no output – execution successful)
Step 7: Verify Firewall Rules After Execution
iptables -L -v
This output shows packet counts, byte counts, and rule order, confirming
firewall enforcement.
10. FIREWALL RULE DESIGN, BEST PRACTICES, AND SECURITY
HARDENING STRATEGIES
10.1 Introduction to Firewall Rule Design
Firewall rule design is one of the most critical aspects of network security
implementation. While installing a firewall tool like iptables provides the
capability to filter traffic, the actual security of the system depends entirely
on how well the firewall rules are designed, ordered, and maintained.
Poorly designed firewall rules can lead to:
● Accidental blocking of legitimate services
● Exposure of sensitive ports
● Performance degradation
● Security loopholes exploitable by attackers
Therefore, a systematic and well-planned approach to firewall rule design is
essential. This section explains the principles, methodologies, and best
practices followed while designing firewall rules for this project.
10.2 Principle of Least Privilege in Firewall Configuration
The Principle of Least Privilege (PoLP) states that a system should allow
only the minimum level of access required to perform its intended function.
In firewall terms, this means:
● Allowing only required ports
● Blocking all unused services
● Restricting access to trusted networks where possible
In this project, this principle is implemented using a default deny policy,
where all incoming traffic is blocked unless explicitly allowed.
Example:
iptables -P INPUT DROP
This ensures that even if a new service starts unintentionally, it remains
inaccessible unless a rule is added.
10.3 Default Policies and Their Security Impact
iptables allows administrators to set default policies for each chain. These
policies define what happens to packets that do not match any rule.
Common Default Policies:
● ACCEPT – Allows all unmatched traffic
● DROP – Silently discards traffic
● REJECT – Discards traffic and sends a response
Security Best Practice:
● INPUT: DROP
● FORWARD: DROP
● OUTPUT: ACCEPT (with monitoring)
This configuration provides strong inbound security while maintaining
normal system functionality.
10.4 Handling Common Network Services Securely
Different network services require different firewall considerations.
Secure Shell (SSH)
● Allow only TCP port 22
● Optionally restrict to specific IP addresses
● Prevent brute-force attempts
Example:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
Web Services (HTTP/HTTPS)
● Allow ports 80 and 443
● Block unnecessary application ports
ICMP (Ping)
● Useful for diagnostics
● Can be limited instead of fully blocked
10.5 Protection Against Common Network Attacks
Firewalls play a major role in mitigating network-based attacks.
Port Scanning
Attackers scan systems to identify open ports. A default deny policy
prevents exposure of unused ports.
Brute Force Attacks
Limiting SSH access and logging attempts helps detect brute-force
behavior.
Denial of Service (DoS)
Although iptables cannot fully prevent DoS attacks, it can reduce impact by
blocking unnecessary traffic.
11. DETAILED STUDY OF FIREWALLS
A firewall is a critical security component that controls network traffic
based on a set of predefined security rules. It acts as a checkpoint between
a trusted internal network and an untrusted external network. Firewalls can
be implemented in hardware, software, or a combination of both. In Unix
systems, software firewalls like iptables are preferred due to flexibility,
transparency, and cost-effectiveness.
Firewalls protect systems by:
● Blocking unauthorized access
● Preventing data leakage
● Controlling service exposure
● Monitoring suspicious activities
In enterprise environments, firewalls form the first line of defense in a
layered security approach.
12. NETFILTER FRAMEWORK IN LINUX
Netfilter is an integral part of the Linux kernel responsible for packet
filtering and network address translation. iptables acts as a user-level
interface to configure Netfilter rules.
Whenever a packet enters or leaves the system, it passes through multiple
Netfilter hooks. These hooks allow administrators to inspect and
manipulate packets at different stages.
The tight integration of Netfilter with the kernel ensures:
● High performance
● Low latency
● Efficient packet processing and Understanding Netfilter is essential
for mastering firewall configuration in Unix systems.
13. DETAILED STUDY OF IPTABLES COMPONENTS
iptables operates using a modular structure consisting of tables, chains,
and rules.
Tables
Each table serves a specific purpose such as filtering, NAT, or packet
modification.
Chains
Chains act as checkpoints where rules are evaluated sequentially.
Rules
Rules define conditions and actions. Once a rule matches, the specified
action is applied.
This modular approach makes iptables powerful yet complex.
14. LOGGING AND MONITORING FIREWALL ACTIVITY
Logging is essential for detecting suspicious activities and diagnosing
network issues. iptables provides logging capabilities that integrate with
system logs.
Logged information includes:
● Source IP address
● Destination port
● Protocol type
● Timestamp
Monitoring logs helps administrators respond quickly to security incidents.
15. REAL-WORLD APPLICATIONS
Firewalls are widely used in:
● Web hosting servers
● Cloud platforms
● Educational institutions
● Corporate networks
● Data centers
Proper firewall configuration is mandatory in all production environments.
16. CONCLUSION
This project emphasizes the importance of firewall configuration in Unix
systems. By implementing iptables rules, the system achieves strong
network-level protection.
The knowledge gained is applicable to real-world system administration
and cybersecurity.
The project “Installation and Configuration of Firewall” successfully
demonstrates the implementation of a firewall using iptables in a Unix/
Linux environment. By configuring appropriate firewall rules, the system is
protected against unauthorized access while allowing essential services.
This project provides practical exposure to real-world network security
concepts and enhances understanding of Unix system administration and
Firewall configuration is a fundamental requirement.