1、Ubuntu系统网络配置总结(包括主机名、网卡名称、网卡配置)
主机名
root@ubuntu:~# hostnamectl set-hostname hostname
root@ubuntu:~# vim /etc/hostname
hostname
root@ubuntu:~# vim /etc/hosts
.....
127.0.1.1 hostname
.....
网卡名称
root@ubuntu:~# vim /etc/default/grub
.....
GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0"
root@ubuntu:~# vim /etc/netplan/00-installer-config.yaml
......
eth0:
root@ubuntu:~# grub-mkconfig -o /boot/grub/grub.cfg
root@ubuntu:~# reboot
网卡配置
root@gitlab:~# vim /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
eth0:
addresses:
- 172.16.0.10/24
gateway4: 172.16.0.254
version: 2
2、编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)。
expect
#!/bin/bash
. /etc/init.d/functions
rpm -q expect &> /dev/null || yum -y install expect &> /dev/null
PASS=123456
ssh-keygen -P "" -f /root/.ssh/id_rsa &> /dev/null
while read IP;do
expect &> /dev/null <<EOF
spawn ssh-copy-id root@$IP
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$PASS\n" }
}
expect eof
EOF
action $IP
done < hosts.list
[root@localhost ~]# vim hosts.list
172.16.0.10
172.16.0.20
172.16.0.30
shell
#!/bin/bash
. /etc/init.d/functions
rpm -q sshpass &> /dev/null || yum -y install sshpass &> /dev/null
HOSTS="
172.16.0.10
172.16.0.20
172.16.0.30
"
PASS=123456
ssh-keygen -P "" -f /root/.ssh/id_rsa &> /dev/null
for i in $HOSTS;do
{
sshpass -p $PASS ssh-copy-id -o StrictHostKeyChecking=no $i &> /dev/null && action $i
}&
done
wait
3、生成10个随机数保存于数组中,并找出其最大值和最小值
#!/bin/bash
declare -i min max
declare -a nums
for ((i=0;i<10;i++));do
nums[$i]=$RANDOM
[ $i -eq 0 ] && min=${nums[0]} && max=${nums[0]} && continue
[ ${nums[$i]} -gt $max ] && max=${nums[$i]} && continue
[ ${nums[$i]} -gt $min ] && min=${nums[$i]}
done
echo "${nums[*]}"
echo Max is $max
echo Min is $min
4、输入若干个数值存
#!/bin/bash
while true;do
read -p ">> " num
if [ $num == "q" ];then
break
fi
echo $num
done