Can iptables drop automatically an established output session after certain seconds e.g. 30 sec. since its launch? But I want to restrict it only for destination port 80 and 443. The purpose is to drop unused established tcp connections belonging to some working applications e.g. Chrome, Teamviewer. I tried with recent and limit modules but without success. May be IPTables haven't function to restrict connection by its duration or I don't know something?
I already read some related topics: https://stackoverflow.com/questions/20327518/need-to-drop-established-connections-with-iptables
iptables - dropping specific established connections after X hours
And so on.
Could you help me with some script or application, please? May be there is no way to do it with IPT?
My home table:
Can iptables drop automatically an established output session after certain seconds e.g. 30 sec. since its launch? But I want to restrict it only for destination port 80 and 443. The purpose is to drop unused established tcp connections belonging to some working applications e.g. Chrome, Teamviewer. I tried with recent and limit modules but without success. May be IPTables haven't function to restrict connection by its duration or I don't know something?
I already read some related topics: https://stackoverflow.com/questions/20327518/need-to-drop-established-connections-with-iptables
iptables - dropping specific established connections after X hours
And so on.
Could you help me with some script or application, please? May be there is no way to do it with IPT?
My home table:
echo Kernel modules
#
modprobe ip_conntrack
modprobe ip_conntrack_ftp
################################################################################
echo Reset iptables
#
iptables -F
iptables -F -t nat
iptables -F -t raw
iptables -F -t mangle
iptables -X
iptables -X -t nat
iptables -X -t raw
iptables -X -t mangle
iptables -Z
iptables -Z -t nat
iptables -Z -t raw
iptables -Z -t mangle
################################################################################
echo Default policy
#
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT DROP
################################################################################
echo Logging INPUT,OUTPUT
#
iptables -A INPUT -j LOG --log-prefix="INPUT chain"
iptables -A OUTPUT -j LOG --log-prefix="OUTPUT chain"
################################################################################
echo Allow local
#
iptables -A INPUT -i lo -s 127.0.0.0/8 -j ACCEPT
iptables -A OUTPUT -o lo -d 127.0.0.0/8 -j ACCEPT
################################################################################
echo Allow icmp out
#
iptables -A OUTPUT -p icmp -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p icmp -m state --state ESTABLISHED -j ACCEPT
################################################################################
echo Allow port 53 out
#
iptables -A OUTPUT -p udp --sport 1024:65535 --dport 53 \
-m state --state NEW -j ACCEPT
iptables -A INPUT -p udp --sport 53 --dport 1024:65535 \
-m state --state ESTABLISHED -j ACCEPT
################################################################################
echo Allow ports 20,21 out
#
iptables -A OUTPUT -p tcp -m tcp --sport 1024:65535 \
--dport 21 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp -m tcp --sport 1024:65535 \
-m multiport --dports 20,1024:65535 \
-m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -m tcp -m multiport --sports 20,21,1024:65535 \
--dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
################################################################################
echo Allow ports 80,443 out
#
iptables -A OUTPUT -p tcp --sport 1024:65535 -m multiport --dports 80,443 \
-m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -m tcp -m multiport --sports 80,443 \
--dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT
################################################################################
echo Allow port 123 out
#
iptables -A OUTPUT -p udp -m udp --sport 123 \
--dport 123 -m state --state NEW -j ACCEPT
iptables -A INPUT -p udp -m udp --sport 123 \
--dport 123 -m state --state ESTABLISHED -j ACCEPT
################################################################################
#
##iptables -A INPUT -j REJECT
##iptables -A FORWARD -j REJECT
##iptables -A OUTPUT -j REJECT