1、Ubuntu系统网络配置总结(包括主机名、网卡名称、网卡配置)
主机名:
root@template-ubuntu:~# hostnamectl set-hostname ubuntu.example.com
配置文件/etc/hostname.-
网卡名称:统一为传统的命名eth格式
root@ubuntu1804:~#vi /etc/default/grub GRUB_CMDLINE_LINUX="net.ifnames=0 #生效新的grub.cfg文件 root@ubuntu1804:~# grub-mkconfig -o /boot/grub/grub.cfg #或者 root@ubuntu1804:~# update-grub
-
网卡配置:/etc/netplan/*.yaml
network: version: 2 renderer: networkd ethernets: eth0: dhcp4: no dhcp6: no addresses: [192.168.1.10/24] gateway4: 192.168.1.252 nameservers: addresses: [223.6.6.6] # 生效 root@template-ubuntu:~# netplan apply
2、编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)。
#!/usr/bin/expect
set ip 10.0.0.7
set user root
set password magedu
set timeout 10
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"password" { send "$password\n" }
}
interact
3、生成10个随机数保存于数组中,并找出其最大值和最小值
#!/bin/bash
declare -a array
declare -i min max
for i in {0..9}; do
array[$i]=$[$RANDOM%100]
# echo ${array[$i]}
done
min=${array[0]}
max=${array[0]}
for ((i=1;i<10;i++));do
[ ${array[$i]} -gt $max ] && max=${array[$i]}
[ ${array[$i]} -lt $min ] && min=${array[$i]}
done
echo "All numbers(0--99) are ${array[*]}"
echo Max is $max
echo Min is $min
4、输入若干个数值存入数组中,采用冒泡算法进行升序或降序排序
root@nginx-web1:~# vim 2.sh
#!/bin/bash
declare -a arr
declare -i min max
for i in {0..9}; do
arr[$i]=$[$RANDOM%100]
done
echo -e "The random number(0-99) is:\n ${arr[*]}"
a=${#arr[*]}
for ((i=1; i<$a; i++))
do
for ((j=0; j<$a-i; j++))
do
if [ ${arr[$j]} -gt ${arr[$[$j + 1]]} ];then
temp=${arr[$j]}
arr[$j]=${arr[$[$j + 1]]}
arr[$[$j+1]]=$temp
fi
done
done
echo -e "Pot sort the number is:\n ${arr[*]}"