本文最后更新于 920 天前,其中的信息可能已经有所发展或是发生改变。
| # debian11 |
| cat > /etc/apt/sources.list << EOF |
| deb https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free |
| deb-src https://mirrors.ustc.edu.cn/debian/ bullseye main contrib non-free |
| |
| deb https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free |
| deb-src https://mirrors.ustc.edu.cn/debian/ bullseye-updates main contrib non-free |
| |
| deb https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free |
| deb-src https://mirrors.ustc.edu.cn/debian/ bullseye-backports main contrib non-free |
| |
| deb https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free |
| deb-src https://mirrors.ustc.edu.cn/debian-security/ bullseye-security main contrib non-free |
| EOF |
| apt update -y && apt upgrade -y |
| |
| #debian 12 |
| cat > /etc/apt/sources.list << EOF |
| # 默认注释了源码仓库,如有需要可自行取消注释 |
| deb http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free non-free-firmware |
| # deb-src http://mirrors.ustc.edu.cn/debian bookworm main contrib non-free non-free-firmware |
| deb http://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware |
| # deb-src http://mirrors.ustc.edu.cn/debian bookworm-updates main contrib non-free non-free-firmware |
| |
| # backports 软件源,请按需启用 |
| # deb http://mirrors.ustc.edu.cn/debian bookworm-backports main contrib non-free non-free-firmware |
| # deb-src http://mirrors.ustc.edu.cn/debian bookworm-backports main contrib non-free non-free-firmware |
| EOF |
| apt update -y && apt upgrade -y |
| apt install sudo -y |
| cat > /etc/sudoers.d/username << EOF |
| username ALL=(ALL) NOPASSWD:ALL |
| EOF |
| sudo vim /etc/network/interfaces |
| |
| sudo systemctl restart networking |
| |
| date |
| |
| |
| sudo timedatectl set-timezone Asia/Shanghai |
| |
| |
| tzselect |
| 命令自动补全忽略大小写 |
| echo 'set completion-ignore-case on' >> ~/.inputrc |
| |
| 修改 vmrc(vim 配置文件) |
| 为当前用户创建 ~/.vimrc,内容参看上述 “配置 vi” |
| |
| 为将 .vimrc 添加到默认用户配置文件 cp ~/.vimrc /etc/skel/.vimrc |
| |
| ll 常规版 |
| 一般 Linux 中默认定义了 ll 别名,但参数比较少,需要使用更加强大的 ll 别名。 |
| Debian 默认并没有定义 ll 别名。 |
| 写入环境变量(当前用户优先执行): |
| bash: |
| echo 'alias ll="ls -lahF --color=auto --time-style=long-iso"' >> ~/.bashrc |
| |
| 高级版 ls:以数字显示权限 |
| 这里我们把命令叫做 lll |
| 命令: |
| ls -lahF --color=auto --time-style=long-iso | awk '{k=0;s=0;for(i=0;i<=8;i++){k+=((substr($1,i+2,1)~/[rwxst]/)*2^(8-i))}j=4;for(i=4;i<=10;i+=3){s+=((substr($1,i,1)~/[stST]/)*j);j/=2}if(k){printf("%0o%0o ",s,k)}print}' |
| |
| 创建文件 |
| 在使用 cat EOF 中出现 $ 变量通常会直接被执行,显示执行的结果。若想保持 $ 变量不变需要使用 \ 符进行注释。 |
| |
| # 如果非 root 用户,切换到 root |
| sudo -i |
| cat > /usr/local/bin/lll <<EOF |
| #!/bin/bash |
| ls -lahF --color=auto --time-style=long-iso | awk '{k=0;s=0;for(i=0;i<=8;i++){k+=((substr(\$1,i+2,1)~/[rwxst]/)*2^(8-i))}j=4;for(i=4;i<=10;i+=3){s+=((substr(\$1,i,1)~/[stST]/)*j);j/=2}if(k){printf("%0o%0o ",s,k)}print}' |
| EOF |
| |
| # 赋予执行权限: |
| chmod +x /usr/local/bin/lll |
| |
| # 如果非 root 用户,执行完毕退出 |
| exit |
| |
| 写入环境变量(可选配置,默认不需要): |
| bash |
| echo 'alias lll="/usr/local/bin/lll"' >> ~/.bashrc |
| sudo apt install -y nftables |
| sudo systemctl enable nftables.service |
| |
| |
| nft flush ruleset |
| |
| nft list ruleset |
| |
| nft add table inet filter |
| |
| |
| nft add chain inet filter input { type filter hook input priority 0 \; policy drop \; } |
| nft add chain inet filter forward { type filter hook forward priority 0 \; policy drop \; } |
| nft add chain inet filter output { type filter hook output priority 0 \; policy accept \; } |
| |
| |
| nft add chain inet filter TCP |
| nft add chain inet filter UDP |
| |
| nft add rule inet filter input ct state related,established accept |
| |
| nft add rule inet filter input iif lo accept |
| |
| nft add rule inet filter input ct state invalid drop |
| |
| nft add rule inet filter input ip protocol icmp icmp type echo-request ct state new accept |
| |
| nft add rule inet filter input ip protocol udp ct state new jump UDP |
| |
| nft add rule inet filter input ip protocol tcp tcp flags \& \(fin\|syn\|rst\|ack\) == syn ct state new jump TCP |
| |
| |
| nft add rule inet filter input ip protocol udp reject |
| nft add rule inet filter input ip protocol tcp reject with tcp reset |
| nft add rule inet filter input counter reject with icmp type prot-unreachable |
| |
| |
| nft add rule inet filter TCP tcp dport 80 accept |
| |
| nft add rule inet filter TCP tcp dport 443 accept |
| |
| nft add rule inet filter TCP tcp dport 22 accept |
| |
| |
| |
| |
| |
| |
| |
| |
| nft add table ip dnat1 |
| |
| |
| nft add chain dnat1 prerouting { type nat hook prerouting priority 0 \;} |
| |
| |
| nft add chain dnat1 postrouting { type nat hook postrouting priority 100 \; } |
| |
| |
| nft add rule dnat1 prerouting ip daddr 192.168.1.1 tcp dport 80 counter dnat 172.16.1.2:80 |
| nft add fule dnat1 postrouting ip daddr 172.16.1.2 tcp dport 80 counter snat to 172.16.1.1 |
| |
| nft add rule dnat1 prerouting ip saddr 172.16.1.2 tcp sport 80 counter dnat 192.168.1.2 |
| nft add rule dnat1 postrouting ip saddr 172.16.1.2 tcp sport 80 counter snat to 192.168.1.1 |