1蝴猪、Ubuntu系統(tǒng)網(wǎng)絡(luò)配置總結(jié)(包括主機(jī)名漓摩、網(wǎng)卡名稱裙士、網(wǎng)卡配置)
1、主機(jī)名修改(永久生效)
法一管毙、修改/etc/hostname文件
法二腿椎、hostnamectrl set-hostname ***
修改完后重新登陸即可
2、網(wǎng)卡名稱修改
ubuntu系統(tǒng)的網(wǎng)卡命名采用的是biosdevname設(shè)備名命名方式夭咬,想要修改網(wǎng)卡名需修改成傳統(tǒng)的命名方式:
a啃炸、修改/etc/default/grub文件,在GRUB_CMDLINE_LINUX=""里添加net.ifnames=0卓舵。
b南用、重構(gòu)啟動(dòng)文件:grub_mkconfig -o /boot/grub/grub.cfg
c、重啟生效
將網(wǎng)卡命名方式改成傳統(tǒng)命名方式后掏湾,在/etc/netplan/下會(huì)生成一個(gè)yaml類型的文件
root@ubuntu180401:/etc/netplan# cat 01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: yes
對(duì)配置文件進(jìn)行修改裹虫,將eth0改成想命名的網(wǎng)卡名即可。
3融击、網(wǎng)卡配置
在2的基礎(chǔ)上進(jìn)行修改配置yaml文件即對(duì)網(wǎng)卡進(jìn)行配置筑公。
2、編寫腳本實(shí)現(xiàn)登陸遠(yuǎn)程主機(jī)尊浪。(使用expect和shell腳本兩種形式)匣屡。
##expect腳本形式
[root@CentOS8 ~]#cat Login_expect
#涩拙!/usr/bin/expect
set ip [lindex $argv 0]
set user [lindex $argv 1]
set passwd [lindex $argv 2]
set timeout 20
spawn ssh $user@$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"passwd" { send "$passwd\n" }
}
expect "]#" { send hostname }
expect eof
##bash shell腳本形式
[root@CentOS8 ~]#cat Login_bash.sh
#!/bin/bash
ip=$1
user=$2
passwd=$3
expect <<EOF
set timeout 20
spawn ssh $user$ip
expect {
"yes/no" { send "yes\n";exp_continue }
"passwd" { send "$passwd\n" }
}
expect eof
EOF
3、生成10個(gè)隨機(jī)數(shù)保存于數(shù)組中耸采,并找出其最大值和最小值
[root@CentOS8 ~]#cat random_number.sh
#!/bin/bash
for((i=0;i<10;i++));do
a[$i]=$[$RANDOM%20]
if [ $i -eq 0 ];then
min=${a[0]}
max=${a[0]}
continue
fi
[ ${a[$i]} -gt $max ] && max=${a[$i]}
[ ${a[$i]} -lt $min ] && min=${a[$i]}
done
echo "All number is ${a[@]}"
echo "max=$max,min=$min"
4、輸入若干個(gè)數(shù)值存入數(shù)組中工育,采用冒泡算法進(jìn)行升序或降序排序
[root@CentOS8 ~]#cat bubbling.sh
#!/bin/bash
#升序排列
read -p "Please enter some numbers: " -a array_num
count=${#array_num[@]}
for((i=0;i<$count;i++));do
for((j=$[$i+1];j<$count;j++));do
if [ ${array_num[i]} -gt ${array_num[j]} ];then
tmp=${array_num[i]}
array_num[i]=${array_num[j]}
array_num[j]=$tmp
fi
done
done
for((i=0;i<count;i++));do
echo ${array_num[i]}
done
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者