VPS常用安全設(shè)置(linux)
發(fā)布時(shí)間:2012-08-15 09:14:34 作者:佚名
我要評論

新手及才接觸VPS的朋友們看一下,主要是關(guān)于VPS安全方面相關(guān)內(nèi)容的
一、修改SSH端口
vi /etc/ssh/sshd_config
找到其中的#Port 22(第13行),去掉#,修改成Port 3333
使用如下命令,重啟SSH服務(wù),注:以后用新端口登陸。
service sshd restart
二、禁止ROOT登陸
先添加一個(gè)新帳號80st ,可以自定義:
useradd 80st
給weidao 帳號設(shè)置密碼:
passwd 80st
仍舊是修改/etc/ssh/sshd_config文件,第39行:#PermitRootLogin yes,去掉前面的#,并把yes改成no,然后,重啟SSH服務(wù)。以后,先使用weidao 登陸,再su root即可得到ROOT管理權(quán)限。
login as: 80st
weidao@ip password:*****
Last login: Tue Nov 22 15:18:18 2011 from 1.2.3.4
su root
Password:*********** #注這里輸入ROOT的密碼
三、使用DDos deflate簡單防落CC和DDOS攻擊
使用netstat命令,查看VPS當(dāng)前鏈接確認(rèn)是否受到攻擊:
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
IP前面的數(shù)字,即為連接數(shù),如果說正常網(wǎng)站,幾十到一百都屬于正常連接,但出現(xiàn)幾百,或上千的就可以墾定這個(gè)IP與你的VPS之間可能存在可疑連接現(xiàn)象。
可以使用iptables直接BAN了這個(gè)IP的永久訪問:
iptables -A INPUT -s 12.34.56.78 -j DROP
使用軟件DDos deflate來自動檢測并直接BAN掉的方法,首先要確認(rèn)一下iptables服務(wù)狀態(tài),默認(rèn)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要設(shè)置成0,因?yàn)橐褂胕ptables來封某些可疑連接,注意EMAIL_TO=”root”,這樣BAN哪個(gè)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”//定時(shí)執(zhí)行程序
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 //檢查時(shí)間間隔,默認(rèn)1分鐘
##### How many connections define a bad IP? Indicate that below.
NO_OF_CONNECTIONS=150 //最大連接數(shù),超過這個(gè)數(shù)IP就會被屏蔽,一般默認(rèn)即可
##### 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,默認(rèn)即可
##### An email is sent to the following address when an IP is banned.
##### Blank would suppress sending of mails
EMAIL_TO=”root”//當(dāng)IP被屏蔽時(shí)給指定郵箱發(fā)送郵件,推薦使用,換成自己的郵箱即可
##### Number of seconds the banned ip should remain in blacklist.
BAN_PERIOD=600 //禁用IP時(shí)間,默認(rèn)600秒,可根據(jù)情況調(diào)整
四、使用iftop查看詳細(xì)網(wǎng)絡(luò)狀況
安裝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運(yùn)行,查看網(wǎng)絡(luò)情況。TX,發(fā)送流量;RX,接收流量;TOTAL,總流量;Cumm,運(yùn)行iftop期間流量;peak,流量峰值;rates,分別代表2秒、10秒、40秒的平均流量。
快捷鍵:h幫助,n切換顯示IP主機(jī)名,s是否顯示本機(jī)信息,d是否顯示遠(yuǎn)端信息,N切換端口服務(wù)名稱,b切換是否時(shí)數(shù)流量圖形條。
五、升級LNMP中的NGINX到最新版
現(xiàn)在最新版是0.8.53,如果以后出新版,只要更新版本號就可以,在SSH里運(yùn)行:
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.查看所有80端口的連接數(shù)
netstat -nat|grep -i “80″|wc -l
2.對連接的IP按連接數(shù)量進(jìn)行排序
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
3.查看TCP連接狀態(tài)
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.查看80端口連接數(shù)最多的20個(gè)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嗅探80端口的訪問看看誰最高
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
vi /etc/ssh/sshd_config
找到其中的#Port 22(第13行),去掉#,修改成Port 3333
使用如下命令,重啟SSH服務(wù),注:以后用新端口登陸。
service sshd restart
二、禁止ROOT登陸
先添加一個(gè)新帳號80st ,可以自定義:
useradd 80st
給weidao 帳號設(shè)置密碼:
passwd 80st
仍舊是修改/etc/ssh/sshd_config文件,第39行:#PermitRootLogin yes,去掉前面的#,并把yes改成no,然后,重啟SSH服務(wù)。以后,先使用weidao 登陸,再su root即可得到ROOT管理權(quán)限。
login as: 80st
weidao@ip password:*****
Last login: Tue Nov 22 15:18:18 2011 from 1.2.3.4
su root
Password:*********** #注這里輸入ROOT的密碼
三、使用DDos deflate簡單防落CC和DDOS攻擊
使用netstat命令,查看VPS當(dāng)前鏈接確認(rèn)是否受到攻擊:
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
IP前面的數(shù)字,即為連接數(shù),如果說正常網(wǎng)站,幾十到一百都屬于正常連接,但出現(xiàn)幾百,或上千的就可以墾定這個(gè)IP與你的VPS之間可能存在可疑連接現(xiàn)象。
可以使用iptables直接BAN了這個(gè)IP的永久訪問:
iptables -A INPUT -s 12.34.56.78 -j DROP
使用軟件DDos deflate來自動檢測并直接BAN掉的方法,首先要確認(rèn)一下iptables服務(wù)狀態(tài),默認(rèn)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要設(shè)置成0,因?yàn)橐褂胕ptables來封某些可疑連接,注意EMAIL_TO=”root”,這樣BAN哪個(gè)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”//定時(shí)執(zhí)行程序
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 //檢查時(shí)間間隔,默認(rèn)1分鐘
##### How many connections define a bad IP? Indicate that below.
NO_OF_CONNECTIONS=150 //最大連接數(shù),超過這個(gè)數(shù)IP就會被屏蔽,一般默認(rèn)即可
##### 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,默認(rèn)即可
##### An email is sent to the following address when an IP is banned.
##### Blank would suppress sending of mails
EMAIL_TO=”root”//當(dāng)IP被屏蔽時(shí)給指定郵箱發(fā)送郵件,推薦使用,換成自己的郵箱即可
##### Number of seconds the banned ip should remain in blacklist.
BAN_PERIOD=600 //禁用IP時(shí)間,默認(rèn)600秒,可根據(jù)情況調(diào)整
四、使用iftop查看詳細(xì)網(wǎng)絡(luò)狀況
安裝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運(yùn)行,查看網(wǎng)絡(luò)情況。TX,發(fā)送流量;RX,接收流量;TOTAL,總流量;Cumm,運(yùn)行iftop期間流量;peak,流量峰值;rates,分別代表2秒、10秒、40秒的平均流量。
快捷鍵:h幫助,n切換顯示IP主機(jī)名,s是否顯示本機(jī)信息,d是否顯示遠(yuǎn)端信息,N切換端口服務(wù)名稱,b切換是否時(shí)數(shù)流量圖形條。
五、升級LNMP中的NGINX到最新版
現(xiàn)在最新版是0.8.53,如果以后出新版,只要更新版本號就可以,在SSH里運(yùn)行:
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.查看所有80端口的連接數(shù)
netstat -nat|grep -i “80″|wc -l
2.對連接的IP按連接數(shù)量進(jìn)行排序
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
3.查看TCP連接狀態(tài)
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.查看80端口連接數(shù)最多的20個(gè)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嗅探80端口的訪問看看誰最高
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
相關(guān)文章
- 虛擬機(jī)是VPS的基礎(chǔ),而Xen和KVM又是當(dāng)今VPS產(chǎn)品中使用最多的兩款虛擬機(jī)程序,這里就來為大家簡單總結(jié)一下VPS方案選擇中Xen和KVM虛擬機(jī)程序的對比:2016-06-28
VPS主機(jī)商普遍采用的主流虛擬機(jī)程序總結(jié)
VPS一般即是用虛擬機(jī)程序構(gòu)建的服務(wù)器配置環(huán)境,而服務(wù)商主要才用到的VM方案有Xen、KVM和OpenVZ等,這里我們就來整理一下VPS主機(jī)商普遍采用的主流虛擬機(jī)程序總結(jié)2016-06-28華夏名網(wǎng)VPS教程 win2003安全設(shè)置與開空間教程
華夏名網(wǎng)VPS教程 win2003安全設(shè)置與開空間教程,不論是使用vps還是win2003服務(wù)器的朋友都可以參考下。2011-04-09景安網(wǎng)絡(luò)快云VPS視頻教程 全10講打包(vps配置)
主要是景安網(wǎng)絡(luò)出的視頻教程,教用戶如何配置vps,需要的朋友可以下載看下2015-10-12在VPS主機(jī)上安裝和使用CentOS遠(yuǎn)程桌面的教程
這篇文章主要介紹了在VPS主機(jī)上安裝和使用CentOS遠(yuǎn)程桌面的教程,文中示例基于CentOS 7系統(tǒng),需要的朋友可以參考下2015-05-29Vultr VPS自定義安裝Windows2003 ISO系統(tǒng)以及加載驅(qū)動可遠(yuǎn)程上網(wǎng)
這篇文章主要介紹了Vultr VPS自定義安裝Windows2003 ISO系統(tǒng)以及加載驅(qū)動可遠(yuǎn)程上網(wǎng)的方法,希望對大家有幫助2015-04-15- 這篇文章主要介紹了CentOS VPS入手后的基本優(yōu)化和安全配置,本文涉及升級防火墻策略、刪除不用的應(yīng)用、清理不需要的用戶和用戶組、更改時(shí)區(qū)等方面,需要的朋友可以參考下2014-12-30
- 這篇文章主要介紹了CentOS VPS新硬盤分區(qū)與掛載教程,本文操作命令使用圖片展示,并配有詳細(xì)的文字說明,需要的朋友可以參考下2014-10-24
- 伴隨著國內(nèi)EA智能交易的興起,VPS技術(shù)在外匯零售交易領(lǐng)域的應(yīng)用也在逐漸擴(kuò)大,那么什么是VPS技術(shù)?今天小編就為大家?guī)碓敿?xì)介紹,感興趣的朋友一起看看吧2016-09-04