Analysis of applicable firewalls on Linux servers

Source: Internet
Author: User
Article Title: Firewall Analysis for Linux servers. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
#! /Bin/bash
Echo-e "\ t \ 033 [1; 31 m RainLow firewall \ 033 [m server version 1.0rc1 -- 09/24/2004 \ n"
Echo-e "#################################### ########################"
Echo-e "This software may be used and distributed according"
Echo-e "the terms of the GNU General Public License (GPL) provided"
Echo-e "credit is given to the original author ."
Echo-e "\ t \ 033 [1; 31 m Copyright (c) 2004 rainlow \ 033 [m \ n"
Echo-e "\ t All rights reserved \ n"
Echo-e "#################################### ########################"
  
# Now begins the firewall
Echo-e "\ n \ t Welcome to \ 033 [3; 31 m Rainlow Firewall \ 033 [0 m \ n"
Echo-e "\ t \ 033 [1; 32 m http://www.rainlow.com \ 033 [m \ n"
  
  
PATH =/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
./Etc/init. d/functions
  
Exit_failure ()
{
Echo-en "\ t \ 033 [3; 031 m [FAILED] \ 033 [0 m \ n"
Echo-en "\ 033 [3; 031 m-> FATAL: $ FAILURE \ 033 [0 m \ n"
Echo-en "\ 033 [3; 031 m-> ** ABORTED **. \ 033 [0 m \ n"
Exit 1
}
  
Check_root ()
{
ROOT_ID = 0
Echo "Checking if you are root ...."
If ["$ UID" = "$ ROOT_ID"]
Then
Echo-e "\ n \ t OK! Continue... \ n"
Echo-e "\"
Else
Echo-e "Sorry, you are not root and not permitted to do this option... \ n"
Echo-e "\"
FAILURE = "you can not run this command, you must be root to do this"
Exit_failure
  
Fi
}
  
Check_enviroment ()
{
Echo-e "\ t \ 033 [1; 31 m Now Checking software envrioment \ 033 [m \ n"
  
OS = 'uname-S'
_ OS = $ OS
If ["$ _ OS "! = "Linux"]; then
FAILURE = "Sorry this version can only work under linux"
Exit_failure
Else
Echo-en "\ t \ 033 [1; 32 m PASS \ 033 [m \ n"
Fi
  
KERNELMAJ = 'uname-r | sed-e's ,\..*,,''
KERNELMIN = 'uname-r | sed-e's, [^ \.] * \., '-e's ,\..*,,''
  
If ["$ KERNELMAJ"-lt 2]; then
FAILURE = "Sorry you kernel is too old, please upgrade it first! "
Exit_failure
Fi
If ["$ KERNELMAJ"-eq 2-a "$ KERNELMIN"-lt 4]; then
FAILURE = "only kernel greater than 2.4 is supported"
Exit_failure
Fi
  
If ('iptables-V 2> & 1 | grep-c "Command not found" '); then
  
FAILURE = "can not find iptables command you must install iptables first"
Exit_failure
Fi
  
If! ('Which modprobe 2> & 1 | grep-c "which: no modprobe in" ') & ([-a/proc/modules] |! [-A/proc/version]); then
If ('lsmod | grep-c "ipchains" '); then
Rmmod ipchains>/dev/null 2> & 1
Fi
Fi
  
}
  
Wait ()
{
Echo | awk '{printf "|", $1 }'
For x in 'seq 1 10 ';
Do
Sleep 1
Echo "#" | awk '{printf "% s", $1 }'
Done
  
Echo-en "\ n"
}
  
Iptables ()
{
/Sbin/iptables "$ @"
}
  
Mp ()
{
/Sbin/modprobe "$ @"
}
  
