其他分享
首页 > 其他分享> > Tset 7

Tset 7

作者:互联网

1、Ubuntu系统网络配置总结(包括主机名、网卡名称、网卡配置) ~~~bash 修改主机名 root@ubuntu1804:~# hostnamectl set-hostname ubuntu1804.magedu.org root@ubuntu1804:~# cat /etc/hostname ubuntu1804.magedu.org root@ubuntu1804:~# hostname ubuntu1804.magedu.org 网卡名称 #修改配置文件为下面形式 root@ubuntu1804:~#vi /etc/default/grub GRUB_CMDLINE_LINUX="net.ifnames=0" #或者sed修改 root@ubuntu1804:~# sed -i.bak '/^GRUB_CMDLINE_LINUX=/s#"$#net.ifnames=0"#' /etc/default/grub #生效新的grub.cfg文件 root@ubuntu1804:~# grub-mkconfig -o /boot/grub/grub.cfg #或者 root@ubuntu1804:~# update-grub root@ubuntu1804:~# grep net.ifnames /boot/grub/grub.cfg       linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a-8c14- fe1a48ba153c ro net.ifnames=0       linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a- 8c14-fe1a48ba153c ro net.ifnames=0       linux /vmlinuz-4.15.0-96-generic root=UUID=51517b88-7e2b-4d4a- 8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0       linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a- 8c14-fe1a48ba153c ro net.ifnames=0       linux /vmlinuz-4.15.0-76-generic root=UUID=51517b88-7e2b-4d4a- 8c14-fe1a48ba153c ro recovery nomodeset net.ifnames=0 #重启生效 root@ubuntu1804:~# reboot 配置自动获取IP root@ubuntu1804:~# cat /etc/netplan/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 静态的IP配置 [root07:19 PMubuntu /etc/netplan]#pwd /etc/netplan [root07:10 PMubuntu /etc/netplan]#cat 02-eth1.yaml network: version: 2 renderer: networkd ethernets: eth1: addresses: [192.168.8.10/24,10.0.0.10/8] gateway4: 10.0.0.2 nameservers: search: [magedu.com, magedu.org] addresses: [180.76.76.76, 8.8.8.8, 1.1.1.1] 修改网卡配置文件后需执行命令生效: root@ubuntu1804:~#netplan apply ~~~ 2、编写脚本实现登陆远程主机。(使用expect和shell脚本两种形式)。 ~~~bash expect方式 第一步:编写文件 [root@centos7 scripts]#vim expect #!/usr/bin/expect spawn ssh 10.0.0.18 expect { "yes/no" { send "yes\n";exp_continue } "password" { send "123456\n" } } interact 第二步:加执行权限执行脚本 [root@centos7 scripts]#chmod +x expect [root@centos7 scripts]#./expect spawn ssh 10.0.0.18 root@10.0.0.18's password: Last login: Tue Jun 22 09:57:01 2021 from 10.0.0.17 [root@ ~]#hostname -I 10.0.0.18 10.0.0.118 ===================================================== shell方式 [root@centos7: script]#cat expect6.sh #!/bin/bash ip=$1 user=$2 password=$3 expect < ${nums[$next]} ));then tmp=${nums[$next]} nums[$next]=${nums[$j]} nums[$j]=$tmp fi done done echo "after sort:${nums[*]}" echo "the Min integer is ${nums[0]},the max integer is ${nums[$(( n-1 ))]}" ~~~ 5、显示统计占用系统内存最多的进程,并排序。 ~~~bash ps -aux |sort -k4nr ps aux --sort=-%mem ~~~ 6、编写脚本,使用for和while分别实现192.168.0.0/24网段内,地址是否能够ping通,若ping通则输出"success!",若ping不通则输出"fail!" ~~~bash #由于使用的是10.0.0.0/24 网段,所以用10.0.0.0/24的测试 方法一 [root@centos7 scripts]#cat 39.sh #!/bin/bash net_ip=10.0.0. for i in {1..255};do { if /bin/ping -c1 -W1 $net_ip$i >/dev/null ;then echo "$net_ip$i is UP success! " else echo "$net_ip$i is DOWN fail! " fi }& done wait 方法二: [root@centos7 scripts]#echo 10.0.0.{1..254} |tr -s " " "\n" > ip.txt [root@centos7 scripts]#cat 40.sh #!/bin/bash while read ip ;do { ping -c1 -W1 $ip >/dev/null [ $? -eq 0 ] && echo "$ip success" || echo "$ip fail" }& done

标签:ubuntu1804,10.0,grub,Tset,ip,net,root
来源: https://blog.51cto.com/u_14847540/2962030