适合新手及才接触VPS的朋友们看一下。主要是关于VPS安全方面相关内容的

禁止ROOT登陆 保证安全性。

使用DDoS deflate简单防攻击。

iftop Linux流量监控工具;

每日自己主动备份VPS到FTP空间。

升级LNMP的NGINX到最新版。

一、改动SSHport

vi /etc/ssh/sshd_config

找到当中的#Port 22(第13行),去掉#,改动成Port 3333

使用例如以下命令,重新启动SSH服务。注:以后用新port登陆。

service sshd restart

二、禁止ROOT登陆

先加入一个新帐号vpsmm。能够自己定义:

useradd vpsmm

给vpsmm帐号设置password:

passwd vpsmm

仍旧是改动/etc/ssh/sshd_config文件,第39行:#PermitRootLogin yes,去掉前面的#,并把yes改成no。然后,重新启动SSH服务。

以后,先使用vpsmm登陆。再su root就可以得到ROOT管理权限。

login as: vpsmm

vpsmm@ip password:*****

Last login: Tue Nov 22 14:39:58 2010 from 1.2.3.4

su root

Password:*********** #注这里输入ROOT的password

三、使用DDos deflate简单防落CC和DDOS攻击

使用netstat命令,查看VPS当前链接确认是否受到攻击:

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

IP前面的数字,即为连接数。假设说正常站点,几十到一百都属于正常连接,但出现几百,或上千的就能够垦定这个IP与你的VPS之间可能存在可疑连接现象。

能够使用iptables直接BAN了这个IP的永久訪问:

iptables -A INPUT -s 12.34.56.78 -j DROP

今天介绍给大家一种方法,是使用软件DDos deflate来自己主动检測并直接BAN掉的方法,首先我们要确认一下iptables服务状态。默认CENTOS就安装的,不看也行。

service iptables status

安装DDos deflat:

wget http://www.inetbase.com/scripts/ddos/install.sh

chmod +x install.sh

./install.sh

安装后须要改动/usr/local/ddos/ddos.conf,主要是APF_BAN=1要设置成0,由于要使用iptables来封某些可疑连接,注意EMAIL_TO=“root”,这样BAN哪个IP会有邮件提示:

##### Paths of the script and other files

PROGDIR="/usr/local/ddos"

PROG="/usr/local/ddos/ddos.sh"

IGNORE_IP_LIST="/usr/local/ddos/ignore.ip.list"  //IP地址白名单

CRON="/etc/cron.d/ddos.cron"    //定时运行程序

APF="/etc/apf/apf"

IPT="/sbin/iptables"

##### frequency in minutes for running the script

##### Caution: Every time this setting is changed, run the script with --cron

#####          option so that the new frequency takes effect

FREQ=1   //检查时间间隔,默认1分钟

##### How many connections define a bad IP? Indicate that below.

NO_OF_CONNECTIONS=150     //最大连接数,超过这个数IP就会被屏蔽。一般默认就可以

##### APF_BAN=1 (Make sure your APF version is atleast 0.96)

##### APF_BAN=0 (Uses iptables for banning ips instead of APF)

APF_BAN=1        //使用APF还是iptables。推荐使用iptables,将APF_BAN的值改为0就可以。

##### KILL=0 (Bad IPs are'nt banned, good for interactive execution of script)

##### KILL=1 (Recommended setting)

KILL=1   //是否屏蔽IP,默认就可以

##### An email is sent to the following address when an IP is banned.

##### Blank would suppress sending of mails

EMAIL_TO="root"   //当IP被屏蔽时给指定邮箱发送邮件,推荐使用,换成自己的邮箱就可以

##### Number of seconds the banned ip should remain in blacklist.

BAN_PERIOD=600    //禁用IP时间,默认600秒。可依据情况调整

四、使用iftop查看具体网络状况

安装IFTOP软件:

yum -y install flex byacc  libpcap ncurses ncurses-devel libpcap-devel

wget http://www.ex-parrot.com/pdw/iftop/download/iftop-0.17.tar.gz

tar zxvf iftop-0.17.tar.gz

cd iftop-0.17

./configure

make && make install

