工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.wdlinux.cn 注册 | 登陆
浏览模式: 标准 | 列表分类:linux

wget和curl中使用代理

 命令使用代理

wget/curl 都支持使用代理

wget -e “http_proxy=10.1.4.43:8080″  proxy.mimvp.com

curl -x 10.1.4.43:8080 proxy.mimvp.com

 

环境变量使用代理

curl、wget也支持通过环境变量http_proxy来设置要使用的代理服务器, 如下:

# 这个帐号使用的代理服务器
http_proxy=”http://mycache.mydomain.com:3128″
export http_proxy

如果代理服务器需要用户名和密码,只要将它们加入 URL。

例如:用户名 myuser,密码 mypwd,添加设定:

# 这个帐号使用的代理服务器和用户名/密码
http_proxy=”http://myuser:mypwd@mycache.mydomain.com:3128″
export http_proxy

然后直接用wget,curl就可以

s5代理配置

 

 
yum install -y pam-devel openldap-devel openssl-devel
 
wget -c http://downloads.sourceforge.net/project/ss5/ss5/3.8.9-8/ss5-3.8.9-8.tar.gz
tar zxvf ss5-3.8.9-8.tar.gz
cd ss5-3.8.9-8
./configure;make;make install
 
 
# vim /etc/opt/ss5/ss5.conf
auth 0.0.0.0/0 – -
改为
auth 0.0.0.0/0 – u
 
permit – 0.0.0.0/0 – 0.0.0.0/0 – – – – -
改成为
permit u 0.0.0.0/0 – 0.0.0.0/0 – – – – -
 
# cat /etc/opt/ss5/ss5.passwd
 ##用户  密码
ttlsa 123456
 
sh /etc/rc.d/init.d/ss5 start
 
 
--------------
 
2、在/etc/rc.d/init.d/ss5 文件修改自定义端口,默认为1080
daemon /usr/sbin/ss5 -t $SS5_OPTS -b 0.0.0.0:10888
3、在/etc/sysconfig/ss5 中,取消注释。 
SS5_OPTS=” -u root”
4、添加验证用户及密码,由于密码是明文的,注意控制权限。
# cat ss5.passwd   #一行一个用户+密码
test 123
lxsym 123  
# chmod 700 /etc/rc.d/init.d/ss5
/etc/rc.d/init.d/ss5 restart  

列出rpm包内容和解压rpm包内容

列出rpm包的内容:
rpm -qpl *.rpm
 
解压rpm包的内容:(没有安装,就像解压tgz包一样rpm包)
rpm2cpio *.rpm | cpio -div
 

yum强制安装

yum install -y yum-downloadonly
 
yum install php-mysql -y --downloadonly --downloaddir=/opt
 
rpm -ivh --force --nodeps php-mysql-5.3.3-22.el6.x86_64.rpm

redis和redis php扩展安装

redis是一个内存数据库,比memcache支持更丰富的value类型,新浪微博就使用redis来做缓存。

redis的源码安装

wget http://download.redis.io/redis-stable.tar.gz
tar -zxvf redis-stable.tar.gz
cd redis-stable
make
make test
make install

1.make时可能会报如下错误:

