CentOS7 修改网卡名与网络修复

Linux网卡改名与网络故障时紧急网络修复方法

CentOS7 修改网卡名

# 切换到网卡配置目录
cd /etc/sysconfig/network-scripts/
# 复制网卡配置文件为ifcfg-eth0
cp -a ifcfg-ens33 ifcfg-eth0
# 备份原文件到opt目录下
mv ifcfg-ens33 /opt/
#查看当前目录下的全部文件
[root@localhost network-scripts]# ls
ifcfg-eth0   ifdown-ipv6    ifdown-TeamPort  ifup-ippp   ifup-routes       network-functions
ifcfg-lo     ifdown-isdn    ifdown-tunnel    ifup-ipv6   ifup-sit          network-functions-ipv6
ifdown       ifdown-post    ifup             ifup-isdn   ifup-Team
ifdown-bnep  ifdown-ppp     ifup-aliases     ifup-plip   ifup-TeamPort
ifdown-eth   ifdown-routes  ifup-bnep        ifup-plusb  ifup-tunnel
ifdown-ib    ifdown-sit     ifup-eth         ifup-post   ifup-wireless
ifdown-ippp  ifdown-Team    ifup-ib          ifup-ppp    init.ipv6-global
root@localhost network-scripts]# vim ifcfg-eth0 #修改配置文件
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="static"     # 连接方式(static/dhcp)
DEFROUTE="yes"        
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="eth0"        # 网卡名称,centos7默认为ens33
UUID="453ef40b-c53f-44d1-a677-d1aa1817c111"
DEVICE="eth0"    # 设备名称,centos7默认为ens33
ONBOOT="yes"    # 是否开机加载
IPADDR=192.168.233.99     # 静态ip地址
GATEWAY=192.168.233.2     # 网关
NETMASK=255.255.255.0    # 子网掩码 centos7的写法(PREFIX=24)
DNS1=180.76.76.76        # 主DNS
DNS2=124.251.124.251    # 备DNS
[root@localhost ~]# source /etc/sysconfig/network-scripts/ifcfg-eth0 
[root@localhost ~]# cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 180.76.76.76
nameserver 124.251.124.251
# 修改grub文件(关闭一致性命名规则)俗称自动发现功能
root@localhost network-scripts]# cd /etc/default/
[root@localhost default]# ls
grub  nss  useradd
[root@localhost default]# vim grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0" 
# 在双引号里面加入net.ifnames=0 biosdevname=0
GRUB_DISABLE_RECOVERY="true"
[root@localhost default]# grub2-mkconfig -o /boot/grub
grub/  grub2/ 
[root@localhost default]# grub2-mkconfig -o /boot/grub2/grub
grub.cfg  grubenv
# 更新grub配置文件,并且加载新的参数
[root@localhost default]# grub2-mkconfig -o /boot/grub2/grub.cfg 
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-862.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-862.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-ab4dc40e801c4059bf95d9a36e28d173
Found initrd image: /boot/initramfs-0-rescue-ab4dc40e801c4059bf95d9a36e28d173.img
done
[root@localhost default]# 
reboot # 重启系统
# 重启系统之后发现网卡名已经更改为eth0
[root@localhost ~]# ip address show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:0c:29:cc:e1:91 brd ff:ff:ff:ff:ff:ff
    inet 192.168.233.99/24 brd 192.168.233.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::8d56:af45:bfeb:db65/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:aa:fa:dd brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:aa:fa:dd brd ff:ff:ff:ff:ff:ff
[root@localhost ~]# 

路之修复网络

root@localhost network-scripts]# nmcli connection delete eth0
Connection 'eth0' (453ef40b-c53f-44d1-a677-d1aa1817c111) successfully deleted.
[root@localhost network-scripts]# nmcli connection add con-name eth666 type ethernet ifname eth0 autoconnect yes 
Connection 'eth666' (577dc8f5-8efa-40a3-8ecf-b2a134e2e405) successfully added.
[root@localhost network-scripts]# nmcli connection show 
NAME                UUID                                  TYPE      DEVICE 
Wired connection 1  01806e22-d18f-3434-9d4e-757711fa509a  ethernet  eth0   
virbr0              f749af6e-b9aa-4f29-a100-4a86e68724d7  bridge    virbr0 
eth666              577dc8f5-8efa-40a3-8ecf-b2a134e2e405  ethernet  --    
[root@localhost network-scripts]# nmcli connection modify eth666 ipv4.method auto 
[root@localhost network-scripts]# cat ifcfg-eth666 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth666
UUID=577dc8f5-8efa-40a3-8ecf-b2a134e2e405
DEVICE=eth0
ONBOOT=yes
[root@localhost network-scripts]# 
[root@localhost network-scripts]# ping allms.cn
PING allms.cn.localdomain (115.159.76.237) 56(84) bytes of data.
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=1 ttl=128 time=54.8 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=2 ttl=128 time=54.4 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=3 ttl=128 time=64.9 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=4 ttl=128 time=55.3 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=5 ttl=128 time=55.7 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=6 ttl=128 time=55.0 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=7 ttl=128 time=55.5 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=8 ttl=128 time=62.8 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=9 ttl=128 time=54.9 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=10 ttl=128 time=55.3 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=11 ttl=128 time=55.2 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=12 ttl=128 time=54.4 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=13 ttl=128 time=119 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=14 ttl=128 time=55.2 ms
64 bytes from 115.159.76.237 (115.159.76.237): icmp_seq=15 ttl=128 time=469 ms
^C
--- allms.cn.localdomain ping statistics ---
15 packets transmitted, 15 received, 0% packet loss, time 14027ms
rtt min/avg/max/mdev = 54.440/88.190/469.652/103.181 ms
[root@localhost network-scripts]# 

添加新评论

已有 1 条评论