centos

cent os


安装iptable iptable-service

1
2
3
4
5
6
7
8
9
10
11
#先检查是否安装了iptables
service iptables status

#安装iptables
yum install -y iptables

#升级iptables
yum update iptables

#安装iptables-services
yum install iptables-services

禁用/停止自带的firewalld服务

1
2
3
4
5
#停止firewalld服务
systemctl stop firewalld

#禁用firewalld服务
systemctl mask firewalld

设置现有规则

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#查看iptables现有规则
iptables -L -n
#先允许所有,不然有可能会杯具
iptables -P INPUT ACCEPT
#清空所有默认规则
iptables -F
#清空所有自定义规则
iptables -X
#所有计数器归0
iptables -Z
#允许来自于lo接口的数据包(本地访问)
iptables -A INPUT -i lo -j ACCEPT
#开放22端口
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#开放21端口(FTP)
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
#开放80端口(HTTP)
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
#开放443端口(HTTPS)
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
#允许ping
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
#允许接受本机请求之后的返回数据 RELATED,是为FTP设置的
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
#其他入站一律丢弃
iptables -P INPUT DROP
#所有出站一律绿灯
iptables -P OUTPUT ACCEPT
#所有转发一律丢弃
iptables -P FORWARD DROP

其他规则设定

1
2
3
4
5
6
7
8
#如果要添加内网ip信任(接受其所有TCP请求)
iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT
#过滤所有非以上规则的请求
iptables -P INPUT DROP
#要封停一个IP,使用下面这条命令:
iptables -I INPUT -s ***.***.***.*** -j DROP
#要解封一个IP,使用下面这条命令:
iptables -D INPUT -s ***.***.***.*** -j DROP

保存规则设定

1
2
#保存上述规则
service iptables save

开启iptables服务

1
2
3
4
5
6
7
#注册iptables服务
#相当于以前的chkconfig iptables on
systemctl enable iptables.service
#开启服务
systemctl start iptables.service
#查看状态
systemctl status iptables.service
以下为完整设置脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh
iptables -P INPUT ACCEPT
iptables -F
iptables -X
iptables -Z
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -p icmp --icmp-type 8 -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
service iptables save
systemctl restart iptables.service

certbot

certbot

官方安装介绍

到上面网站按照步骤安装certbot,安装完成后,certbot 生成证书有两种方式

第一种:standalone模式,certbot 会启动自带的nginx(如果服务器上已有nginx,需要停止已有的nginx)生成证书

1
certbot certonly --standalone -d example.com -d www.example.com

第二种:webroot模式

certbot会生成随机文件到给定目录(nginx配置的网页目录)下的/.well-known/acme-challenge/目录里面,并通过已经启动的nginx验证随机文件,生成证书

1
certbot certonly --webroot -w /usr/local/nginx/html -d linlc.cc -d xcx.linlc.cc -w /var/www/doee -d doee.cc
  • -w nginx.conf 里server配置的网页目录,既生成随机验证的文件的目录
  • -d nginx.conf 里的 server_name

$续期:# 最后如果要续期,(正式 去掉 –dry-run 参数)

1
2
3
4
certbot renew --dry-run

# 查询已经生成证书的情况
certbot certificates

$通配符:生成通配符域名(一定要加 *.linlc.cc 与 linlc.cc 这两个,否则不会生成顶级域名的证书)

1
certbot certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns-01 -w /usr/local/nginx/html -d *.linlc.cc -d linlc.cc -d timed.ink

只需要跟换 -w, -d 后面的参数就行了

linux 常用命令

linux 命令大全

其他命令

1
2
3
top

free -h

curl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 下载 -o 文件名;-O默认文件名保存
curl -o baidu.hml http://www.baidu.com
curl -O http://su.bdimg.com/static/superplus/img/logo_white_ee663702.png
curl -O http://121.199.28.164/llc/resource/img/jidihaiyang0[1-2].jpg

# -x proxy代理
curl -x 123.45.67.89:1080 -o page.html http://www.linuxidc.com

# -D 写入header到cookie0001.txt文件
curl -x 123.45.67.89:1080 -o page.html -D cookie0001.txt http://www.linuxidc.com

# -b 引用本地cookie0001.txt,发送请求
curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com

# -d 发送http的post请求
curl -d "cmd=login&username=loganv&password=123456&vcode=1234" -D cookie001.txt http://www.linuxidc.com/ajax.aspx

# -F 表单提交,post上传文件可用@localfilepath
curl -F upload=@123.txt -F nick=loganv http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi

# -T 上传本地文件到ftp服务器 -u una:pwd
curl -T 123.txt -u qxu1606420111:ftpftp123 ftp://qxu1606420111.my3w.com/myfolder/a.txt

# -A 模拟请求浏览器
# avascript:alert(window.navigator.userAgent);
curl -A "Mozilla/5.0 (iPod touch; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.0 Mobile/12B411 Safari/600.1.4" -o baidu.html -D cookie0001.txt http://www.baidu.com

# -I 仅返回header
# -H "Connection: keep-alive \n Content-Type: text/html" 设置 header

scp

1
2
3
4
5
6
7
8
# 本地-->远程
scp ~/Desktop/1.txt root@192.168.0.1:~/Downloads/

# 远程-->本地
scp root@192.168.0.1:~/Downloads/1.txt ~/Desktop/1.txt

# scp -i 证书路径 源文件路径 拷贝路径
# 端口大P: -P 51022

Read More

nginx

nginx location 用法

https://www.cnblogs.com/dadonggg/p/7797281.html

编译

安装编译环境

1
2
sudo apt-get install build-essential
sudo apt-get install libtool

安装nginx依赖库

1
sudo apt-get install libpcre3 libpcre3-dev libssl-dev zlib1g-dev

nginx,pcre,openssl官网下载最新源码,解压nginx,pcre,openssl到/opt/nginx/目录下,

进入/opt/nginx/nginx-1.15.8目录

1
./configure --with-pcre=/opt/nginx/pcre-8.42 --with-openssl=/opt/nginx/openssl-1.1.0j --with-http_ssl_module

编译成功后,安装

1
make && make install

Read More