centos7 网络配置
ip a 查看网卡名
_config_network() {
cat > /etc/sysconfig/network-scripts/ifcfg-ens33 <<EOF
TYPE="Ethernet"
BOOTPROTO="static"
NAME="ens33"
DEVICE="ens33"
ONBOOT="yes"
IPADDR=192.168.143.139
GATEWAY=192.168.143.2
NETMASK=255.255.255.0
DNS1=223.5.5.5
EOF
systemctl restart network
}
_config_network
centos7网络仓库
_config_repo() {
rpm -qe wget >/dev/null 2>&1
if [ $? -eq 1 ];then
yum install -y wget
fi
mkdir -p /etc/yum.repos.d/back
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/back/
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
rm -rf /var/cache/yum/*
yum makecache fast
}
_config_repo
centos8网络配置
ip a查看网卡名
_config_network() {
cat > /etc/sysconfig/network-scripts/ifcfg-ens33 <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.143.102
PREFIX=24
GATEWAY=192.168.143.2
DNS1=114.114.114.114
EOF
systemctl restart NetworkManager
ifdown ens33 ;ifup ens33
}
_config_network
centos8网络仓库
_config_repo() {
mkdir -p /etc/yum.repos.d/back
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/back/
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
yum -y install epel-release
rm -rf /var/cache/yum/*
yum makecache
}
_config_repo
回归传统命名
修改网络信息,reboot一下
nfig_eth0() {
cat > /etc/sysconfig/network-scripts/ifcfg-ens33 <<EOF
TYPE=Ethernet
BOOTPROTO=static
NAME=eth0
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.143.102
PREFIX=24
GATEWAY=192.168.143.2
DNS1=114.114.114.114
EOF
mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0
mkdir -p /etc/default/grub/back
cp /etc/default/grub /etc/default/grub/back/
cat > /etc/default/grub <<EOF
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto resume=/dev/mapper/cl-swap rd.lvm.lv=cl/root rd.lvm.lv=cl/swap net.ifnames=0 biosdevname=0 rhgb quiet"
GRUB_DISABLE_RECOVERY="true"
GRUB_ENABLE_BLSCFG=true
EOF
grub2-mkconfig -o /etc/grub2.cfg
}
_config_eth0