Load_module ()
{
If [-e/lib/modules/'uname-R'/kernel/net/ipv4/netfilter/ip_tables.o]
Then
Echo-e "\ n \ tLoading iptables modules please wait ...."
Mp ip_tables
Mp ipt_LOG
Mp ipt_owner
Mp ipt_MASQURADE
Mp ipt_REJECT
Mp ipt_conntrack_ftp
Mp ipt_conntrack_irc
Mp iptable_filter
Mp iptable_nat
Mp iptable_mangle
Mp ip_conntrack
Mp ipt_limit
Mp ipt_state
Mp ipt_unclean
Mp ipt_TCPMSS
Mp ipt_TOS
Mp ipt_TTL
Mp ipt_quota
Mp ipt_iplimit
Mp ipt_pkttype
Mp ipt_ipv4options
Mp ipt_MARK
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Else
Echo-e "\ tSorry, no iptables modules found !! "
Fi
}
  
Ip_stack_adjust ()
{
If [-e/proc/sys/net/ipv4/ip_forward]
  
Then
Echo-e "enable ip_forward.please wait ...."
Echo 0>/proc/sys/net/ipv4/ip_forward
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/ip_default_ttl]
  
Then
Echo-e "changing default ttl ...."
Echo 88>/proc/sys/net/ipv4/ip_default_ttl
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
Echo-e "\ n \ t disable dynamic ip support ...."
Echo 0>/proc/sys/net/ipv4/ip_dynaddr
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
  
If [-e/proc/sys/net/ipv4/ip_no_pmtu_disc]
  
Then
Echo-e "disable path mtu discovery. please wait ...."
Echo 0>/proc/sys/net/ipv4/ip_no_pmtu_disc
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
  
If [-e/proc/sys/net/ipv4/ipfrag_high_thresh]
  
Then
Echo-e "changing ipfrag_high_thresh.please wait ...."
Echo 5800>/proc/sys/net/ipv4/ipfrag_high_thresh
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/ipfrag_low_thresh]
  
Then
Echo-e "changing ipfrag_low_thresh.please wait ...."
Echo 2048>/proc/sys/net/ipv4/ipfrag_low_thresh
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/ipfrag_time]
  
Then
Echo-e "changing ipfrag_low_thresh.please wait ...."
Echo 20>/proc/sys/net/ipv4/ipfrag_time
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/ipfrag_secret_interval]
  
Then
Echo-e "changing ipfrag_secret_interval.please wait ...."
Echo 600>/proc/sys/net/ipv4/ipfrag_secret_interval
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/tcp_syn_retries]
  
Then
Echo-e "changing tcp_syn_retries.please wait ...."
Echo 4>/proc/sys/net/ipv4/tcp_syn_retries
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/tcp_synack_retries]
  
Then
Echo-e "changing tcp_synack_retries.please wait ...."
Echo 4>/proc/sys/net/ipv4/tcp_synack_retries
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/tcp_keepalive_time]
  
Then
Echo-e "changing tcp_keepalive_time.please wait ...."
Echo 300 & gt;/proc/sys/net/ipv4/tcp_keepalive_time
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/tcp_keepalive_probes]
  
Then
Echo-e "changing tcp_keepalive_probes.please wait ...."
Echo 4>/proc/sys/net/ipv4/tcp_keepalive_probes
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/tcp_keepalive_intvl]
  
Then
Echo-e "changing tcp_keepalive_intvl.please wait ...."
Echo 60>/proc/sys/net/ipv4/tcp_keepalive_intvl
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
If [-e/proc/sys/net/ipv4/tcp_retries1]
  
Then
Echo-e "changing tcp_retriest.please wait ...."
Echo 3>/proc/sys/net/ipv4/tcp_retries1
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
  
If [-e/proc/sys/net/ipv4/tcp_retries2]
  
Then
Echo-e "changing tcp_retriest.please wait ...."
Echo 15>/proc/sys/net/ipv4/tcp_retries2
Echo-e "\ t \ 033 [3; 032 m [OK] \ 033 [0m \ n"
Fi
  
If [-e/proc/sys/net/ipv4/tcp_orphan_retries]
  
Then
Echo-e "disable tcp

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.