61.Linux2008. 12. 1. 13:12
반응형
쉘스크립 을 통한 리눅스 웹서버 보안 코드

cat LinuxKernelCustom.sh

-----------------------------------
#!/bin/sh
#
# apache Optimizer
#

IPADDR="`/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/.*://'`"


# Usage : [IPADDR] is system ip address include
       
case "$1" in
        start)
        echo -n "Starting ${IPADDR} TCP.IP Network Optimize..........................";
        echo;
        echo;
        # 브로드캐스트(Broadcast) 요청에 반응하지 않도록 설정
        eval 'sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1';
       
        # SyncFlooding 공격대응
        eval 'sysctl -w net.ipv4.tcp_max_syn_backlog=1280';
        eval 'sysctl -w net.ipv4.tcp_syncookies=1';
        # Proxy ARP 미설정
        eval 'sysctl -w net.ipv4.conf.eth0.proxy_arp=0';
        eval 'sysctl -w net.ipv4.conf.lo.proxy_arp=0';
        eval 'sysctl -w net.ipv4.conf.default.proxy_arp=0';
        eval 'sysctl -w net.ipv4.conf.all.proxy_arp=0';


        # TCP SYN Cookie 방어 설정
        eval 'sysctl -w net.ipv4.tcp_syncookies=1';


        # ICMP 리다렉트(REDIRECT) 차단 설정
        eval 'sysctl -w net.ipv4.conf.all.accept_redirects=0';
        eval 'sysctl -w net.ipv4.conf.lo.accept_redirects=0';
        eval 'sysctl -w net.ipv4.conf.eth0.accept_redirects=0';
        eval 'sysctl -w net.ipv4.conf.default.accept_redirects=0';


        # 부적합한 오류 메세지 로그기록 설정
        eval 'sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1';


        # IP 스푸칭(SPOOFING) 차단 설정
        eval 'sysctl -w net.ipv4.conf.all.rp_filter=1';
        eval 'sysctl -w net.ipv4.conf.lo.rp_filter=1';
        eval 'sysctl -w net.ipv4.conf.eth0.rp_filter=1';
        eval 'sysctl -w net.ipv4.conf.default.rp_filter=1';
       
        # 소스 라우팅(source routing) 패킷 거부 설정
        eval 'sysctl -w net.ipv4.conf.all.accept_source_route=0';
        eval 'sysctl -w net.ipv4.conf.lo.accept_source_route=0';
        eval 'sysctl -w net.ipv4.conf.eth0.accept_source_route=0';
        eval 'sysctl -w net.ipv4.conf.default.accept_source_route=0';


        # 스푸핑, 소스 라우팅 및 리다이렉트 패킷 로그기록 설정
        eval 'sysctl -w net.ipv4.conf.all.log_martians=1';
        eval 'sysctl -w net.ipv4.conf.lo.log_martians=1';
        eval 'sysctl -w net.ipv4.conf.eth0.log_martians=1';
        eval 'sysctl -w net.ipv4.conf.default.log_martians=1';


        # TCP/IP 네트워크 최적화
        eval 'sysctl -w net.ipv4.tcp_fin_timeout=30';
        eval 'sysctl -w net.ipv4.tcp_keepalive_time=180';
        eval 'sysctl -w net.ipv4.tcp_window_scaling=0';
        eval 'sysctl -w net.ipv4.tcp_sack=0';
        eval 'sysctl -w net.ipv4.tcp_timestamps=0';


        # BUFFER-SPACE 최적화 (RAM 2GB 이상일 경우)
        eval 'sysctl -w net.ipv4.tcp_mem=100000000';
        eval 'sysctl -w net.ipv4.tcp_wmem=100000000';
        eval 'sysctl -w net.ipv4.tcp_rmem=30000000';


        # BUFFER-SIZE 최적화 (RAM 2GB 이상일 경우)
        eval 'sysctl -w net.core.rmem_max=10485760';
        eval 'sysctl -w net.core.rmem_default=10485760';
        eval 'sysctl -w net.core.wmem_max=10485760';
        eval 'sysctl -w net.core.wmem_default=10485760';

        # TCP_MAX_BUCKETS 설정 (RAM 2GB 이상일 경우)
        eval 'sysctl -w net.ipv4.tcp_max_tw_buckets=2000000';


        # IP_LOCAL_PORT_RANGE 설정
       #eval 'sysctl -w net.ipv4.ip_local_port_range=32768 61000';


        # IPFRAG_HIGH_THRESH IPFRAG_LOW_THRESH 설정 (RAM 2GB 이상일 경우)
        eval 'sysctl -w net.ipv4.ipfrag_high_thresh=2069496';
        eval 'sysctl -w net.ipv4.ipfrag_low_thresh=2019432';


        # OPTMEM_MAX HOT_LIST_LENGTH 설정 (RAM 2GB 이상일 경우)
        eval 'sysctl -w net.core.optmem_max=10000000';
        #eval 'sysctl -w net.core.hot_list_length=102400';
        #
        ;;
        status)
        sysctl -a
        ;;
        *)
        echo "Usage: apache_optimizer.sh {start|status}"
        exit 1;
esac;
echo;
echo "......Done";
exit 0;

---------------------------------------------------------

chmod 700 LinuxKernelCustom.sh


./LinuxKernelCustom.sh start

./LinuxKernelCustom.sh status ->확인

Posted by 1010