빨간 네모 부분 LOG에 패킷, 바이트가 0 이 아니면 이쪽으로 향하는 길 잃은 영혼(패킷-_-)이 존재 한다는 겁니다.
dmesg 명령어로 LOG를 확인하고 출발지, 목적이 IP, PORT, prot 등을 확인하여 규칙을 추가하여 줍시다.
위 내역에서 숫자가 발생한 부분은 각각 패킷, 데이터가 얼마나 흘렀는지를 알 수 있는 부분이며, 0 은 아직 한번도 이 쪽 규칙을 타지 않았음을 나타냅니다. (한참 지켜보고 필요없다 싶으면 제거할 수도 있겠죠? ㅎㅎ)
#!/bin/bash # Haebi's iptables script # http://haebi.kr, http://haebi.net # based on # https://gist.github.com/thomasfr/9712418 # Check iptables status # sudo iptables -L -n -v --line-numbers IPT="/sbin/iptables" # Your DNS servers you use: cat /etc/resolv.conf DNS_SERVER=" 8.8.4.4 8.8.8.8 " # Service List (TCP) # ----------------------- # 22 SSH # 80 Web # 443 Web (HTTPS) # 1194 OpenVPN #1 # 1196 OpenVPN #2 # 3306 MySQL # 21 FTP (Command) # 50000:51000 FTP (Data) # 137:139 SAMBA # 445 SAMBA ALLOW_INPUT_PORT_TCP=" 22 80 443 1194 1196 3306 21 50000:51000 137:139 445 " # Service List (UDP) # ----------------------- # 53 DNS # 137:139 SAMBA # 8649 ganglia ALLOW_INPUT_PORT_UDP=" 53 137:139 8649 " # Allow outgoing access ALLOW_OUTPUT_ADDR=" 172.17.10.0/24 " # Allow outgoing TCP # 22 ssh connect other server ALLOW_OUTPUT_PORT_TCP=" 22 " # Allow outgoing UDP # 123 ntp syncs ALLOW_OUTPUT_PORT_UDP=" 123 " $IPT -P INPUT ACCEPT $IPT -F # Allowing DNS lookups (tcp, udp port 53) to server for ip in $DNS_SERVER do $IPT -A OUTPUT -p udp -d $ip --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT $IPT -A INPUT -p udp -s $ip --sport 53 -m state --state ESTABLISHED -j ACCEPT $IPT -A OUTPUT -p tcp -d $ip --dport 53 -m state --state NEW,ESTABLISHED -j ACCEPT $IPT -A INPUT -p tcp -s $ip --sport 53 -m state --state ESTABLISHED -j ACCEPT done # Allow any connection from this host. $IPT -A INPUT -i lo -j ACCEPT $IPT -A OUTPUT -o lo -j ACCEPT # Allow all broadcast traffic. iptables -A INPUT -m pkttype --pkt-type broadcast -j ACCEPT # Open Incoming TCP Ports for PORT in $ALLOW_INPUT_PORT_TCP do $IPT -A INPUT -p tcp --dport $PORT -m state --state NEW,ESTABLISHED -j ACCEPT $IPT -A OUTPUT -p tcp --sport $PORT -m state --state ESTABLISHED -j ACCEPT done # Open Incoming UDP Ports for PORT in $ALLOW_INPUT_PORT_UDP do $IPT -A INPUT -p udp --dport $PORT -m state --state NEW,ESTABLISHED -j ACCEPT $IPT -A OUTPUT -p udp --sport $PORT -m state --state ESTABLISHED -j ACCEPT done # Allow out going access for ip in $ALLOW_OUTPUT_ADDR do $IPT -A OUTPUT -d $ip -m state --state NEW,ESTABLISHED -j ACCEPT $IPT -A INPUT -s $ip -m state --state ESTABLISHED -j ACCEPT done # Allow out going TCP access for port in $ALLOW_OUTPUT_PORT_TCP do $IPT -A OUTPUT -p tcp --dport $port -m state --state NEW,ESTABLISHED -j ACCEPT $IPT -A INPUT -p tcp --sport $port -m state --state ESTABLISHED -j ACCEPT done # Allow out going UDP access for port in $ALLOW_OUTPUT_PORT_UDP do $IPT -A OUTPUT -p udp --dport $port -m state --state NEW,ESTABLISHED -j ACCEPT $IPT -A INPUT -p udp --sport $port -m state --state ESTABLISHED -j ACCEPT done ####################################################################################################### ## Global iptable rules. Not IP specific # Allow outgoing icmp connections (pings,...)" $IPT -A OUTPUT -p icmp -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT $IPT -A INPUT -p icmp -m state --state ESTABLISHED,RELATED -j ACCEPT # Simple Service Discovery Protocol $IPT -A INPUT -p udp --dport 1900 -d 239.255.255.250 --state NEW -j ACCEPT # Multicast address # 224.0.0.1 The All Hosts multicast group addresses all hosts on the same network segment. $IPT -A INPUT -d 224.0.0.1 -j ACCEPT # 224.0.0.22 Internet Group Management Protocol $IPT -A OUTPUT -d 224.0.0.22 -j ACCEPT # Device discovery $IPT -A INPUT -d 239.255.255.250 -j ACCEPT $IPT -A OUTPUT -d 239.255.255.250 -j ACCEPT # Default ----------------------------------------------------------------- iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT # Log before dropping $IPT -A INPUT -j LOG -m limit --limit 5/min --log-level 7 --log-prefix 'IP INPUT drop: ' $IPT -A OUTPUT -j LOG -m limit --limit 5/min --log-level 7 --log-prefix 'IP OUTPUT drop: ' # If forward drop then NAT Masquerade will not work. $IPT -P INPUT DROP #$IPT -P FORWARD DROP $IPT -P OUTPUT DROP $IPT -nL # NAT --------------------------------------------------------------------- $IPT -t nat -F $IPT -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE $IPT -t nat -A POSTROUTING -s 10.8.2.0/24 -d 172.17.10.0/24 -o eth0 -j MASQUERADE $IPT -t nat -nL