centos7 网络配置

ip a 查看网卡名

  1. _config_network() {
  2. cat > /etc/sysconfig/network-scripts/ifcfg-ens33 <<EOF
  3. TYPE="Ethernet"
  4. BOOTPROTO="static"
  5. NAME="ens33"
  6. DEVICE="ens33"
  7. ONBOOT="yes"
  8. IPADDR=192.168.143.139
  9. GATEWAY=192.168.143.2
  10. NETMASK=255.255.255.0
  11. DNS1=223.5.5.5
  12. EOF
  13. systemctl restart network
  14. }
  15. _config_network

centos7网络仓库

  1. _config_repo() {
  2. rpm -qe wget >/dev/null 2>&1
  3. if [ $? -eq 1 ];then
  4. yum install -y wget
  5. fi
  6. mkdir -p /etc/yum.repos.d/back
  7. mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/back/
  8. curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  9. curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  10. rm -rf /var/cache/yum/*
  11. yum makecache fast
  12. }
  13. _config_repo

centos8网络配置

ip a查看网卡名

  1. _config_network() {
  2. cat > /etc/sysconfig/network-scripts/ifcfg-ens33 <<EOF
  3. TYPE=Ethernet
  4. BOOTPROTO=static
  5. NAME=ens33
  6. DEVICE=ens33
  7. ONBOOT=yes
  8. IPADDR=192.168.143.102
  9. PREFIX=24
  10. GATEWAY=192.168.143.2
  11. DNS1=114.114.114.114
  12. EOF
  13. systemctl restart NetworkManager
  14. ifdown ens33 ;ifup ens33
  15. }
  16. _config_network

centos8网络仓库

  1. _config_repo() {
  2. mkdir -p /etc/yum.repos.d/back
  3. mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/back/
  4. wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
  5. yum -y install epel-release
  6. rm -rf /var/cache/yum/*
  7. yum makecache
  8. }
  9. _config_repo

回归传统命名

修改网络信息,reboot一下

  1. nfig_eth0() {
  2. cat > /etc/sysconfig/network-scripts/ifcfg-ens33 <<EOF
  3. TYPE=Ethernet
  4. BOOTPROTO=static
  5. NAME=eth0
  6. DEVICE=eth0
  7. ONBOOT=yes
  8. IPADDR=192.168.143.102
  9. PREFIX=24
  10. GATEWAY=192.168.143.2
  11. DNS1=114.114.114.114
  12. EOF
  13. mv /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-eth0
  14. mkdir -p /etc/default/grub/back
  15. cp /etc/default/grub /etc/default/grub/back/
  16. cat > /etc/default/grub <<EOF
  17. GRUB_TIMEOUT=5
  18. GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
  19. =saved
  20. GRUB_DISABLE_SUBMENU=true
  21. GRUB_TERMINAL_OUTPUT="console"
  22. 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"
  23. GRUB_DISABLE_RECOVERY="true"
  24. GRUB_ENABLE_BLSCFG=true
  25. EOF
  26. grub2-mkconfig -o /etc/grub2.cfg
  27. }
  28. _config_eth0