安装后,使用iftop执行,查看网络情况。TX,发送流量。RX,接收流量;TOTAL,总流量;Cumm,执行iftop期间流量。peak。流量峰值;rates,分别代表2秒、10秒、40秒的平均流量。

快捷键:h帮助,n切换显示IP主机名,s是否显示本机信息,d是否显示远端信息,N切换port服务名称,b切换是否时数流量图形条。

五、每日备份你的VPS上传到FTP空间

六、升级LNMP中的NGINX到最新版

如今最新版是0.8.53,假设以后出新版。仅仅要更新版本就能够,在SSH里执行:

wget http://www.nginx.org/download/nginx-0.8.53.tar.gz

tar zxvf nginx-0.8.53.tar.gz

cd nginx-0.8.53

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module  --with-http_sub_module

make

mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

cd objs/

cp nginx /usr/local/nginx/sbin/

/usr/local/nginx/sbin/nginx -t

kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`

kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`

/usr/local/nginx/sbin/nginx -v

cd ..

cd ..

rm -rf nginx-0.8.53

rm -rf nginx-0.8.53.tar.gz

七、经常使用netstat命令:

1.查看全部80port的连接数

netstat -nat|grep -i "80"|wc -l

2.对连接的IP按连接数量进行排序

netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n

3.查看TCP连接状态

netstat -nat |awk '{print $6}'|sort|uniq -c|sort -rn

netstat -n | awk '/^tcp/ {++S[$NF]};END {for(a in S) print a, S[a]}'

netstat -n | awk '/^tcp/ {++state[$NF]}; END {for(key in state) print key,"\t",state[key]}'

netstat -n | awk '/^tcp/ {++arr[$NF]};END {for(k in arr) print k,"\t",arr[k]}'

netstat -n |awk '/^tcp/ {print $NF}'|sort|uniq -c|sort -rn

netstat -ant | awk '{print $NF}' | grep -v '[a-z]' | sort | uniq -c

4.查看80port连接数最多的20个IP

netstat -anlp|grep 80|grep tcp|awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n20

netstat -ant |awk '/:80/{split($5,ip,":");++A[ip[1]]}END{for(i in A) print A,i}' |sort -rn|head -n20

5.用tcpdump嗅探80port的訪问看看谁最高

tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr |head -20

6.查找较多time_wait连接

netstat -n|grep TIME_WAIT|awk '{print $5}'|sort|uniq -c|sort -rn|head -n20

7.找查较多的SYN连接

netstat -an | grep SYN | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | more

最新文章

  1. ABAP关键字SUBMIT的简单例子和学习小记
  2. 框架dubbox的简单使用
  3. 《与小卡特一起学Python》 Code2
  4. 烂泥:KVM、kickstart与nginx集成
  5. getDefinitionByName getDefinition 区别
  6. [HDU 3535] AreYouBusy (动态规划 混合背包 值得做很多遍)
  7. Java IO (2) - OutputStream
  8. apache开源项目--Cassandra
  9. HDU 1361 Parencodings(栈)
  10. Sql Server日期时间格式转换
  11. C语言中不同变量的访问方式
  12. How to create DB2 user function easily by DB Query Analyzer 6.03
  13. PHP基本随笔
  14. jpa的Join和Fetch
  15. OOP的概念和基础特性
  16. Linux shell判断文件和文件夹是否存在(转发)
  17. Linux安装Tomcat-Nginx-FastDFS-Redis-Solr-集群——【第十三集之Redis的单机版搭建】
  18. URL和URI的不同
  19. JDBC中链接数据库前为什么要用Class.forName(驱动类)加载驱动类?
  20. [转]自定义Drawable实现灵动的红鲤鱼动画(上篇)

热门文章

  1. java.lang.OutOfMemoryError: Java heap space错误及处理办法
  2. RDLC报表上下标实现
  3. EMCA常用命令 【weber整理必出精品】
  4. C++中的函数指针用法
  5. 费马小定理&欧拉定理
  6. Java如何获取当前的jar包路径以及如何读取jar包中的资源
  7. 关于css伪类:hover的用法
  8. ubuntu12.04 安装 ruby1.9.3
  9. php性能效率优化
  10. shopnc怎么开启伪静态 shopnc开启伪静态的方法