zmalloc.o: In function `zmalloc_used_memory':
/root/redis-stable/src/zmalloc.c:223: undefined reference to `__sync_add_and_fetch_4'
collect2: ld returned 1 exit status
make[1]: *** [redis-server] Error 1
make[1]: Leaving directory `/root/redis-stable/src'
make: *** [all] Error 2

解决办法:
编辑src/.make-settings里的OPT,改为OPT=-O2 -march=i686。

2.make test报错:

You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1

解决办法安装tcl

wget http://downloads.sourceforge.net/tcl/tcl8.6.0-src.tar.gz
 
cd tcl8.6.0/
 
cd unix &&
./configure --prefix=/usr \
            --mandir=/usr/share/man \
            --without-tzdata \
            $([ $(uname -m) = x86_64 ] && echo --enable-64bit) &&
make &&
 
sed -e "s@^\(TCL_SRC_DIR='\).*@\1/usr/include'@" \
    -e "/TCL_B/s@='\(-L\)\?.*unix@='\1/usr/lib@" \
    -i tclConfig.sh
 
make install &&
make install-private-headers &&
ln -v -sf tclsh8.6 /usr/bin/tclsh &&
chmod -v 755 /usr/lib/libtcl8.6.so

redis命令介绍

Redis 由四个可执行文件:redis-benchmark、redis-cli、redis-server、redis-stat 这四个文件,加上一个redis.conf就构成了整个redis的最终可用包。它们的作用如下:

redis-server:Redis服务器的daemon启动程序
redis-cli:Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作
redis-benchmark:Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
redis-stat:Redis状态检测工具,可以检测Redis当前状态参数及延迟状况
现在就可以启动redis了,redis只有一个启动参数,就是他的配置文件路径。

启动redis

复制源码包里的redis.conf到/etc
# cd redis-stable
# cp redis.conf /etc/redis.conf

编辑/etc/redis.conf ,修改
daemaon no 为daemaon yes ,以守护进程方式启动进程。

# redis-server /etc/redis.conf

关闭redis 
# redis-cli shutdown //关闭所有
关闭某个端口上的redis
# redis-cli -p 6397 shutdown //关闭6397端口的redis
说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename dump.rdb

redis配置

注意,默认复制过去的redis.conf文件的daemonize参数为no,所以redis不会在后台运行,这时要测试,我们需要重新开一个终端。修改为yes则为后台运行redis。另外配置文件中规定了pid文件,log文件和数据文件的地址,如果有需要先修改,默认log信息定向到stdout.

下面是redis.conf的主要配置参数的意义:

daemonize:是否以后台daemon方式运行
pidfile:pid文件位置
port:监听的端口号
timeout:请求超时时间
loglevel:log信息级别
logfile:log文件位置
databases:开启数据库的数量
save * *:保存快照的频率,第一个*表示多长时间,第三个*表示执行多少次写操作。在一定时间内执行一定数量的写操作时,自动保存快照。可设置多个条件。
rdbcompression:是否使用压缩
dbfilename:数据快照文件名(只是文件名,不包括目录)
dir:数据快照的保存目录(这个是目录)
appendonly:是否开启appendonlylog,开启的话每次写操作会记一条log,这会提高数据抗风险能力,但影响效率。
appendfsync:appendonlylog如何同步到磁盘(三个选项,分别是每次写都强制调用fsync、每秒启用一次fsync、不调用fsync等待系统自己同步)
这时你可以打开一个终端进行测试了,配置文件中默认的监听端口是6379

redis开机自动启动

用这个脚本管理之前,需要先配置下面的内核参数,否则Redis脚本在重启或停止redis时,将会报错,并且不能自动在停止服务前同步数据到磁盘上:

# vi /etc/sysctl.conf

vm.overcommit_memory = 1

然后应用生效:

# sysctl –p

建立redis启动脚本:

# vim /etc/init.d/redis

#!/bin/bash
#
# Init file for redis
#
# chkconfig: - 80 12
# description: redis daemon
#
# processname: redis
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
#BIN="/usr/local/bin"
BIN="/usr/local/bin"
CONFIG="/etc/redis.conf"
PIDFILE="/var/run/redis.pid"
### Read configuration
[ -r "$SYSCONFIG" ] && source "$SYSCONFIG"
RETVAL=0
prog="redis-server"
desc="Redis Server"
start() {
        if [ -e $PIDFILE ];then
             echo "$desc already running...."
             exit 1
        fi
        echo -n $"Starting $desc: "
        daemon $BIN/$prog $CONFIG
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}
stop() {
        echo -n $"Stop $desc: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog $PIDFILE
        return $RETVAL
}
restart() {
        stop
        start
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] && restart
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        RETVAL=1
esac
exit $RETVAL

然后增加服务并开机自启动:

# chmod 755 /etc/init.d/redis
# chkconfig --add redis
# chkconfig --level 345 redis on
# chkconfig --list redis

redis php扩展安装

wget https://github.com/nicolasff/phpredis/zipball/master -O php-redis.zip
unzip php-redis.zip
cd nicolasff-phpredis-2d0f29b/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install

完成后redis.so被安装到
/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/

vi /usr/local/php/lib/php.ini

添加
extension=redis.so

重启php-fpm即可。

configure时可能会遇到,添加--with-php-config参数可以解决。

configure: error: Cannot find php-config. Please use --with-php-config=PATH

./configure --with-php-config=/usr/local/php/bin/php-config

linux安全优化

cd /dev
dd if=/dev/zero of=tmpmnt bs=1024 count=100000
/sbin/mke2fs /dev/tmpmnt
cp -R /tmp/ /tmp_backup
mount -o loop,rw,nosuid,noexec /dev/tmpmnt /tmp
chmod 0777 /tmp
cp -R /tmp_backup/* /tmp/

# 修改/etc/fstab 添加下面的条目使其在引导时仍然有效
/dev/tmpmnt /tmp ext2 loop,rw,nosuid,noexec 0 0


mv /var/tmp /var/tmpbak
ln -s /tmp /var/tmp

chattr +i /etc/passwd*
chattr +i /etc/shadow*
chattr +i /etc/rc.d/rc.local
chmod 700 /etc/rc.d/init.d/*


chmod 700 /usr/bin/gcc
chmod 700 /usr/bin/g++
chmod 700 /usr/bin/c++
chmod 700 /usr/bin/ld
chmod 700 /usr/bin/as
chmod 700 /usr/bin/perl


chmod 700 /bin/ping
chmod 700 /usr/bin/finger
chmod 700 /usr/bin/who
chmod 700 /usr/bin/w
chmod 700 /usr/bin/locate
chmod 700 /usr/bin/whereis
chmod 700 /sbin/ifconfig
chmod 700 /usr/bin/pico
chmod 700 /usr/bin/vi
chmod 700 /usr/bin/which
chmod 700 /usr/bin/gcc
chmod 700 /usr/bin/make
chmod 700 /bin/rpm

php.ini
disable_functions = "symlink,shell_exec,exec,proc_close,proc_open,popen,system,dl,passthru,escapeshellarg, escapeshellcmd"

Linux批量添加IP,Centos如何快速绑定多个IP

我们购买了5个IP,13个IP,难道都要一个一个的来写配置文件吗?Linux这么批量添加IP?Centos如何快速绑定多个IP?可否做到一个配置文件即可?可以! 
可以在/etc/sysconfig/network-scripts下创建一个range文件

比如,vi /etc/sysconfig/network-scripts/ifcfg-eth0-range0

DEVICE=eth0
ONBOOT=yes
BOOTPROTO=static
IPADDR_START=10.0.0.111
IPADDR_END=10.0.0.119
CLONENUM_START=0
GATEWAY=10.0.0.1
NETMASK=255.255.255.000
NO_ALIASROUTING=yes

其中:

 

IPADDR_START 是起始IP地址,
IPADDR_END 是结束IP地址,
CLONENUM_START 是起始IP别名网卡名(本例中是 eth0:0)

然后重启网络让IP生效: service network restart

 

NETMASK 子网掩码 参考表:

 

/29 (5 usable) NETMASK = 255.255.255.248
/28 (13 usable) NETMASK = 255.255.255.240
/27 (29 usable) NETMASK = 255.255.255.224
/26 (61 usable) NETMASK = 255.255.255.192
/25 (125 usable) NETMASK = 255.255.255.128
/24 (253 usable) NETMASK = 255.255.255.0


-------------------------------------------
最简单的配置如下:

IPADDR_START=开始IP地址
IPADDR_END=结束IP地址
CLONENUM_START=0

linux安全加固(转)

1  BIOS 
你应该总是在系统启动的时候设置一个BIOS 密码和禁用从CD-ROM 和软盘引导,这将可以防止一些人未经允许访问你的系统和更改BIOS 设置

2 
sshd 服务 
SSH
 是一个协议,利用它可以登录到一个远程系统或远程执行系统命令,默认允许root 登录,并且sshv1 存在缺陷,我们应该在sshd_config 禁止root 访问和使用sshv2 来让ssh 更加安全
#vi /etc/ssh/sshd_config
 
Protocol 2
PermitRootLogin = no
#sshd /etc/rc.d/init.d/sshd restart

3  禁用 telnet 
早期的Linux 默认开启telnet 服务,telnet,ftp,rlogin 都是明文传输的协议是容易被嗅探到的,这就是为什么推荐使用安全的版本(sftp,scp,ssh )的原因,如果你必须要使用telnet ,那么至少应该隐藏banner 信息
#vi   /etc/xinetd.d/telnet
disable=yes

4  禁用代码编译 
你可以禁用代码编译并且只把编译的权限分配给一个用户组
#
 该组的成员可以编译代码
/usr/sbin/groupadd compiler
# 把常见的编译器所属组赋给编译用户组
chgrp compiler /usr/bin/*cc*   
chgrp compiler /usr/bin/*++*
chgrp compiler /usr/bin/ld
chgrp compiler /usr/bin/as
 

# 设置mysqlaccess 的 访问
chgrp root mysqlaccess
 
#
 设置权限
chmod 750 /usr/bin/*cc*
chmod 750 /usr/bin/*++*
chmod 750 /usr/bin/ld
chmod 750 /usr/bin/as
chmod 755 /usr/bin/mysqlaccess
#
 把用户添加到组里
vi /etc/group
 

compiler:x:520:user1,user2

5 ProFTP 
#
 修改proftpd.conf 来禁止root 登陆
vi /etc/proftpd.conf
 
Add RootLogin off
/sbin/service proftpd restart

6 
TCP wrappers 
编辑hosts.allow hosts.deny 可以限制或允许访问inet 服务
vi   /etc/hosts.allow
 
#Approved IP addresses
ALL:192.168.0.1
ALL:192.168.5.2
#CSV uploader machine
proftpd:10.0.0 .5
#pop3 from antwhere
ipop3:ALL
vi /etc/hosts.deny
ALL:ALL EXCEPT localhostENY

7 
、创建su 用户组 
因为我们在SSH 禁止了root 用户访问并且禁用了telnet ,所有我们应该分配给一些用户su 权限来获取root 特权
vi /etc/group
 ,添加一行如下
wheel:x:10:root,user1,user2
 
chgrp wheel /bin/su
chmod o-rwx /bin/su
说明:或者直接使用pam 模块来做,再则也可以编译/etc/sudoers 来做

8 
root 通知 
当一个具有root 权限的用户登录的时候发mail ,具体实施方法如下:
vi /root/.bashrc 
,当有root 权限的用户登录时发生email 通知
 
echo ‘ALERT – Root Shell Access (Server Name) on:’ `date` `who` | mail -s “Alert: Root Access from `who | cut -d”(” -f2 | cut -d”)” -f1`” your@email.com

 

9 history 安全 
这是一个避免删除.bash_history 或重定向到/dev/null 的好主意,因此他不能清除或删除他最后执行的命令
chattr +a .bash_history
chattr +i .bash_history
获取用户的人会知道他的历史命令锁定并且要同意才可以使用服务

10 
、使用欢迎信息 
你必须提供一些信息让攻击者知道该系统不对公众开放,在国外有类似案件,攻击者入侵一个系统并且系统没有这些信息,这种情况下法院不能做任何裁决,因为系统说welcome
1
 )删除/etc/redhat-release
2
 )编辑/etc/issue /etc/motd 并显示警告信息

11 
、禁用所有特殊账户 
#
 你应该从系统中删除所有默认用户和组
例如news,lp,sync,shutdown,uucp,games,halt 
userdel name
groupdel name
#
 锁定特定账户
/usr/sbin/usermod -L -s /bin/false user

12 
chmod 危险文件 
这可能是限制不具有root 权限的用户执行下面这些命令的好主意
chmod 700 /bin/ping
chmod 700 /usr/bin/finger
chmod 700 /usr/bin/who
chmod 700 /usr/bin/w
chmod 700 /usr/bin/locate
chmod 700 /usr/bin/whereis
chmod 700 /sbin/ifconfig
chmod 700 /usr/bin/pico
chmod 700 /usr/bin/vi
chmod 700 /usr/bin/which
chmod 700 /usr/bin/gcc
chmod 700 /usr/bin/make
chmod 700 /bin/rpm

13 
、指定允许root 登陆的TTY 设备 
因为/etc/securetty 文件允许你指定root 可以从哪个TTY 设备登录
vi /etc/securetty
 ,然后只留2 个连接
tty1
tty2

14 
、选择一个安全的密码 
/etc/login.defs 文件中定义了shadow 密码的具体配置,默认密码长度最短为5 字符,你应该至少设置为8 
vi   /etc/login.defs
PASS_MIN_LEN   8

 

15 、检测Rootkit 
chkrootkit rkhunter ,以chkrootkit 为例
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.tar.gz 
wget ftp://ftp.pangeia.com.br/pub/seg/pac/chkrootkit.md5

md5sum chkrootkit.tar.gz  # 首先检查md5 校验值
tar -zxvf chkrootkit.tar.gz
cd chkrootkit
./configure && make sense
然后运行./chkrootkit
我们可以将其添加到contrab 使其每天自动扫描:
vi /etc/cron.daily/chkrootkit.sh
#!/bin/bash
#
 输入chkrootkit 的安装目录
cd /root/chkrootkit/
# 
输入你想收到检测报告的email 
./chkrootkit | mail -s “Daily chkrootkit from Server Name” your@email.com 

16 
、安装补丁 
你要经常检查更新以修复某些缺陷或系统稳定性的改进,否则你存在漏洞的系统将会不时的遭受新的攻击
#
 列出可用更新
up2date -l
#
 安装未排除的更新
up2date -u
#
 安装包括排除的更
up2date -uf

17 
、隐藏Apache 信息 
你应该隐藏Apache banner 信息使攻击者不知道Apache 的版本,从而使他们难以利用漏洞
vi /etc/httpd/conf/httpd.conf
#
 改变服务器签名
ServerSignature Off
service httpd restart

18 
、隐藏php 信息 
你应该隐藏php banner 信息,原因同上
vi php.ini
 
expose_php=Off
 
service apache restart

19 、关闭不用的服务 
你应该把任何未使用的服务关闭,可以在/etc/xinetd.d 文件夹里找到
cd /etc/xinetd.d
grep disable * | column  -t
这将显示所有服务开启或关闭的状态,然后根据需要来开启或关闭服务

20 
、检测监听的端口 
检测是否有必要开放端口是非常重要的
 
netstat -tulp
  lsof -i -n | egrep ‘COMMAND|LISTEN|UDP’  nmap 

21 、关闭端口和服务 
重点是关闭在系统启动时打开的不需要的端口,方法如下:
#
 对于正在运行的服务,可以执行
chkconfig -list | grep on
#
 禁用服务可以执行
chkconfig servicename off
#
 然后停止正在运行的服务
/etc/init.d/service stop

22 
、删除不用的rpm  
首先应该清楚你的系统的作用,它是web,mail,file 服务器或其他,然后觉得哪些包是必要的,之后删除不需要的软件包,方法如下:
#
 首先列出安装列表
rpm -qa
#
 更详细的信息
rpm -qi rpmname
#
 还可以检测删除包可能出现的冲突
rpm -e --test rpmname

23 
、禁用危险的php 函数 
你应该禁用php 的危险函数防止在网站上执行系统命令whereis php.ini
vi /usr/local/lib/php.ini
disable_functions = “symlink,shell_exec,exec,proc_close,proc_open,popen,
system,dl,passthru,escapeshellarg, escapeshellcmd”

24 
、安装配置防火墙 
高级策略防火墙(APF )是一种IP 表(网络过滤),它是基于当今互联网部署服务器防火墙系统的基本需要和客户部署LINUX 安装的唯一需要而设计的。 它是最好的开源防火墙之一
1
 )配置APF 防火墙方法:
wget http://www.r-fx.ca/downloads/apf-current.tar.gz 

tar -zxvf apf-current.tar.gz
cd apf-0.9.7 -1
./install.sh

2 vi /etc/apf/conf.apf ,一般配置如下
启用防火墙使用DShield.org 块列表
USE_DS=”1″
然后我将列出常规的配置和CPanel 配置方式,因为CPanel 是应该最广泛的虚拟主机管理软件

1 )常规配置(DNS,Mail,Web,FTP)

Common ingress (inbound)
# Common ingress (inbound) TCP ports -3000_3500 = passive port range for Pure FTPD IG_TCP_CPORTS=”21,22,25,53,80,110,143,443,995″
# Common ingress (inbound) UDP ports IG_UDP_CPORTS=”53″
# Egress filtering [0 = Disabled / 1 = Enabled]
EGF=”1″
# Common egress (outbound) TCP ports
EG_TCP_CPORTS=”21,25,80,443,43″
# Common egress (outbound) UDP ports
EG_UDP_CPORTS=”20,21,53″

2 CPanel 配置
Common ingress (inbound) ports
# Common ingress (inbound) TCP ports -3000_3500 = passive port range for Pure FTPD IG_TCP_CPORTS=”21,22,25,53,80,110,143,443,2082,2083, 2086,2087,2095, 2096,3000_3500″
# Common ingress (inbound) UDP ports
IG_UDP_CPORTS=”53″
Common egress (outbound) ports
# Egress filtering [0 = Disabled / 1 = Enabled]
EGF=”1″
# Common egress (outbound) TCP ports
EG_TCP_CPORTS=”21,25,80,443,43,2089″
# Common egress (outbound) UDP ports
EG_UDP_CPORTS=”20,21,53″
 
之后启动防火墙:/etc/apf/apf -s ,如果运行良好我在回去修改配置文件,使DEVM=”0″

3 )配置APF AntiDos
vi /etc/apf/ad/conf.antidos
 ,找到下面的内容并替换成你的资料
# Organization name to display on outgoing alert emails
CONAME=”Your Company”
# Send out user defined attack alerts [0=off,1=on]
USR_ALERT=”0″
# User for alerts to be mailed to
USR=you@yourco.com 
你应把USR_ALERT 改为1
保存后重启APF /etc/apf/apf –r

To make the firewall start with the Operating System: chkconfig –level 2345 apf on 
APF
 开机自启动:chkconfig –level 2345 apf on
禁止一个IP /etc/apf/apf -d ip 或vi /etc/apf/deny_hosts.rules
允许一个IP /etc/apf/apf -a ip 或vi /etc/apf/deny_hosts.rules

 

25 、安装配置BFD (暴力破解检测) 
BFD
 是一个用于分析应用日志和检测验证失败的模块化shell 脚本,而且安装配置和用法都是非常容易的。使用BFD 的原因很简单,其实在LINUX 领域几乎没有结合防火墙或实时设备来监控不验证和暴力攻击审计的程序。在用BFD 之前你必须安装APF 防火墙
wget http://www.r-fx.ca/downloads/bfd-current.tar.gz 
tar -zxvf bfd-current.tar.gz
cd bfd-0.9

vi /usr/local/bfd/conf.bfd
#
 把以下内容改为你的资料

# Enable/disable user alerts [0 = off; 1 = on]
ALERT_USR=”1″
# User alert email address
EMAIL_USR=”your@mail.com” 
# User alert email; subject
SUBJ_USR=”Brute Force Warning for $HOSTNAME”
vi /usr/local/bfd/ignore.hosts
 ,然后把你的IP 设置成允许主机,避免意外的锁定自己
#
 重启BFD
/usr/local/sbin/bfd -s

26 
、内核加固(sysctl.conf  
sysctl.conf
 用来加固内核,目的是避免DOS 和欺骗攻击,具体的方法如下:
#
 了解下当前配置的大概情况
sysctl -a
vi /etc/sysctl.conf
添加如下内容:

# Kernel sysctl configuration file for Red Hat Linux
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 0 
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1 
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0 
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1 
#Prevent SYN attack
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 2
 
# Disables packet forwarding
net.ipv4.ip_forward=0 
# Disables IP source routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.lo.accept_source_route = 0
net.ipv4.conf.eth0.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
 
# Enable IP spoofing protection, turn on source route verification
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.lo.rp_filter = 1
net.ipv4.conf.eth0.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1
 
# Disable ICMP Redirect Acceptance
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.lo.accept_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
 
# Enable Log Spoofed Packets, Source Routed Packets, Redirect Packets
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.lo.log_martians = 1
net.ipv4.conf.eth0.log_martians = 1
 
# Disables IP source routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.lo.accept_source_route = 0
net.ipv4.conf.eth0.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
 
# Enable IP spoofing protection, turn on source route verification
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.lo.rp_filter = 1
net.ipv4.conf.eth0.rp_filter = 1
 
net.ipv4.conf.default.rp_filter = 1 
# Disable ICMP Redirect Acceptance
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.lo.accept_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
 
# Disables the magic-sysrq key
kernel.sysrq = 0 
# Modify system limits for Ensim WEBppliance
fs.file-max = 65000 
# Decrease the time default value for tcp_fin_timeout connection
net.ipv4.tcp_fin_timeout = 15 
# Decrease the time default value for tcp_keepalive_time connection
net.ipv4.tcp_keepalive_time = 1800 
# Turn off the tcp_window_scaling
net.ipv4.tcp_window_scaling = 0 
# Turn off the tcp_sack
net.ipv4.tcp_sack = 0 
# Turn off the tcp_timestamps
net.ipv4.tcp_timestamps = 0 
# Enable TCP SYN Cookie Protection
net.ipv4.tcp_syncookies = 1 
# Enable ignoring broadcasts request
net.ipv4.icmp_echo_ignore_broadcasts = 1 
# Enable bad error message Protection
net.ipv4.icmp_ignore_bogus_error_responses = 1 
# Log Spoofed Packets, Source Routed Packets, Redirect Packets
net.ipv4.conf.all.log_martians = 1 
# Set maximum amount of memory allocated to shm to 256MB
kernel.shmmax = 268435456 
# Improve file system performance
vm.bdflush = 100 1200 128 512 15 5000 500 1884 2 
# Improve virtual memory performance
vm.buffermem = 90 10 60 
# Increases the size of the socket queue (effectively, q0).
net.ipv4.tcp_max_syn_backlog = 1024 
# Increase the maximum total TCP buffer-space allocatable
net.ipv4.tcp_mem = 57344 57344 65536 
# Increase the maximum TCP write-buffer-space allocatable
net.ipv4.tcp_wmem = 32768 65536 524288
# Increase the maximum TCP read-buffer space allocatable
net.ipv4.tcp_rmem = 98304 196608 1572864 
# Increase the maximum and default receive socket buffer size
net.core.rmem_max = 524280
net.core.rmem_default = 524280
 
# Increase the maximum and default send socket buffer size
net.core.wmem_max = 524280
net.core.wmem_default = 524280
 
# Increase the tcp-time-wait buckets pool size
net.ipv4.tcp_max_tw_buckets = 1440000 
# Allowed local port range
net.ipv4.ip_local_port_range = 16384 65536 
# Increase the maximum memory used to reassemble IP fragments
net.ipv4.ipfrag_high_thresh = 512000
net.ipv4.ipfrag_low_thresh = 446464
 
# Increase the maximum amount of option memory buffers
net.core.optmem_max = 57344 
# Increase the maximum number of skb-heads to be cached
net.core.hot_list_length = 1024 
## DO NOT REMOVE THE FOLLOWING LINE!
## nsobuild:20051206
#
 重启后生效
/sbin/sysctl -p
 

sysctl -w net.ipv4.route.flush=1

27 、更改SSH 端口 
更改SSH 默认端口号在一定程度上可以提高安全性
vi /etc/ssh/sshd_config
Port 22
 改为其他端口
当然不要忘记把更改的端口加进防火墙,然后重启生效:/etc/init.d/ssh restart ,如果安装了APF 并把端口添加之后,还要重启APF:/etc/init.d/apf restart

28 /tmp,/var/tmp,/dev/shm 分区的安全 
/tmp,/var/tmp,/dev/shm
 目录是不安全的,任何用户都可以执行脚本,最好的解决办法是挂载nocexec nosuid 选项的参数( 注意:不建议在CPanel 使用)

1
 /tmp 目录
cd /dev
#
 创建 100M (“count”) 的存储文件:
dd if=/dev/zero of=tmpMnt bs=1024 count=100000
#
 设为一个扩展的文件系统
/sbin/mke2fs /dev/tmpMnt (“…is not a block special device. continue?”
 回答yes)
#
 备份现有临时文件
cp -R /tmp/ /tmp_backup
#
 noexec 挂载新文件系统: 
mount -o loop,rw,nosuid,noexec /dev/tmpMnt /tmp
chmod 0777 /tmp
#
 把备份的文件拷贝回去
cp -R /tmp_backup/* /tmp/
#
 删除备份
rm -rf /tmp_backup
#
 修改/etc/fstab 添加下面的条目使其在引导时仍然有效
/dev/tmpMnt /tmp ext2 loop,rw,nosuid,noexec 0 0

2
 /var/tmp 目录
mv /var/tmp /var/tmpbak
ln -s /tmp /var/tmp
cp /var/tmpbak/* /tmp/

3
 /dev/shm 目录
vi  /etc/fstab
"none /dev/shm tmpfs defaults,rw 0 0"  
改为  "none /dev/shm tmpfs defaults,nosuid,noexec,rw 0 0"

Records:22812345678910»