How to Install Iptables on CentOS 8
Choose a different version or distribution
Introduction
Before, we begin talking about the steps to install iptables on CentOS 8. First, let's understand - What are Iptables?
Iptables is a user-space utility program used to configure the Net-filter firewall rules in the Linux kernel. It provides a flexible and powerful firewall solution to control network traffic on CentOS 8.
In this tutorial, you will install Iptables on CentOS 8. We will also answer a few FAQs related to Iptables installation.
Advantages of Using iptables on CentOS 8
- Firewall Security: iptables provides a robust firewall solution to secure your CentOS 8 system from unauthorized access and network threats. It allows you to define security rules based on IP addresses, ports, protocols, and connection states.
- Network Traffic Control: With iptables, you can control network traffic by allowing or blocking specific connections or ports. This enables you to customize inbound and outbound traffic, enhancing network security and performance.
- Port Forwarding and Network Address Translation (NAT): iptables allows you to perform port forwarding and network address translation, enabling you to redirect incoming connections to different ports or internal network destinations.
- Flexible Rule Management: iptables provides a flexible syntax and rule management system, allowing you to create and manage complex firewall configurations efficiently. It offers various target and match options to match packets and apply specific actions.
- Compatibility with existing iptables Configurations: Although CentOS 8 uses nftables by default, iptables can still be used in compatibility mode to leverage existing iptables configurations and scripts. This makes it easier to migrate from older systems or maintain consistency between different deployments.
Prerequisites
1) Make sure, to log in as a user with the sudo privileges.
Step 1 – Disabling the FirewallD
1) Firstly, you need to type the below command, it will stop the FirewallD service, by:
sudo systemctl stop firewalld
2) After that, disable the FirewallD service to start automatically on system boot using the following command:
sudo systemctl disable firewalld
3) Then, you will need to mask the FirewallD service, which prevents it from being started by other services:
sudo systemctl mask --now firewalld
Step 2 – Installing and Enabling Iptables
1) Continue to run the below command, and it will install iptables-service
the package from the CentOS repositories:
sudo yum install iptables-services
2) After, installing the package, start the Iptables services using the following command:
sudo systemctl start iptables
sudo systemctl start ip6tables
3) After that, enable the Iptables service. It then starts automatically on system boot by:
sudo systemctl enable iptables
sudo systemctl enable ip6tables
4) Proceed to check the Iptables service status, by:
sudo systemctl status iptables
sudo systemctl status ip6tables
5) You can check the current Iptables rules using the below command:
sudo iptables -nvL
sudo ip6tables -nvL
Now, by default, only the SSH port 22 is open. The output will look like this:
Output
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
5400 6736K ACCEPT all -- * * 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
0 0 ACCEPT icmp -- * * 0.0.0.0/0 0.0.0.0/0
2 148 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0
3 180 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:22
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
0 0 REJECT all -- * * 0.0.0.0/0 0.0.0.0/0 reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT 4298 packets, 295K bytes)
pkts bytes target prot opt in out source destination
Now, you have successfully enabled the Iptables service and can start building your firewall. The changes will remain as is after a reboot.
FAQs to Install Iptables on CentOS 8
What is Iptables and why should I install it on CentOS 8?
Iptables is a firewall management tool that is used to configure and manage firewall rules on CentOS 8. It is important to install Iptables on CentOS 8 to protect your system from network attacks and security threats.
How do I check if Iptables is already installed on my CentOS 8 system?
You can check if Iptables is already installed on your CentOS 8 system by using the iptables --version
command.
How do I enable Iptables on CentOS 8 after installation?
You can enable Iptables on CentOS 8 by using the "systemctl enable iptables" command.
How do I check if Iptables is working properly on my CentOS 8 system?
You can check if Iptables is working properly on your CentOS 8 system by using the iptables -L
command to list the current firewall rules.
Are there any alternatives to Iptables for firewall configuration on CentOS 8?
Yes, there are other firewall management tools such as Firewalld and UFW that can be used as alternatives to Iptables on CentOS 8. However, Iptables remains a popular and reliable choice for firewall configuration on Linux systems.
Can I still use iptables on CentOS 8?
Yes, even though CentOS 8 uses nftables, you can still use iptables on CentOS 8 by installing the iptables compatibility package.
How do I start and enable the iptables service?
After installing iptables, you can start and enable the iptables.service by running the following commands:
sudo systemctl start iptables
sudo systemctl enable iptables
Conclusion
We hope this detailed tutorial helped you to Install Iptables on CentOS 8.
If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.