How to Allow web traffic in iptables in linux (Redhat/CentOS/Oracle linux/Amzon Linux2)
How to Allow web traffic in iptables in linux
This article describes how to configure your iptables
software firewall to allow web traffic on port 80 (HTTP) and port 443 (HTTPS).
Prerequisites
You need to have the following prerequisites:
- Basic understanding of Secure Shell (SSH)
- Sudo or administrative access to your server
Log in to your server by using SSH and then complete the steps in the following sections for your preferred setup method.
One-liner command
Use the following one-line command to open the open the firewall ports:
Individual commands
If you prefer to configure the software firewall by using discrete steps instead of by using the one-line command, perform the following steps:
Run the following command to allow traffic on port 80:
# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
DROP all -- ip-127-0-0-0.ec2.internal/8 anywhere
ACCEPT tcp -- anywhere anywhere state ESTABLISHED
ACCEPT udp -- anywhere anywhere state ESTABLISHED
ACCEPT icmp -- anywhere anywhere state ESTABLISHED
# iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:http
ACCEPT tcp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
DROP all -- ip-127-0-0-0.ec2.internal/8 anywhere
ACCEPT tcp -- anywhere anywhere state ESTABLISHED
Run the following command to allow traffic on port 443:
Run the following command to save the
iptables
rules:
After you complete the preceding steps, you have configured configured your server to allow HTTP and HTTPS web traffic through your iptables
firewall. If you’ve configured your website to accept traffic on ports 80 and 443, you should be able to visit both the HTTP and HTTPS versions of your website.
No comments