Linux firewall can be managed using iptables command. I setup tomcat with Apache webserver in front using mod_jk2. But tomcat was still accessbile from port 8080. In order to disable direct access to port 8080 I executed following command.
iptables -A INPUT -p tcp --dport 8080 -j REJECT
You can review the above rule and any other existing rules as follows;
iptables -L -n --line-numbers
Now, if later you wanted to undo or remove a rule, use the above command to figure out the line number of the rule. A sample output from the previous command looks like below;
Chain INPUT (policy DROP)
num target prot opt source destination
1 LOG tcp -- 0.0.0.0/0 0.0.0.0/0 tcp flags:!0x16/0x02 state NEW LOG flags 0 level 4 prefix `NEW NOT SYN: '
2 DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp flags:!0x16/0x02 state NEW
3 DROP tcp -- 207.46.249.190 0.0.0.0/0 tcp
4 DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:1214
5 DROP udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:1214
6 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
7 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp spt:67 dpt:68
Now, let's say you wanted to remove the rule at line number #3. It can be done as following;
iptables -R INPUT 3
For more details, look at this quick HowTo guide.
iptables -A INPUT -p tcp --dport 8080 -j REJECT
You can review the above rule and any other existing rules as follows;
iptables -L -n --line-numbers
Now, if later you wanted to undo or remove a rule, use the above command to figure out the line number of the rule. A sample output from the previous command looks like below;
Chain INPUT (policy DROP)
num target prot opt source destination
1 LOG tcp -- 0.0.0.0/0 0.0.0.0/0 tcp flags:!0x16/0x02 state NEW LOG flags 0 level 4 prefix `NEW NOT SYN: '
2 DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp flags:!0x16/0x02 state NEW
3 DROP tcp -- 207.46.249.190 0.0.0.0/0 tcp
4 DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:1214
5 DROP udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:1214
6 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
7 ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp spt:67 dpt:68
Now, let's say you wanted to remove the rule at line number #3. It can be done as following;
iptables -R INPUT 3
For more details, look at this quick HowTo guide.
Comments