1、网卡名称更改为eth*
centos:
1 [root@CentOS7 ~]# cat /etc/default/grub 2 GRUB_TIMEOUT=5 3 GRUB_DISTRIBUTOR="$(sed ‘s, release .*$,,g‘ /etc/system-release)" 4 GRUB_DEFAULT=saved 5 GRUB_DISABLE_SUBMENU=true 6 GRUB_TERMINAL_OUTPUT="console" 7 GRUB_CMDLINE_LINUX="crashkernel=auto spectre_v2=retpoline rhgb quiet net.ifnames=0 biosdevname=0" #增加net.ifnames=0 biosdevname=0 8 GRUB_DISABLE_RECOVERY="true" 9 [root@CentOS7 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33 #更改网卡配置文件 10 TYPE="Ethernet" 11 PROXY_METHOD="none" 12 BOOTPROTO="static" 13 DEFROUTE="yes" 14 NAME="eth0" #更改NAME名称为eth0 15 DEVICE="eth0" #更改DEVICE名称为eth0 16 ONBOOT="yes" 17 IPADDR=10.0.0.7 18 NETMASK=255.255.255.0 19 GATEWAY=10.0.0.2 20 DNS1=10.0.0.2 21 [root@CentOS7 ~]# mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0 #修改网卡配置文件名称为eth0 22 [root@CentOS7 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg #重新生成gurb配置并更新内核 23 Generating grub configuration file ... 24 Found linux image: /boot/vmlinuz-3.10.0-1160.el7.x86_64 25 Found initrd image: /boot/initramfs-3.10.0-1160.el7.x86_64.img 26 Found linux image: /boot/vmlinuz-0-rescue-67a276dba63741a08afb2f95b256dbcc 27 Found initrd image: /boot/initramfs-0-rescue-67a276dba63741a08afb2f95b256dbcc.img 28 done 29 [root@CentOS7 ~]# reboot #重启系统 30 [root@CentOS7 ~]# ip a #验证网卡名称 31 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 32 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 33 inet 127.0.0.1/8 scope host lo 34 valid_lft forever preferred_lft forever 35 inet6 ::1/128 scope host 36 valid_lft forever preferred_lft forever 37 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 38 link/ether 00:0c:29:dc:98:a8 brd ff:ff:ff:ff:ff:ff 39 inet 10.0.0.7/24 brd 10.0.0.255 scope global noprefixroute eth0 40 valid_lft forever preferred_lft forever 41 inet6 fe80::20c:29ff:fedc:98a8/64 scope link 42 valid_lft forever preferred_lft forever
Ubuntu:
wang@Ubuntu1804:~$ sudo vim /etc/default/grub [sudo] password for wang: wang@Ubuntu1804:~$ cat /etc/default/grub GRUB_DEFAULT=0 GRUB_TIMEOUT_STYLE=hidden GRUB_TIMEOUT=2 GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` GRUB_CMDLINE_LINUX_DEFAULT="" GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0" #增加net.ifnames=0 biosdevname=0 wang@Ubuntu1804:~$ sudo update-grub #重新生成grub配置并更新内核 Sourcing file `/etc/default/grub‘ Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.15.0-112-generic Found initrd image: /boot/initrd.img-4.15.0-112-generic done wang@Ubuntu1804:~$ sudo reboot #重启系统 wang@Ubuntu1804:~$ ifconfig #验证网卡名称 eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 10.0.0.9 netmask 255.255.255.0 broadcast 10.0.0.255 inet6 fe80::20c:29ff:fecf:1d8e prefixlen 64 scopeid 0x20<link> ether 00:0c:29:cf:1d:8e txqueuelen 1000 (Ethernet) RX packets 227 bytes 47655 (47.6 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 193 bytes 21708 (21.7 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 26 bytes 2530 (2.5 KB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 26 bytes 2530 (2.5 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、修改yum源
- 阿里镜像站点:https://developer.aliyun.com/mirror/
- 清华大学镜像站点:https://mirrors.tuna.tsinghua.edu.cn/
- 网易云镜像站点:http://mirrors.163.com/
centos配置阿里yum源:
centos7: [root@CentOS7 ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup #备份 [root@CentOS7 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo #下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/ [root@CentOS7 ~]# yum makecache #运行yum makecache生成缓存 centos8: [root@CentOS8 ~]# mv /etc/yum.repos.d/CentOS-Linux-BaseOS.repo /etc/yum.repos.d/CentOS-Linux-BaseOS.repo.backup [root@CentOS8 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo [root@CentOS8 ~]# yum makecache
Ubuntu1804配置清华大学镜像源:
1 wang@Ubuntu1804:/etc/apt$ sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup 2 wang@Ubuntu1804:/etc/apt$ sudo vim /etc/apt/sources.list 3 wang@Ubuntu1804:/etc/apt$ cat /etc/apt/sources.list 4 # 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释 5 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse 6 # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse 7 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse 8 # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse 9 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse 10 # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse 11 deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse 12 # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse 13 14 # 预发布软件源,不建议启用 15 # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse 16 # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse 17 wang@Ubuntu1804:/etc/apt$ sudo apt update
3、安装常用软件包:
centos:
# yum -y install gcc make gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel systemd-devel zlib-devel vim lrzsz tree tmux lsof tcpdump wget net-tools iotop bc bzip2 zip unzip nfs-utils man-pages redhat-lsb-core postfix mailx bash-completion man-pages
Ubuntu:
$ sudo apt -y purge ufw lxd lxd-client lxcfs lxc-common
$ sudo apt -y install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute gcc openssh-server lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip
4、配置ssh服务:
CentOS7:
# sed -i.bak -e ‘s/#UseDNS yes/UseDNS no/‘ -e ‘s/GSSAPIAuthentication yes/GSSAPIAuthentication no/‘ /etc/ssh/sshd_config # systemctl restart sshd
CentOS8:
# sed -i.bak -e ‘s/#UseDNS no/UseDNS no/‘ -e ‘s/GSSAPIAuthentication yes/GSSAPIAuthentication no/‘ /etc/ssh/sshd_config # systemctl restart sshd
Ubuntu:
$ vim /etc/ssh/sshd_config #PermitRootLogin prohibit-password PermitRootLogin yes #允许root用户登录 #UseDNS no UseDNS no #关闭DNS解析 $ sudo vim /etc/ssh/sshd_config $ sudo su - root # passwd Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully # systemctl restart sshd
5、centos禁用selinux及关闭防火墙
# sed -ri.bak ‘s/^(SELINUX=).*/\1disabled/‘ /etc/selinux/config # systemctl disable --now firewalld
6、设置.vimrc
#!/bin/bash # UserName=your name QQ=your QQ UserURL=your URL set_vimrc(){ cat >.vimrc <<EOF set ts=4 set expandtab set ignorecase autocmd BufNewFile *.sh exec ":call SetTitile()" func SetTitile() if expand("%:e") == ‘sh‘ call setline(1,"#!/bin/bash") call setline(2,"#") call setline(3,"#*************************************************************************************") call setline(4,"#Author: $UserName") call setline(5,"#QQ: $QQ") call setline(6,"#Date: ".strftime("%Y-%m-%d")) call setline(7,"#FileName ".expand("%")) call setline(8,"#URL: $UserURL") call setline(9,"#Description: The test script") call setline(10,"#Copyreght (C): ".strftime("%Y")." All rightsreserved") call setline(11,"#*************************************************************************************") call setline(12,"") endif endfunc autocmd BufNewFile * normal G EOF echo -e "\e[1;31m vimrc设置完成 \e[0m" } set_vimrc