# Debian
# 1.必备软件安装
apt-get install net-tools sudo gnupg
1
# 2.增加sudo用户
编辑/etc/sudoers
user ALL=(ALL:ALL) ALL
1
# 3.把DVD源去掉
sudo vi /etc/apt/sources.list
1
# 4.终端设置文本
localectl
localectl set-locale LANG=en_US.UTF-8
export LC_ALL="en_US.UTF-8"
1
2
3
2
3
# 5.NFS(客户端)
apt-cache search showmount
apt install nfs-common
1
2
2
# 6.去掉安装系统时候使用的代理
编辑文件/etc/apt/apt.conf,删除代理
Acquire::http::Proxy "http://192.168.50.216:1087";
1
# 7.配置静态路由
路由追踪
traceroute 192.168.50.1
1
添加路由
ip route add 10.8.0.0/24 via 192.168.50.1
1
查看路由列表
OMV-➜ ~ ip route list
default via 192.168.50.4 dev ens192 proto static
10.8.0.0/24 via 192.168.50.1 dev ens192
172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
172.20.0.0/16 dev br-b2702b8521f6 proto kernel scope link src 172.20.0.1
192.168.50.0/24 dev ens192 proto kernel scope link src 192.168.50.3
OMV-➜ ~ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default _gateway 0.0.0.0 UG 0 0 0 ens192
10.8.0.0 RT-AX86U-6010 255.255.255.0 UG 0 0 0 ens192
172.17.0.0 0.0.0.0 255.255.0.0 U 0 0 0 docker0
172.20.0.0 0.0.0.0 255.255.0.0 U 0 0 0 br-b2702b8521f6
192.168.50.0 0.0.0.0 255.255.255.0 U 0 0 0 ens192
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
加到网络配置文件中/etc/network/interfaces
up ip route add 10.8.0.0/24 via 192.168.50.1 dev ens192
1
# 8.查看安装包释放内容
dpkg -L xxxxxx
1
# 9.SSH登陆
# 使用密码登录
编辑当前账号~/.ssh/authorized_keys文件,添加公钥。
# 允许 Root 用户名密码登录
vim /etc/ssh/sshd_config
PermitRootLogin yes
PasswordAuthentication yes
1
2
3
4
2
3
4
# 关闭root用户登陆
设置/etc/ssh/sshd_config中的PermitRootLogin值为no
vim /etc/ssh/sshd_config
service ssh restart
1
2
2
# 禁止使用密码登录
# 编辑文件 PasswordAuthentication值
vim /etc/ssh/sshd_config
# 设置 PasswordAuthentication值
PasswordAuthentication no
service ssh restart
1
2
3
4
5
2
3
4
5
# 发现SSH登录失败记录
grep "Failed password" /var/log/auth.log
1
# 配置密钥登陆
- 现在本机生成密钥对,输入以下命令:
[root@host ~]$ ssh-keygen <== 建立密钥对
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): <== 按 Enter
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): <== 输入密钥锁码,或直接按 Enter 留空
Enter same passphrase again: <== 再输入一遍密钥锁码
Your identification has been saved in /root/.ssh/id_rsa. <== 私钥
Your public key has been saved in /root/.ssh/id_rsa.pub. <== 公钥
The key fingerprint is:
0f:d3:e7:1a:1c:bd:5c:03:f1:19:f1:22:df:9b:cc:08 root@host
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
密钥锁码在使用私钥时必须输入,这样就可以保护私钥不被盗用。当然,也可以留空,实现无密码登录。
现在,在 root 用户的家目录中生成了一个 .ssh 的隐藏目录,内含两个密钥文件。id_rsa 为私钥,id_rsa.pub 为公钥。
- 在服务器上安装公钥
方式一:把共钥放到authorized_keys文件中
cat id_rsa.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh
1
2
3
2
3
方式二:使用ssh-copy-id命令自动拷贝id_rsa.pub公钥到authorized_keys
ssh-copy-id root@master01
1
- 设置 SSH,打开密钥登录功能
编辑 /etc/ssh/sshd_config 文件,进行如下设置:
RSAAuthentication yes
PubkeyAuthentication yes
1
2
2
另外,请留意 root 用户能否通过 SSH 登录:
PermitRootLogin yes
1
当你完成全部设置,并以密钥方式登录成功后,再禁用密码登录:
PasswordAuthentication no
1
# 配置远程登陆清单
- 在
.ssh文件夹中创建config文件,内容如下:
host *
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
Host bihell
HostName 堡垒机地址
Port 端口
User 用户名
IdentityFile ~/.ssh/id_rsa
ServerAliveInterval 80
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
2.直接ssh刚才配置文件中的Host名字即可 ssh bihell
# 实现 clone session
vim ~/.ssh/config
# 添加以下内容
Host *
ServerAliveInterval 30
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
ControlPersist yes
1
2
3
4
5
6
7
2
3
4
5
6
7
# 10.关闭IPV6
# 编辑 sysctl.conf
vim /etc/sysctl.conf
# 以下行以禁用 IPv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
# 加载新配置
sysctl -p
# 改动配置文件,编辑/etc/network/interfaces 或 /etc/network/interfaces.d/ 中的文件
# 没有ipv6的例子
auto eth0
iface eth0 inet dhcp
# 重启网络服务
systemctl restart networking
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 11.网络配置
# 配置静态IP
修改文件/etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
allow-hotplug ens192
iface ens192 inet static
address 192.168.50.219
netmask 255.255.255.0
gateway 192.168.50.3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
配置多个静态ip
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto ens3
iface ens3 inet static
address 192.168.50.129/24
gateway 192.168.50.1
netmask 255.255.255.0
dns-nameservers 8.8.8.8 8.8.4.4
iface ens3 inet static
address 192.168.50.156/24
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
重启服务
sudo systemctl restart networking
1
# 增加地址到网卡
sudo ip addr add 192.168.50.180/24 dev ens192
# 指定广播地址
sudo ip addr add 192.168.50.180/24 broadcast 192.168.50.255 dev ens192
ifconfig eth2 10.0.5.10 netmask 255.255.255.0 broadcast 10.0.5.255
1
2
3
4
2
3
4
# 设置网口IP
ifconfig eth0 192.168.1.10
1
# 设置子网掩码
ifconfig eth0 netmask 255.255.255.0
1
# 设置广播地址
ifconfig eth0 broadcast 192.168.1.255
1
# 删除网卡IP地址
sudo ip addr del 192.168.50.180/24 dev ens192
ifconfig eth0 0.0.0.0
1
2
2
# 显示网络接口
# 显示所有网络接口
ip a
ip link
ifconfig a
# 显示激活的网口
ifconfig
# 显示指定网络接口
ifconfig en8
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 显示网络接口统计信息
ip -s link
ip -s link show dev ens192
1
2
2
# 设置接口mtu
ip link set mtu 9000
ifconfig eth0 mtu 9000
1
2
2
# 设置接口混杂模式
ip link set em1 promisc on
ifconfig eth0 promisc
1
2
2
# 启用禁用接口
ip link set eth0 up
ip link set eth0 down
ifconfig eth0 up
ifconfig eth0 down
1
2
3
4
2
3
4
# 查看arp缓存
ip neigh
arp
# 包含统计信息
ip -s neigh
# 查看某个网口的
ip neigh show dev ens192
arp -i eth1
# 显示某个ip的arp
arp -a 192.168.1.11
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# 添加删除arp缓存
# 添加
ip neigh add 192.168.1.10 lladdr 0e:e5:20:c6:c4:75 dev eth1
arp -s 192.168.1.11 -i eth2 0e:e5:20:c6:c4:75
# 删除
ip neigh del 192.168.1.10 dev eth1
arp -i eth2 -d eth2 192.168.1.11
# 替换新增
ip neigh replace 192.168.1.10 lladdr 0e:e5:20:c6:c4:75 dev eth1
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 查看 mac 地址
[hadoop@node01 ~]$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
link/ether 00:0c:29:3c:46:fc brd ff:ff:ff:ff:ff:ff
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default
link/ether 02:42:97:23:25:8c brd ff:ff:ff:ff:ff:ff
1
2
3
4
5
6
7
2
3
4
5
6
7
# 12.重新配置默认Java版本
update-alternatives --config java
1
# 13.禁Ping
修改/etc/sysctl.conf加一行
net.ipv4.icmp_echo_ignore_all = 1
1
执行sysctl -p加载配置后生效。
临时启用Ping
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all
1
# 14.禁止IP访问
iptables -I INPUT -s 124.115.0.199 -j DROP
/etc/rc.d/init.d/iptables save
service iptables restart
1
2
3
2
3
# 15.修改DNS
vim /etc/resolv.conf
1
# 16.在PATH中添加一条新路径
export PATH="$PATH:/home/user/bin"
1
# 17.删除用户
# r 用于彻底删除,用户HOME目录下的档案会被移除,在其他位置上的档案也将一一找出并删除,比如路径/var/mail/用户名下的邮件。
userdel -r ubuntu
1
2
2
# 18.格式化硬盘
fdisk -l
fdisk /dev/sdc
mkfs.ext4 /dev/sdc
mkdir /mnt/M06
mount /dev/sdc /mnt/M06
df -h
1
2
3
4
5
6
2
3
4
5
6