To open the web server port in IPTables, execute the following command:
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
If HTTPS is used, then also:
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
To open only a particular network, for example 192.168.0.0/24:
sudo iptables -A INPUT -s 192.168.0.0/24 -p tcp -m tcp --dport 80 -j ACCEPT
You can also restrict access by the IP configuration of the web server itself, for example, as I described for Apache2 in this article – Access Control Apache2.
To set the connection limit on port 80:
iptables -A INPUT -p tcp --dport 80 -m limit --limit 50/second -j ACCEPT
To remove a rule, we’ll specify the same command, replacing -A with -D, for example:
sudo iptables -D INPUT -p tcp -m tcp --dport 80 -j ACCEPT
To view the list of rules, use the command:
sudo iptables -nvL
See also:
Configuring IPTables