rhel8.3 系统下修改有线网卡配置信息实现联网

rhel8.3 系统下修改有线网卡配置信息实现联网

  • 问题解决:
    • 1.查找宿主机所在局域网中空闲的IP
      • 1)方式一:nmcli modify直接修改
      • 2)方式二:删除ifcfg文件,再通过nmcli命令添加

问题描述

因为之前实验的原因,宿主机的有线网卡ip被修改了,导致无法上网,需要重新配置有线网卡信息来实现联网。

问题解决:

1.查找宿主机所在局域网中空闲的IP

首先可以通过将网卡设置为DHCP模式,获取所在局域网的路由器分配的空闲IP地址。

[root@wlb network-scripts]# pwd
/etc/sysconfig/network-scripts
[root@wlb network-scripts]# cat ifcfg-enp6s0f4u2u1 
NAME=enp6s0f4u2u1
DEVICE=enp6s0f4u2u1
ONBOOT=yes
BOOTPROTO=dhcp

[root@wlb network-scripts]# nmcli connection reload 
[root@wlb network-scripts]# nmcli connection down enp6s0f4u2u1 
Connection 'enp6s0f4u2u1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/15)
[root@wlb network-scripts]# nmcli connection up enp6s0f4u2u1 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/16)
[root@wlb network-scripts]# ip addr show enp6s0f4u2u1 
2: enp6s0f4u2u1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 2c:16:db:a5:e3:e2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.27/24 brd 192.168.1.255 scope global dynamic noprefixroute enp6s0f4u2u1
       valid_lft 86394sec preferred_lft 86394sec
[root@wlb network-scripts]# 

rhel8.3 系统下修改有线网卡配置信息实现联网_第1张图片## 2.将IP通过nmcli命令工具生存ifcfg配置文件,设置为静态IP
两种方式:

1)方式一:nmcli modify直接修改

[root@wlb network-scripts]# nmcli connection modify enp6s0f4u2u1 con-name enp6s0f4u2u1 ifname enp6s0f4u2u1 ipv4.method manual ipv4.addresses 192.168.1.27/24 ipv4.gateway 192.168.1.1 ipv4.dns 114.114.114.114  
[root@wlb network-scripts]# nmcli connection down enp6s0f4u2u1 
Connection 'enp6s0f4u2u1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/17)
[root@wlb network-scripts]# nmcli connection up  enp6s0f4u2u1 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/18)
[root@wlb network-scripts]# 
[root@wlb network-scripts]# cat ifcfg-enp6s0f4u2u1 
NAME=enp6s0f4u2u1
DEVICE=enp6s0f4u2u1
ONBOOT=yes
BOOTPROTO=none

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
IPADDR=192.168.1.27
PREFIX=24
GATEWAY=192.168.1.1
DNS1=114.114.114.114
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
UUID=3fb4a032-24a9-637d-d7a8-15a0744daa71

rhel8.3 系统下修改有线网卡配置信息实现联网_第2张图片

2)方式二:删除ifcfg文件,再通过nmcli命令添加

[root@wlb network-scripts]# rm -f ifcfg-enp6s0f4u2u1 
[root@wlb network-scripts]# nmcli connection add con-name enp6s0f4u2u1 ifname enp6s0f4u2u1 ipv4.method manual ipv4.addresses 192.168.1.27/24 ipv4.gateway 192.168.1.1 ipv4.dns 114.114.114.114  type ethernet 
Warning: There is another connection with the name 'enp6s0f4u2u1'. Reference the connection by its uuid 'baba6b0a-f1db-4e23-b120-dd8336227a54'
Connection 'enp6s0f4u2u1' (baba6b0a-f1db-4e23-b120-dd8336227a54) successfully added.
[root@wlb network-scripts]# nmcli connection reload 
[root@wlb network-scripts]# nmcli connection down enp6s0f4u2u1 
Connection 'enp6s0f4u2u1' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/19)
[root@wlb network-scripts]# nmcli connection up enp6s0f4u2u1 
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/20)
[root@wlb network-scripts]# cat ifcfg-enp6s0f4u2u1-1 
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
IPADDR=192.168.1.27
PREFIX=24
GATEWAY=192.168.1.1
DNS1=114.114.114.114
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=enp6s0f4u2u1
UUID=baba6b0a-f1db-4e23-b120-dd8336227a54
DEVICE=enp6s0f4u2u1
ONBOOT=yes
[root@wlb network-scripts]# 

rhel8.3 系统下修改有线网卡配置信息实现联网_第3张图片

此时就可以联网了。

你可能感兴趣的:(Linux运维,linux)