Linux修改网卡命令规则和配置IP地址(简单易懂,方便易学)


一、修改网卡命令规则

[[email protected] ~]# vim /etc/default/grub

在这里插入图片描述
找到quiet 在后面添加一句net.ifnames=0 biosdevname=0

[[email protected] ~]# grub2-mkconfig  -o  /boot/grub2/grub.cfg  #让网卡命名规则生效

[[email protected] ~]# reboot #重启

二、nmcli命令修改ip

1.删除错误网卡命名

[[email protected] ~]# nmcli  connection  show #查看

[[email protected] ~]# nmcli   connection   delete   ens33 #删除错误网卡命名

[[email protected] ~]# nmcli   connection   delete   有线连接\ 1


2.添加网卡命名

[[email protected] ~]# nmcli connection add type ethernet  ifname eth0   con-name eth0

3.修改IP地址、子网掩码、网关地址

[[email protected] ~]#nmcli connection modify  eth0    
ipv4.method    manual                #手工配置           
ipv4.addresses   192.168.4.7/24      #ip           
ipv4.gateway   192.168.4.254         #网关       
connection.autoconnect    yes		 #开机自启动

[[email protected] ~] nmcli connection up eth0  #激活

[[email protected] ~]# ifconfig |head -2    #查看一下
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.4.7  netmask 255.255.255.0  broadcast 192.168.4.255

[[email protected] ~]# ip a s  #另一种查看方式

4.通过网卡配置文件修改IP

[[email protected] ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
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
UUID=e409c5fd-f6f1-4c00-b684-be38e2f2848d
DEVICE=eth0
ONBOOT=yes
IPADDR=192.168.4.7
PREFIX=24
GATEWAY=192.168.4.254
ZONE=


最后送给大家一句话“不积跬步无以至千里,不积小流无以成江海”。

猜你喜欢

转载自blog.csdn.net/ring__wang/article/details/108585221