Setting Up a Firewall with iptables on Manjaro Gnome

In this guide, I will walk you through the process of configuring a firewall on Manjaro Gnome Minimal Edition using iptables. By the end of this tutorial, your PC will be securely able to communicate with other devices over SFTP, while preventing any unsolicited inbound traffic from your local network.

Step 1: Install iptables

To begin, we must install iptables, the powerful utility that allows us to configure our firewall. This can be accomplished easily using the following command:

Step 2: Set Default Policies

Next, we’ll set the default policies for iptables. In this case, we will block all incoming and forwarded traffic, while allowing all outgoing traffic to flow freely:

Step 3: Allow Loopback Traffic

To ensure that your system can still communicate internally (i.e., within the machine itself), we must allow loopback traffic. This will enable processes to talk to each other locally without interference:

Step 4: Allow Established and Related Connections

It’s crucial to allow traffic that is part of an already established or related connection. This ensures that your firewall doesn’t block responses to outgoing requests, like those from your web browser or SFTP connections:

Step 5: Allow SFTP Outbound Connections

To enable secure file transfers over SSH, we’ll allow outbound connections on port 22 for SFTP. This will ensure that your system can establish secure connections to other machines for file sharing:

Step 6: Save the Rules

Once the rules are configured, it’s essential to save them so they persist after a reboot. Use the following command to save the configuration to a file:

Step 7: Ensure Rules Persist Across Reboots

Finally, we’ll ensure that our firewall rules are automatically loaded at boot time by creating and enabling a systemd service. This will guarantee that the rules are always applied when the system starts up.

Start by creating the service file:

Then, add the following content to the file:

After saving the file, enable and start the service with the following commands:

Using Nano for Simple Edits

For simple tasks like creating and editing configuration files, I highly recommend using the Nano text editor. Its straightforward interface and easy-to-use commands make it perfect for quick edits and small jobs. If you’d like to learn more about Nano and its features, check out my blog post here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.