×
Community Blog How to Configure Iptables on ECS Debian Server?

How to Configure Iptables on ECS Debian Server?

This article explains how to configure Iptables on ECS Debian Server.

Iptables is a Linux kernel firewall that can be used to manage network traffic by setting up rules and policies. Here's how to configure Iptables on ECS Debian Server:

1.  Update the package repository and install Iptables:

sudo apt update
sudo apt install iptables

2.  Create a new Iptables rule file:

sudo touch /etc/iptables-rules

3.  Open the Iptables rule file with a text editor:

sudo nano /etc/iptables-rules

4.  Add the rules for incoming and outgoing traffic:

*filter
# Allow all outgoing traffic
-A OUTPUT -j ACCEPT

# Allow incoming SSH traffic
-A INPUT -p tcp --dport ssh -j ACCEPT

# Allow incoming HTTP and HTTPS traffic
-A INPUT -p tcp --dport http -j ACCEPT
-A INPUT -p tcp --dport https -j ACCEPT

# Block all other incoming traffic
-A INPUT -j DROP
COMMIT

These rules allow all outgoing traffic and incoming SSH, HTTP, and HTTPS traffic, but block all other incoming traffic.

5.  Save and close the Iptables rule file.

6.  Enable Iptables at boot time:

sudo touch /etc/network/if-pre-up.d/iptables
sudo chmod +x /etc/network/if-pre-up.d/iptables
sudo nano /etc/network/if-pre-up.d/iptables

7.  Add the following content to the iptables file:

#!/bin/sh
iptables-restore < /etc/iptables-rules
exit 0

8.  Save and close the iptables file.

9.  Restart the network service:

Restart the network service:

Now, Iptables is configured on your ECS Debian server. You can verify the Iptables rules by running the following command:

sudo iptables -L

This will show you the list of rules that have been applied to your system. If you want to modify the rules, you can edit the /etc/iptables-rules file and then run the following command to apply the changes:

sudo iptables-restore < /etc/iptables-rules

Note: Be careful when configuring Iptables, as incorrect rules can block all incoming and outgoing traffic, which can result in loss of connectivity to your server.

0 2 1
Share on

Dikky Ryan Pratama

61 posts | 14 followers

You may also like

Comments

Dikky Ryan Pratama

61 posts | 14 followers

Related Products