I will be adding and removing entries to the script below automatically (adding ports 80/443 with different IP addresses). If I run this script, I am "assuming" that connections will be uninterrupted, unless however I remove an IP. Am I correct in this thought?
Here is my script:
iptables --flush
iptables -A INPUT -i eth0 -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp --dport ssh -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -s 1.2.3.4 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -s 1.2.3.4 -j ACCEP
iptables -A INPUT -p tcp --dport 80 -j DROPT
iptables -A INPUT -p tcp --dport 443 -j DROP
iptables -A INPUT -j DROP
iptables -A OUTPUT -j ACCEPT
iptables -A INPUT -j LOG
iptables -A INPUT -j REJECT
There are several methods to add new rules to current chains. For example;
You should write a shell script that reads ip addresses in a file and inserts them to chain.
You should save current rules to a file and add rules directly inside file and restore rules from this file again.
after editing iptables.rules with any text editor you should duplicate any line and change the source ip address.
After editing file you should restore rules by
In conclusion;