Sakura VPS iptables Configuration ~ The day a warning arrived "We have detected traffic from your server that appears to be a UDP Flood DoS directed at external hosts." ~
It looks like the server is being used as a stepping stone to attack external hosts, so unless I take countermeasures, they will shut it down.
That was the gist of it.
As a countermeasure, I reinstalled the OS and then configured iptables as follows.
Configuration Steps
Run the following with root privileges.
1
su -
Allow established connections
1
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
Allow the local loopback address
1
iptables -A INPUT -i lo -j ACCEPT
Allow ICMP
1
iptables -A INPUT -p icmp -j ACCEPT
Deny private IP addresses
1 2 3 4 5 6
iptables -A INPUT -s 10.0.0.0/8 -j DROP iptables -A INPUT -d 10.0.0.0/8 -j DROP iptables -A INPUT -s 172.16.0.0/12 -j DROP iptables -A INPUT -d 172.16.0.0/12 -j DROP iptables -A INPUT -s 192.168.0.0/16 -j DROP iptables -A INPUT -d 192.168.0.0/16 -j DROP
Deny broadcast addresses
1 2
iptables -A INPUT -d 0.0.0.0/8 -j DROP iptables -A INPUT -d 255.255.255.255 -j DROP
Protect against fragment packet attacks
1
iptables -A INPUT -f -j DROP
Block stealth scans
1
iptables -A INPUT -p tcp -m state --state NEW ! --syn -j DROP
iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD DROP
Verify the configuration
1
iptables -L --line-numbers -n
Save and apply the configuration
1 2
service iptables save service iptables restart
Summary
Since applying these settings, I haven’t run into any particular problems.
A friend’s Sakura VPS was hit by the same kind of attack, and when I shared these settings, the attacks stopped for them too.
So I believe they have a certain amount of effect.
##Command summary
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT iptables -A INPUT -i lo -j ACCEPT iptables -A INPUT -p icmp -j ACCEPT iptables -A INPUT -s 10.0.0.0/8 -j DROP iptables -A INPUT -d 10.0.0.0/8 -j DROP iptables -A INPUT -s 172.16.0.0/12 -j DROP iptables -A INPUT -d 172.16.0.0/12 -j DROP iptables -A INPUT -s 192.168.0.0/16 -j DROP iptables -A INPUT -d 192.168.0.0/16 -j DROP iptables -A INPUT -d 0.0.0.0/8 -j DROP iptables -A INPUT -d 255.255.255.255 -j DROP iptables -A INPUT -f -j DROP iptables -A INPUT -p tcp -m state --state NEW ! --syn -j DROP iptables -A INPUT -p tcp --dport 113 -j REJECT --reject-with tcp-reset iptables -A INPUT -p icmp --icmp-type echo-request -m hashlimit --hashlimit 1/s --hashlimit-burst 5 --hashlimit-mode srcip --hashlimit-name input_icmp --hashlimit-htable-expire 300000 -j DROP
iptables -P INPUT DROP iptables -P OUTPUT ACCEPT iptables -P FORWARD DROP
1 2
service iptables save service iptables restart
Sakura VPS iptables Configuration ~ The day a warning arrived "We have detected traffic from your server that appears to be a UDP Flood DoS directed at external hosts." ~