Skip to content

Instantly share code, notes, and snippets.

@secondfry
Last active November 1, 2019 13:47
Show Gist options
  • Save secondfry/bf1fe797c4dc95b3a80a7083dd528acf to your computer and use it in GitHub Desktop.
Save secondfry/bf1fe797c4dc95b3a80a7083dd528acf to your computer and use it in GitHub Desktop.
Probably my default iptables config
#!/bin/bash
### Читаем:
### https://wiki.archlinux.org/index.php/Simple_stateful_firewall
### https://www.booleanworld.com/depth-guide-iptables-linux-firewall/
### https://javapipe.com/blog/iptables-ddos-protection/
### Подготовка.
# ulogd!
echo '>> Checking ulogd presense'
systemctl status ulogd
if [ $? -ne 0 ]; then
echo '!! Install ulogd'
exit 1
fi
echo '>> ulogd present, checking if it is active'
systemctl is-active --quiet ulogd
if [ $? -ne 0 ]; then
echo '>> It is not active, trying to start it'
systemctl start ulogd
if [ $? -ne 0 ]; then
echo '!! Failed to start inactive ulogd'
exit 1
fi
echo '>> ulogd is active (...now)'
else
echo '>> ulogd is active'
fi
# SSH
echo '>> Detecting SSH configuration'
SSH_PORT_LINE=$(grep -E "^Port" /etc/ssh/sshd_config)
if [ $? -ne 0 ]; then
echo '!! You must move SSH from default port'
exit 1
fi
SSH_PORT=$(echo $SSH_PORT_LINE | awk '{print $2}')
# Сохраняем правила в файл.
echo '>> Saving current iptables rules to /root/'
iptables-save > /root/`date +%Y%m%d%H%M%S`-iptables-before.rules
# Удаляем все правила и чистим полностью таблицы filter, raw и mangle.
echo '>> Cleaning iptables'
iptables -F
iptables -X
iptables -t raw -F
iptables -t raw -X
iptables -t mangle -F
iptables -t mangle -X
### Первым делом настраиваем filter таблицу.
echo '>> Working...'
# Создаем два новых чейна для проверки TCP и UDP пакетов.
iptables -N TCP
iptables -N UDP
# По умолчанию, дропаем все FORWARD реквесты, ибо мы не nat сервер.
iptables -P FORWARD DROP
# По умолчанию, разрешаем все наши OUTPUT пакеты.
iptables -P OUTPUT ACCEPT
# Разрешаем весь трафик по локалхосту.
iptables -A INPUT -i lo -j ACCEPT
# Запрещаем ping flood...
iptables -N _LD_PING_FLOOD
iptables -A INPUT -p icmp --icmp-type 8 -m recent --set --name ICMP-PING
iptables -A INPUT -p icmp --icmp-type 8 -m recent --update --name ICMP-PING --seconds 2 --hitcount 5 -m comment --comment "ICMP Ping Flood" -j _LD_PING_FLOOD
iptables -A _LD_PING_FLOOD -m limit --limit 10/min -j NFLOG --nflog-prefix "ICMP Ping Flood drop"
iptables -A _LD_PING_FLOOD -m limit --limit 10/min -j NFLOG --nflog-prefix "ICMP Ping Flood drop" --nflog-group 1
iptables -A _LD_PING_FLOOD -j DROP
# ...и разрешаем сам ping.
iptables -A INPUT -p icmp --icmp-type 8 -m conntrack --ctstate NEW -j ACCEPT
# Разрешаем уже установленные сессии.
iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# По умолчанию, дропаем все INPUT пакеты.
iptables -P INPUT DROP
# Все новые (state SYN) TCP подключения перенаправляем в таблицу TCP.
iptables -A INPUT -p tcp --syn -m conntrack --ctstate NEW -j TCP
# Подготовка к TCP Portscan
iptables -N _LD_TCP_PORTSCAN
iptables -A _LD_TCP_PORTSCAN -m limit --limit 10/min -j NFLOG --nflog-prefix "TCP Portscan reject"
iptables -A _LD_TCP_PORTSCAN -m limit --limit 10/min -j NFLOG --nflog-prefix "TCP Portscan reject" --nflog-group 1
iptables -A _LD_TCP_PORTSCAN -p tcp -j REJECT --reject-with tcp-reset
# Все TCP подключения по закрытым портам помечаем как порт сканеров и реджектим.
iptables -A INPUT -p tcp -m recent --set --name TCP-PORTSCAN -j _LD_TCP_PORTSCAN
# Все повторные TCP подключения оттуда обновляет timestamp скана и реджектятся на месте.
iptables -I TCP -p tcp -m recent --update --seconds 60 --name TCP-PORTSCAN -j _LD_TCP_PORTSCAN
# Все новые UDP подключения перенаправляем в таблицу UDP.
iptables -A INPUT -p udp -m conntrack --ctstate NEW -j UDP
# Подготовка к UDP Portscan
iptables -N _LD_UDP_PORTSCAN
iptables -A _LD_UDP_PORTSCAN -m limit --limit 10/min -j NFLOG --nflog-prefix "UDP Portscan reject"
iptables -A _LD_UDP_PORTSCAN -m limit --limit 10/min -j NFLOG --nflog-prefix "UDP Portscan reject" --nflog-group 1
iptables -A _LD_UDP_PORTSCAN -p udp -j REJECT --reject-with icmp-port-unreachable
# Все UDP подключения по закрытым портам помечаем как порт сканеров и реджектим.
iptables -A INPUT -p udp -m recent --set --name UDP-PORTSCAN -j _LD_UDP_PORTSCAN
# Все повторные UDP подключения оттуда обновляет timestamp скана и реджектятся на месте.
iptables -I UDP -p udp -m recent --update --seconds 60 --name UDP-PORTSCAN -j _LD_UDP_PORTSCAN
### Теперь настраиваем raw таблицу. Она вызывается первой, на уровне NIC и позволяет рано отбрасывать пакеты.
# Пропускаем дальше весь трафик по локалхосту.
iptables -t raw -A PREROUTING -i lo -j ACCEPT
iptables -t mangle -I PREROUTING -i lo -j ACCEPT
# Дропаем совсем все фрагментированные пакеты.
iptables -t raw -N _LD_FRAG_FLOOD
iptables -t raw -A PREROUTING -f -m comment --comment "Fragmentation Flood" -j _LD_FRAG_FLOOD
iptables -t raw -A _LD_FRAG_FLOOD -m limit --limit 10/min -j NFLOG --nflog-prefix "Fragmentation Flood drop"
iptables -t raw -A _LD_FRAG_FLOOD -m limit --limit 10/min -j NFLOG --nflog-prefix "Fragmentation Flood drop" --nflog-group 1
iptables -t raw -A _LD_FRAG_FLOOD -j DROP
# Reverse Path filter test
iptables -t raw -N _LD_RPFILTER
iptables -t raw -A PREROUTING -m rpfilter --invert -j _LD_RPFILTER
iptables -t raw -A _LD_RPFILTER -m limit --limit 10/minute -j NFLOG --nflog-prefix "rpfilter drop"
iptables -t raw -A _LD_RPFILTER -m limit --limit 10/minute -j NFLOG --nflog-prefix "rpfilter drop" --nflog-group 1
iptables -t raw -A _LD_RPFILTER -j DROP
# Дропаем все пакеты классического DNS Amplification (он льется с 53 порта).
# Но обычный DNS трафик льется оттуда же! Как же быть?
# Есть на выбор conntrack или хитрость.
# Хитрость – если запрос делали мы, то из внешки трафик будет литься нам на эфемерные порты.
EPHEMEREAL_START=$(cat /proc/sys/net/ipv4/ip_local_port_range | awk '{print $1}')
EPHEMEREAL_END=$(cat /proc/sys/net/ipv4/ip_local_port_range | awk '{print $2}')
iptables -t raw -N _LD_DNS_AMP
iptables -t raw -A PREROUTING -p udp --sport 53 ! --dport $EPHEMEREAL_START:$EPHEMEREAL_END -m comment --comment "DNS Amplification" -j _LD_DNS_AMP
iptables -t raw -A _LD_DNS_AMP -m limit --limit 10/min -j NFLOG --nflog-prefix "DNS Amplification drop"
iptables -t raw -A _LD_DNS_AMP -m limit --limit 10/min -j NFLOG --nflog-prefix "DNS Amplification drop" --nflog-group 1
iptables -t raw -A _LD_DNS_AMP -j DROP
# Дропаем все пакеты классического LDAP Amplification (он льется с 389 порта).
iptables -t raw -N _LD_LDAP_AMP
iptables -t raw -A PREROUTING -p udp --sport 389 -m comment --comment "LDAP Amplification" -j _LD_LDAP_AMP
iptables -t raw -A _LD_LDAP_AMP -m limit --limit 10/min -j NFLOG --nflog-prefix "LDAP Amplification drop"
iptables -t raw -A _LD_LDAP_AMP -m limit --limit 10/min -j NFLOG --nflog-prefix "LDAP Amplification drop" --nflog-group 1
iptables -t raw -A _LD_LDAP_AMP -j DROP
# Дропаем все пакеты классического SSDP Amplification (он льется с 1900 порта).
iptables -t raw -N _LD_SSDP_AMP
iptables -t raw -A PREROUTING -p udp --sport 1900 -m comment --comment "SSDP Amplification" -j _LD_SSDP_AMP
iptables -t raw -A _LD_SSDP_AMP -m limit --limit 10/min -j NFLOG --nflog-prefix "SSDP Amplification drop"
iptables -t raw -A _LD_SSDP_AMP -m limit --limit 10/min -j NFLOG --nflog-prefix "SSDP Amplification drop" --nflog-group 1
iptables -t raw -A _LD_SSDP_AMP -j DROP
# Проверяем спуфинг
iptables -t raw -N SPOOFING
iptables -t raw -N _LD_SPOOFING
iptables -t raw -A PREROUTING -j SPOOFING
iptables -t raw -A SPOOFING -s 224.0.0.0/3 -j _LD_SPOOFING
iptables -t raw -A SPOOFING -s 169.254.0.0/16 -j _LD_SPOOFING
iptables -t raw -A SPOOFING -s 172.16.0.0/12 -j _LD_SPOOFING
iptables -t raw -A SPOOFING -s 192.0.2.0/24 -j _LD_SPOOFING
iptables -t raw -A SPOOFING -s 192.168.0.0/16 -j _LD_SPOOFING
iptables -t raw -A SPOOFING -s 10.0.0.0/8 -j _LD_SPOOFING
iptables -t raw -A SPOOFING -s 0.0.0.0/8 -j _LD_SPOOFING
iptables -t raw -A SPOOFING -s 240.0.0.0/5 -j _LD_SPOOFING
iptables -t raw -A SPOOFING -s 127.0.0.0/8 -j _LD_SPOOFING
iptables -t raw -A SPOOFING -j RETURN
iptables -t raw -A _LD_SPOOFING -m limit --limit 10/min -j NFLOG --nflog-prefix "Spoofing drop"
iptables -t raw -A _LD_SPOOFING -m limit --limit 10/min -j NFLOG --nflog-prefix "Spoofing drop" --nflog-group 1
iptables -t raw -A _LD_SPOOFING -j DROP
## Финальные штрихи
# Дропаем весь инвалидный трафик (инвалидность определяется некорректными заголовками).
iptables -t mangle -N _LD_INVALID
iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j _LD_INVALID
iptables -t mangle -A _LD_INVALID -m limit --limit 10/min -j NFLOG --nflog-prefix "ctstate INVALID drop"
iptables -t mangle -A _LD_INVALID -m limit --limit 10/min -j NFLOG --nflog-prefix "ctstate INVALID drop" --nflog-group 1
iptables -t mangle -A _LD_INVALID -j DROP
# Пропускаем tcp и udp трафик.
iptables -t raw -A PREROUTING -p tcp -j ACCEPT
iptables -t raw -A PREROUTING -p udp -j ACCEPT
# Пропускаем icmp ping.
iptables -t raw -A PREROUTING -p icmp --icmp-type 8 -j ACCEPT
# Дропаем все остальное (вместо reject в INPUT).
iptables -t raw -A PREROUTING -m limit --limit 10/min -j NFLOG --nflog-prefix "Weird Protocol drop"
iptables -t raw -A PREROUTING -m limit --limit 10/min -j NFLOG --nflog-prefix "Weird Protocol drop" --nflog-group 1
iptables -t raw -P PREROUTING DROP
### Здесь разрешаем подключения по определенным портам.
echo '>> Main part done!'
echo '>> Now fancy stuff :)'
echo -n '>> Allowing incoming SSH (TCP '
echo -n $SSH_PORT
echo ')'
iptables -A TCP -p tcp --dport $SSH_PORT -j ACCEPT
echo '>> Allowing incoming DNS (UDP 53)'
iptables -A UDP -p udp --dport 53 -j ACCEPT
PREV_IFS=$IFS
IFS=' '
echo '>> Enter ports separated by spaces (i.e. `80 443`) to be allowed in TCP chain'
echo -n '< '
read PORTS_TCP
for port in "${PORTS_TCP[@]}"; do
echo -n 'iptables -A TCP -p tcp --dport '
echo -n $port
echo ' -j ACCEPT'
iptables -A TCP -p tcp --dport $port -j ACCEPT
done
echo '>> Enter ports separated by spaces (i.e. `7777`) to be allowed in UDP chain'
echo -n '< '
read PORTS_UDP
for port in "${PORTS_UDP[@]}"; do
echo -n 'iptables -A UDP -p udp --dport '
echo -n $port
echo ' -j ACCEPT'
iptables -A UDP -p udp --dport $port -j ACCEPT
done
IFS=$PREV_IFS
### Ранее было так.
###
### # Разрешаем подключение по указанному порту TCP (твой_новый_ssh_порт). Не 22. SSH обязательно переместить с этого порта (/etc/ssh/sshd_config)
### iptables -A TCP -p tcp --dport твой_новый_ssh_порт -j ACCEPT
###
### # Разрешаем подключение по указанному порту UDP (DNS трафик).
### iptables -A UDP -p udp --dport 53 -j ACCEPT
###
### # Разрешаем подключение по указанному порту UDP (твой_порт_игрового_сервера).
### iptables -A UDP -p udp --dport твой_порт_игрового_сервера -j ACCEPT
### Послесловие.
# Сохраняем правила в файл.
echo '>> Saving current iptables rules to /root/'
iptables-save > /root/`date +%Y%m%d%H%M%S`-iptables-after.rules
echo '>> iptables -nvL'
iptables -nvL
echo '>> iptables -nvL -t raw'
iptables -nvL -t raw
echo '>> We are done!'
#!/bin/bash
### Читаем:
### https://wiki.archlinux.org/index.php/Simple_stateful_firewall
### https://www.booleanworld.com/depth-guide-iptables-linux-firewall/
### https://javapipe.com/blog/iptables-ddos-protection/
### Подготовка.
# SSH
echo '>> Detecting SSH configuration'
SSH_PORT_LINE=$(grep -E "^Port" /etc/ssh/sshd_config)
if [ $? -ne 0 ]; then
echo '!! You must move SSH from default port'
exit 1
fi
SSH_PORT=$(echo $SSH_PORT_LINE | awk '{print $2}')
# Сохраняем правила в файл.
echo '>> Saving current iptables rules to /root/'
iptables-save > /root/`date +%Y%m%d%H%M%S`-iptables-before.rules
# Удаляем все правила и чистим полностью таблицы filter, raw и mangle.
echo '>> Cleaning iptables'
iptables -F
iptables -X
iptables -t raw -F
iptables -t raw -X
iptables -t mangle -F
iptables -t mangle -X
### Первым делом настраиваем filter таблицу.
echo '>> Working...'
# Создаем два новых чейна для проверки TCP и UDP пакетов.
iptables -N TCP
iptables -N UDP
# По умолчанию, дропаем все FORWARD реквесты, ибо мы не nat сервер.
iptables -P FORWARD DROP
# По умолчанию, разрешаем все наши OUTPUT пакеты.
iptables -P OUTPUT ACCEPT
# Разрешаем весь трафик по локалхосту.
iptables -A INPUT -i lo -j ACCEPT
# Запрещаем ping flood...
iptables -A INPUT -p icmp --icmp-type 8 -m recent --set --name ICMP-PING
iptables -A INPUT -p icmp --icmp-type 8 -m recent --update --name ICMP-PING --seconds 2 --hitcount 5 -m comment --comment "ICMP Ping Flood" -j DROP
# ...и разрешаем сам ping.
iptables -A INPUT -p icmp --icmp-type 8 -m conntrack --ctstate NEW -j ACCEPT
# Разрешаем уже установленные сессии.
iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
# По умолчанию, дропаем все INPUT пакеты.
iptables -P INPUT DROP
# Все новые (state SYN) TCP подключения перенаправляем в таблицу TCP.
iptables -A INPUT -p tcp --syn -m conntrack --ctstate NEW -j TCP
# Все TCP подключения по закрытым портам помечаем как порт сканеров и реджектим.
iptables -A INPUT -p tcp -m recent --set --name TCP-PORTSCAN -j REJECT --reject-with tcp-reset
# Все повторные TCP подключения оттуда обновляет timestamp скана и реджектятся на месте.
iptables -I TCP -p tcp -m recent --update --seconds 60 --name TCP-PORTSCAN -j REJECT --reject-with tcp-reset
# Все новые UDP подключения перенаправляем в таблицу UDP.
iptables -A INPUT -p udp -m conntrack --ctstate NEW -j UDP
# Все UDP подключения по закрытым портам помечаем как порт сканеров и реджектим.
iptables -A INPUT -p udp -m recent --set --name UDP-PORTSCAN -j REJECT --reject-with icmp-port-unreachable
# Все повторные UDP подключения оттуда обновляет timestamp скана и реджектятся на месте.
iptables -I UDP -p udp -m recent --update --seconds 60 --name UDP-PORTSCAN -j REJECT --reject-with icmp-port-unreachable
### Теперь настраиваем raw таблицу. Она вызывается первой, на уровне NIC и позволяет рано отбрасывать пакеты.
# Пропускаем дальше весь трафик по локалхосту.
iptables -t raw -A PREROUTING -i lo -j ACCEPT
iptables -t mangle -I PREROUTING -i lo -j ACCEPT
# Дропаем совсем все фрагментированные пакеты.
iptables -t raw -A PREROUTING -f -m comment --comment "Fragmentation Flood" -j DROP
# Reverse Path filter test
iptables -t raw -A PREROUTING -m rpfilter --invert -j DROP
# Дропаем все пакеты классического DNS Amplification (он льется с 53 порта).
# Но обычный DNS трафик льется оттуда же! Как же быть?
# Есть на выбор conntrack или хитрость.
# Хитрость – если запрос делали мы, то из внешки трафик будет литься нам на эфемерные порты.
EPHEMEREAL_START=$(cat /proc/sys/net/ipv4/ip_local_port_range | awk '{print $1}')
EPHEMEREAL_END=$(cat /proc/sys/net/ipv4/ip_local_port_range | awk '{print $2}')
iptables -t raw -A PREROUTING -p udp --sport 53 ! --dport $EPHEMEREAL_START:$EPHEMEREAL_END -m comment --comment "DNS Amplification" -j DROP
# Дропаем все пакеты классического LDAP Amplification (он льется с 389 порта).
iptables -t raw -A PREROUTING -p udp --sport 389 -m comment --comment "LDAP Amplification" -j DROP
# Дропаем все пакеты классического SSDP Amplification (он льется с 1900 порта).
iptables -t raw -A PREROUTING -p udp --sport 1900 -m comment --comment "SSDP Amplification" -j DROP
# Проверяем спуфинг
iptables -t raw -N SPOOFING
iptables -t raw -A PREROUTING -j SPOOFING
iptables -t raw -A SPOOFING -s 224.0.0.0/3 -j DROP
iptables -t raw -A SPOOFING -s 169.254.0.0/16 -j DROP
iptables -t raw -A SPOOFING -s 172.16.0.0/12 -j DROP
iptables -t raw -A SPOOFING -s 192.0.2.0/24 -j DROP
iptables -t raw -A SPOOFING -s 192.168.0.0/16 -j DROP
iptables -t raw -A SPOOFING -s 10.0.0.0/8 -j DROP
iptables -t raw -A SPOOFING -s 0.0.0.0/8 -j DROP
iptables -t raw -A SPOOFING -s 240.0.0.0/5 -j DROP
iptables -t raw -A SPOOFING -s 127.0.0.0/8 -j DROP
iptables -t raw -A SPOOFING -j RETURN
## Финальные штрихи
# Дропаем весь инвалидный трафик (инвалидность определяется некорректными заголовками).
iptables -t mangle -A PREROUTING -m conntrack --ctstate INVALID -j DROP
# Пропускаем tcp и udp трафик.
iptables -t raw -A PREROUTING -p tcp -j ACCEPT
iptables -t raw -A PREROUTING -p udp -j ACCEPT
# Пропускаем icmp ping.
iptables -t raw -A PREROUTING -p icmp --icmp-type 8 -j ACCEPT
# Дропаем все остальное (вместо reject в INPUT).
iptables -t raw -P PREROUTING DROP
### Здесь разрешаем подключения по определенным портам.
echo '>> Main part done!'
echo '>> Now fancy stuff :)'
echo -n '>> Allowing incoming SSH (TCP '
echo -n $SSH_PORT
echo ')'
iptables -A TCP -p tcp --dport $SSH_PORT -j ACCEPT
echo '>> Allowing incoming DNS (UDP 53)'
iptables -A UDP -p udp --dport 53 -j ACCEPT
PREV_IFS=$IFS
IFS=' '
echo '>> Enter ports separated by spaces (i.e. `22 80 443`) to be allowed in TCP chain'
echo -n '< '
read PORTS_TCP
for port in "${PORTS_TCP[@]}"; do
echo -n 'iptables -A TCP -p tcp --dport '
echo -n $port
echo ' -j ACCEPT'
iptables -A TCP -p tcp --dport $port -j ACCEPT
done
echo '>> Enter ports separated by spaces (i.e. `53 7777`) to be allowed in UDP chain'
echo -n '< '
read PORTS_UDP
for port in "${PORTS_UDP[@]}"; do
echo -n 'iptables -A UDP -p udp --dport '
echo -n $port
echo ' -j ACCEPT'
iptables -A UDP -p udp --dport $port -j ACCEPT
done
IFS=$PREV_IFS
### Ранее было так.
###
### # Разрешаем подключение по указанному порту TCP (твой_новый_ssh_порт). Не 22. SSH обязательно переместить с этого порта (/etc/ssh/sshd_config)
### iptables -A TCP -p tcp --dport твой_новый_ssh_порт -j ACCEPT
###
### # Разрешаем подключение по указанному порту UDP (DNS трафик).
### iptables -A UDP -p udp --dport 53 -j ACCEPT
###
### # Разрешаем подключение по указанному порту UDP (твой_порт_игрового_сервера).
### iptables -A UDP -p udp --dport твой_порт_игрового_сервера -j ACCEPT
### Послесловие.
# Сохраняем правила в файл.
echo '>> Saving current iptables rules to /root/'
iptables-save > /root/`date +%Y%m%d%H%M%S`-iptables-after.rules
echo '>> iptables -nvL'
iptables -nvL
echo '>> iptables -nvL -t raw'
iptables -nvL -t raw
echo '>> We are done!'
# https://javapipe.com/blog/iptables-ddos-protection/
kernel.printk = 4 4 1 7
kernel.panic = 10
kernel.core_uses_pid = 1
kernel.msgmnb = 65536
kernel.msgmax = 65536
vm.swappiness = 20
vm.dirty_ratio = 80
vm.dirty_background_ratio = 5
fs.file-max = 2097152
net.core.netdev_max_backlog = 262144
net.core.rmem_default = 31457280
net.core.rmem_max = 67108864
net.core.wmem_default = 31457280
net.core.wmem_max = 67108864
net.core.somaxconn = 65535
net.core.optmem_max = 25165824
net.ipv4.neigh.default.gc_thresh1 = 4096
net.ipv4.neigh.default.gc_thresh2 = 8192
net.ipv4.neigh.default.gc_thresh3 = 16384
net.ipv4.neigh.default.gc_interval = 5
net.ipv4.neigh.default.gc_stale_time = 120
net.netfilter.nf_conntrack_max = 10000000
net.netfilter.nf_conntrack_tcp_loose = 0
net.netfilter.nf_conntrack_tcp_timeout_established = 1800
net.netfilter.nf_conntrack_tcp_timeout_close = 10
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 10
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 20
net.netfilter.nf_conntrack_tcp_timeout_last_ack = 20
net.netfilter.nf_conntrack_tcp_timeout_syn_recv = 20
net.netfilter.nf_conntrack_tcp_timeout_syn_sent = 20
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 10
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.ip_no_pmtu_disc = 1
net.ipv4.route.flush = 1
net.ipv4.route.max_size = 8048576
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.icmp_ignore_bogus_error_responses = 1
net.ipv4.tcp_congestion_control = htcp
net.ipv4.tcp_mem = 65536 131072 262144
net.ipv4.udp_mem = 65536 131072 262144
net.ipv4.tcp_rmem = 4096 87380 33554432
net.ipv4.udp_rmem_min = 16384
net.ipv4.tcp_wmem = 4096 87380 33554432
net.ipv4.udp_wmem_min = 16384
net.ipv4.tcp_max_tw_buckets = 1440000
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_max_orphans = 400000
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_rfc1337 = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_fack = 1
net.ipv4.tcp_ecn = 2
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_intvl = 60
net.ipv4.tcp_keepalive_probes = 10
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.ip_forward = 0
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.rp_filter = 1
## Хм...
# kernel.sysrq = 0
# kernel.shmmax = 4294967296
# kernel.shmall = 4194304
# net.ipv4.ip_local_port_range = 1024 65000
## Может так, все-таки, лучше?..
kernel.sysrq = 176
kernel.shmmax = 18446744073692774399
kernel.shmall = 18446744073692774399
net.ipv4.ip_local_port_range = 32768 60999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment