I'm setting up a basic iptables firewall on a Rocky Linux-based server with kernel version 5.15.103-1. The primary requirement is to establish specific access rules for different groups of servers. The goal is to allow full access for administrative workstations and a restricted form of access for production servers while denying access for any other requests.
My firewall script currently looks like this:
K1="10.0.51.31-10.0.51.41"
K2="10.0.51.91-10.0.51.101"
ADMIN="10.0.51.21,10.0.51.22"
# Clear rules and set default policies
iptables -F
iptables -X
iptables -N admin; iptables -N prod
# ACCEPT connections initiated from host itself
iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# ACCEPT from loopback
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT ! -i lo -d 127.0.0.0/8 -j DROP
# Allow ICMP echo requests (ping) and related ICMP messages
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 0 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 3/4 -j ACCEPT
iptables -A INPUT -j admin
iptables -A INPUT -j prod
# Allow all except ssh
iptables -A prod -p tcp ! --dport 22 -m iprange --src-range $K1 -j ACCEPT
iptables -A prod -p tcp ! --dport 22 -m iprange --src-range $K2 -j ACCEPT
# Allow all
iptables -A admin -p tcp -s $ADMIN -j ACCEPT
# Log and drop all other connections
iptables -A INPUT -m limit --limit 10/sec -j LOG --log-prefix "iptables " --log-level 4
iptables -A INPUT -j LOG --log-prefix "iptables " --log-level 4
iptables -A INPUT -j DROP
This server doesn't have public interfaces, and internet access is routed through a Linux-based NAT gateway. However, I'm noticing dropped packets in the logs like,
Aug 15 14:35:50 prod2 kernel: iptables IN=em2 OUT= MAC=41:fb:72:ff:94:7e:15:f3:2b:1c:1b:b6:18:01 SRC=52.218.197.1 DST=10.0.51.153 LEN=40 TOS=0x00 PREC=0x00 TTL=237 ID=13818 DF PROTO=TCP SPT=443 DPT=8418 WINDOW=12284 RES=0x00 ACK URGP=0
This traffic is related to upload/download from S3.
These packets should only be able to reach my server through the NAT gateway, implying that they are part of a session initiated from my server. Notably, not all of these packets are being dropped, and I can successfully curl this IP address without issues.
Despite the dropped packets, I haven't encountered any other problems with the server, (download/upload to S3). I attempted to cross-reference those logs with the conntrack table and tcpdump, but I didn't achieve much success. Is there a way to further investigate and determine why these packets are being dropped, especially when they are likely part of a session initiated from my server?