共有 54 篇文章
Networking timeout
2023-02-15 - 2024-09-18

1

1vim /etc/systemd/system/network-online.target.wants/networking.service
2
3TimeoutStartSec=2sec

2

1vim /etc/dhcp/dhclient.conf
2
3timeout 15

1

change auto eth0 to allow-hotplug eth0

Analyzeblame
2023-02-15 - 2024-09-18

开机时间

1systemd-analyze
Netstat
2023-02-15 - 2024-09-18
1# 查看系统tcp连接中各个状态的连接数。
2netstat -an|awk '/^tcp/ {++s[$NF]} END {for(a in s ) print a,s[a]}'
3
4# 查看和本机23端口建立连接并状态在established的所有ip
5netstat -an|grep 80|grep ESTA|awk '{print $5}'|awk 'BEGIN {FS=":"} {print $1 "\n"}'|sort|uniq -c
Iptables deny ip
2023-02-15 - 2024-09-18

only permit china ip

1systemctl stop firewalld.service
2systemctl disable firewalld.service
3
4yum install ipset
5yum install iptables-services

清空之前的规则

1iptables -P INPUT ACCEPT
2iptables -F

创建一个名为cnip的规则

1ipset -N cnip hash:net
2ipset save
3# 下载国家IP段,这里以中国为例
4wget -P . http://www.ipdeny.com/ipblocks/data/countries/cn.zone
5# 将IP段添加到cnip规则中
6for i in $(cat /root/cn.zone ); do ipset -A cnip $i; done
7
8ipset save cnip -f /etc/ipset.cnip
9/sbin/ipset restore -f /etc/ipset.cnip

放行IP段

1iptables -A INPUT -p tcp -m set --match-set cnip src -j ACCEPT

关掉指定端口

 1iptables -P INPUT DROP
 2# 关闭指定端口,比如80/443
 3iptables -A INPUT -p tcp --dport 80 -j DROP
 4iptables -A INPUT -p tcp --dport 443 -j DROP
 5
 6# 将参数里的-A改成-D就是删除规则了,如
 7iptables -D INPUT -p tcp -m set --match-set cnip src -j ACCEPT
 8iptables -D INPUT -p tcp --dport 443 -j DROP
 9
10# save
11iptables-save > /etc/sysconfig/iptalbes
12iptables-save > /etc/iptables-script
13# restore
14iptables-restore > /etc/sysconfig/iptables
15iptables-restore > /etc/iptables-script

接受全部中国IP

1#全部接受中国IP
2-A INPUT -m set --match-set china src -j ACCEPT
3#接受中国IP访问本机特定端口特定协议(例如5060UDP协议),freeswitch一般要用这条,直接具体到端口协议
4-A INPUT -m set --match-set china src -p udp -m udp --dport 5060 -j ACCEPT
5#接受中国IP的ping响应
6-A INPUT -m set --match-set china src -p icmp -j ACCEPT
1#!/bin/bash
2ipset create china hash:net hashsize 1024 maxelem 65536
3rm -f cn.zone
4wget http://www.ipdeny.com/ipblocks/data/countries/cn.zone
5for i in `cat cn.zone`
6do
7ipset add china $i
8done
1#!/bin/bash
2ipset create hongkong hash:net hashsize 1024 maxelem 65536
3rm -f hk.zone
4wget http://www.ipdeny.com/ipblocks/data/countries/hk.zone
5for i in `cat hk.zone`
6do
7ipset add hongkong $i
8done

配置文件

1vim /etc/sysconfig/iptables
 1*filter
 2:INPUT ACCEPT [0:0]
 3:FORWARD ACCEPT [0:0]
 4:OUTPUT ACCEPT [0:0]
 5-A INPUT -m set --match-set cnip src -j ACCEPT
 6-I INPUT -m set --match-set hongkong src -j DROP
 7-I INPUT -p tcp --dport 80 --syn -m recent --name SYN_FLOOD --update --seconds 60 --hitcount 10 -j REJECT
 8-I INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT
 9-A INPUT -j DROP
10COMMIT
11# Completed on Sun Mar 27 20:29:24 2022
1ipset save > /etc/ipset.cn.hk
2/sbin/ipset restore -f /etc/ipset.cn.hk
3systemctl restart iptables
1iptables -L -n --line-number
2iptables -vnL
3netstat -an | awk '/^tcp/ {++s[$NF]} END {for(a in s ) print a,s[a]}'

限制 syn 并发数为每秒 1 次

1iptables -A INPUT -p tcp --syn -m limit --limit 1/s -j ACCEPT

限制单个 IP 在 60 秒新建立的连接数为 10

