IP 检查

检查 IP 是否被墙,风险检测,酌情挑选,替换为 VPS 的 IP 后查看。

# 全球 ping
https://ping.pe/142.171.77.131
# 全国 ping
https://www.itdog.cn/ping/142.171.77.131
# 风险检测
https://scamalytics.com/ip/142.171.77.131
https://www.ipqualityscore.com/ip-reputation-check/lookup/142.171.77.131
https://ipdata.co/
https://ip.guide/142.171.77.131

系统设置

  1. 更新软件库
apt update -y && apt upgrade -y
# 更新后删除不必要的软件和依赖
apt autoclean && apt autoremove -y
  1. 安装必备软件
# 系统必备
apt install sudo curl wget net-tools
# 其它常用,查看负载和硬盘
apt install htop ncdu -y
# 非必须
apt install nmap -y
# 选项 -T4 表示使用较高的扫描速度(4表示4个线程),选项 -p- 表示扫描所有端口
nmap -T4 -p- xx.xx.xx.xx
  1. 更改时区
# 列出时区
timedatectl list-timezones | grep Asia/Shanghai
# 更改时区
sudo timedatectl set-timezone Asia/Shanghai
# 查看时区时间
date -R

# alpine
# ls: /usr/share/zoneinfo: No such file or directory
# 安装 tzdata(时区数据)包
apk add tzdata
# 设置时区
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 更新硬件时钟
hwclock --systohc

# 在 Alpine Linux 中,ntpdate 已不再是推荐的同步时间工具。推荐使用 chrony 作为 NTP 时间同步服务。
# 安装 chrony
apk add chrony
# 启动 chronyd 服务并启用开机启动
rc-service chronyd start
rc-update add chronyd
# 手动同步时间(可选):
# 如果你想立即手动同步时间,可以运行以下命令:
chronyc -a makestep

# pve lxc alpine 执行 rc-service chronyd start,提示错误如下:
#  * Starting chronyd ...
# adjtimex(0x8001) failed : Operation not permitted
#  * start-stop-daemon: failed to start `/usr/sbin/chronyd'
#  * Failed to start #chronyd 
#                                   [ !! ]
# * ERROR: chronyd failed to start
  1. 校正时间
apt install -y ntpdate
ntpdate time.nist.gov
ntpdate time1.aliyun.com
# 每天凌晨 1 点同步一次
0 1 * * * /usr/sbin/ntpdate time.nist.gov && /sbin/hwclock -w 2>&1 > /dev/null
  1. 修改主机名
# 设置服务器名
# 比如: 用途名 + 省份 + 机房名 + 机柜号 + 编号,示例如下 "db-us-131.example.com"
hostnamectl set-hostname racknerd-131
vi /etc/hosts #设置主机名
142.171.77.131 racknerd-131
# hostnamectl 后不重启系统生效
# 更新当前 shell
exec bash
# 广播新主机名给所有进程
systemctl restart systemd-logind
  1. ssh 安全加固
# 一键修改默认 ssh 端口,自行替换 2022
sed -i 's/^#\?Port 22/Port 2022/' /etc/ssh/sshd_config
# 禁止 root 登陆
sed 's/^PermitRootLogin yes/#PermitRootLogin prohibit-password/' /etc/ssh/sshd_config | grep PermitRootLogin
sed -i 's/^PermitRootLogin yes/#PermitRootLogin prohibit-password/' /etc/ssh/sshd_config
sed -i 's/^#\?PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
# 重启生效
## Debian系统
systemctl restart ssh
/etc/init.d/ssh restart
## RHEL/CentOS系统
service sshd restart
## Ubuntu系统
service ssh restart
# 禁止密码登录 ssh,只允许密钥登录
bash <(curl -fsSL git.io/key.sh) -og AAAAA -p 77777 -d
# 其中 AAAAA 是你的 Github 用户名,自己去 GitHub 设置里的 SSH Keys 上传你密钥的公钥就行了,77777 是你想要的 ssh 端口
# fail2ban
# https://github.com/yuju520/YujuToolBox/blob/main/yuju.sh
  1. 开启 swap
# 检查是否有 swap
cat /proc/swaps
# swap 步骤开始
# 1 GB == 1048576 KB
dd if=/dev/zero of=/swapfile bs=1024 count=2097152     # 2G
dd if=/dev/zero of=/swapfile bs=1024 count=1048576     # 1G
dd if=/dev/zero of=/swapfile bs=1024 count=524288      # 512 MB
dd if=/dev/zero of=/swapfile bs=1024 count=262144      # 256 MB
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
swapon -s
free -m
# 删除重新来
swapoff -v /swapfile
rm -rf /swapfile[可选]
  1. 开启 bbr

bbr 是 Google 提出的一种新型拥塞控制算法(Bottleneck Bandwidth and RTT),全称为瓶颈带宽和往返传播时间。

# 开启 bbr
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
# 不重启生效,检查 bbr 开启状态
sysctl -p
lsmod | grep bbr
# 或者
sysctl net.ipv4.tcp_available_congestion_control

开启防火墙

sudo apt install ufw
sudo ufw disable
sudo ufw enable
sudo ufw status
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22

查看硬件

# 查看 vps 的配置信息,cpu、磁盘 IO 和带宽测试
wget -qO- bench.sh | bash

查看解锁

# IP质量体检报告
bash <(curl -Ls IP.Check.Place)
# 融合怪
bash <(wget -qO- bash.spiritlhl.net/ecs)
curl -L https://gitlab.com/spiritysdx/za/-/raw/main/ecs.sh -o ecs.sh && chmod +x ecs.sh && bash ecs.sh

常用脚本

  1. 清理日志
# 一键清理 /var/log/ 目录下的过期日志
find /var/log/ -name "*.1" -exec rm -rf {} \; && find /var/log/ -name "*.log.1" -exec rm -rf {} \; && find /var/log/ -name "*.gz" -exec rm -rf {} \;
# https://github.com/yuju520/YujuToolBox/blob/main/yuju.sh