1iptables -I INPUT -p tcp --dport 80 --syn -m recent --name SYN_FLOOD --update --seconds 60 --hitcount 10 -j REJECT
Debian 笔记本合盖和电源键作用
2023-02-15 - 2024-09-18

取消笔记本合盖后挂起

1vim /etc/systemd/logind.conf

修改

1# HandleLidSwitch=suspend
2HandleLidSwitch=ignore
3# HandlePowerKey=poweroff
4HandlePowerKey=ignore

修改屏幕保护

GDB Usage
2023-02-15 - 2024-09-18

连接远程调试

1target remote localhost:1234

查看内存

1x/<n/f/u> <addr>
2
3x /8xb 0xffff80000002fff0
4# 以16进制方式查看0xffff80000002fff0处8字节内容

n

从当前地址往后请求的字节数,如果不指定的话,GDB默认是4个bytes。

APT key deprecated
2023-02-15 - 2024-09-18
1curl -s URL | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/NAME.gpg --import
2sudo chmod 644 /etc/apt/trusted.gpg.d/NAME.gpg

google-chrome

1curl -s https://dl.google.com/linux/linux_signing_key.pub | sudo gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/google_linux_signing_key.gpg --import
2sudo chmod 644 /etc/apt/trusted.gpg.d/google_linux_signing_key.gpg
Alsa
2023-02-15 - 2024-09-18

声音控制

1apt install alsa-tools
2amixer set 'Master' unmute

更换默认card

找到对应card序号

1cat /proc/asound/cards

创建此文件 /etc/asound.conf 添加以下内容

1# 1 应改为对应card序号
2defaults.pcm.card 1
3defaults.ctl.card 1

查看cardID或名字

1# 列出映射设备
2aplay -l
3# 查看card信息
4amixer -c Generic_1 scontrols
5amixer -c 1 scontrols
Debian Zoneinfo
2023-02-15 - 2024-09-18
1# 使用UTC时间
2cp /usr/share/zoneinfo/UTC /etc/localtime
3# 使用GMT-8时间,即北京时间
4cp /usr/share/zoneinfo/Etc/GMT-8 /etc/localtime
5# 查看当前时间
6date "+%Y-%m-%d %H:%M:%S"
7TZ=UTC-8 date +%c%:::z
8# 同步时间到硬件
9hwclock -w
Trust CA certificates
2023-01-26 - 2024-09-18

Debian

 1# Debian/Ubuntu/Gentoo
 2# - 安装
 3sudo cp root_ca.crt /usr/local/share/ca-certificates/root_ca.crt
 4# update-ca-certificates 会添加 /etc/ca-certificates.conf 配置文件中指定的证书
 5#   另外所有 /usr/local/share/ca-certificates/*.crt 会被列为隐式信任
 6sudo update-ca-certificates
 7
 8# - 删除
 9sudo rm /usr/local/share/ca-certificates/root_ca.crt
10sudo update-ca-certificates --fresh

RHEL

1# CentOS/Fedora/RHEL
2yum install ca-certificates
3# 启用动态 CA 配置功能:
4update-ca-trust force-enable
5cp root_ca.crt /etc/pki/ca-trust/source/anchors/
6update-ca-trust

MacOS

1# 安装 root_ca.crt
2sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/root_ca.crt
3
4# 删除指定的证书
5sudo security delete-certificate -c "<name of existing certificate>"

Windows

  1. 在根证书文件点鼠标右键,选择“安装证书”
  2. 选择“当前用户”或者“本地计算机”,下一步
  3. “将所有的证书都放入下列存储”,“浏览”,“受信任的根证书颁发机构”,“确定”,下一步
  4. 完成,“是”,确定
File Permission
2022-08-19 - 2024-09-18

修改文件或目录所有者

1# 修改文件的所有者为root
2chown root <file>
3# 修改文件的所有者和所有组为root
4chown root: <file>
5# 修改文件的所有者为root,所有组为akvicor
6chown root:akvicor <file>
7# 修改文件的所有组为root
8chown :root <file>

修改文件或目录的访问权限

1# chmod <xxx> <file/dir>
2chmod 777 file
3# chmod <u/g/o/a><+/-><r/w/x> <file/dir>
4chmod u+x file

目标

  • u: 用户
  • g: 组
  • o: 其他用户
  • a: 全部

操作

  • +: 加
  • -: 减

权限

  • r: 读
  • w: 写
  • x: 执行

特殊权限

  • s: ->u组,简称SUID的特殊权限。当执行该文件时将具有该文件所有者的权限。
  • s: ->g组,简称SGID的特殊权限。在该目录下创建的文件和目录都属于该目录所属的组
  • t: ->o组,简称SBIT的特殊权限。只能让所属主以及root可以删除/移动/重命名该目录下的文件

其中sudo命令就是通过u组的s权限实现的。