文章目录
- 系统说明
- openEuler23.03系统手动配置ip流程
- 修改名称
- 生成网卡配置文件【openEuler23.03系统添加网卡文件配置流程】
- 手动指定ip
- 添加ipv6地址
- 修改配置文件信息和名称
- 删除创建的网卡信息
- 重启网卡生效并测试
- openEuler23.03系统网络管理说明
系统说明
我这用云上最小化安装的openEuler23.03系统为例,其他细版本同理
[root@openeuler ~]# cat /etc/openEuler-release
openEuler release 23.03
[root@openeuler ~]#
openEuler23.03系统手动配置ip流程
修改名称
- 新创建的虚拟机,nmcli con命令看到的NAME和网卡名称可能不是一致的,此时就需要将NAME手动修改为和DEVICE一致,否则可能会出问题
[root@openeuler ~]# nmcli con show
NAME UUID TYPE DEVICE
cloud-init ens3 fbc49833-4cdb-548b-a293-c38b39836fdb ethernet ens3
[root@openeuler ~]# nmcli con modify 'cloud-init ens3' con-name ens3
[root@openeuler ~]# nmcli con show
NAME UUID TYPE DEVICE
ens3 fbc49833-4cdb-548b-a293-c38b39836fdb ethernet ens3
[root@openeuler ~]#
- 可以看到,默认情况下,网卡配置文件中没有网卡文件,如果手动直接vi添加,可能会出各种问题,需要用nmcli命令添加
[root@openeuler ~]# cd /etc/sysconfig/network-scripts/
[root@openeuler network-scripts]# ls
[root@openeuler network-scripts]#
- 我这做了上面操作以后,没几分钟ssh掉了,后台查看发现ip丢了,重启了下网络服务恢复正常。
经过排查,是因为虚拟机没有固定IP,所以过一会ip就会掉,固定IP以后该问题消失。
生成网卡配置文件【openEuler23.03系统添加网卡文件配置流程】
- 我们用nmcli命令创建一个自命名的网卡文件,这样网卡配置文件下就会自动生成一个文件了
root@openeuler network-scripts]# nmcli con
NAME UUID TYPE DEVICE
ens3 fbc49833-4cdb-548b-a293-c38b39836fdb ethernet ens3
[root@openeuler network-scripts]#
[root@openeuler network-scripts]# nmcli con add type ethernet con-name ens3.bak ifname eth3.bak
Connection 'ens3.bak' (8f62c526-ff97-4706-983d-7a071be677cc) successfully added.
[root@openeuler network-scripts]# nmcli con
NAME UUID TYPE DEVICE
ens3 fbc49833-4cdb-548b-a293-c38b39836fdb ethernet ens3
ens3.bak 8f62c526-ff97-4706-983d-7a071be677cc ethernet --
[root@openeuler network-scripts]# ls
ifcfg-ens3.bak
[root@openeuler network-scripts]# cat ifcfg-ens3.bak
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=ens3.bak
UUID=8f62c526-ff97-4706-983d-7a071be677cc
DEVICE=eth3.bak
ONBOOT=yes
[root@openeuler network-scripts]#
手动指定ip
给刚才创建的配置文件手动指定ip,直接用nmcli命令简单些
[root@openeuler network-scripts]#
[root@openeuler network-scripts]# nmcli con modify ens3.bak ipv4.addresses "11.22.33.82/24" ipv4.gateway "11.22.33.254" ipv4.method manual
[root@openeuler network-scripts]# ls
ifcfg-ens3.bak
[root@openeuler network-scripts]# cat ifcfg-ens3.bak
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=ens3.bak
UUID=8f62c526-ff97-4706-983d-7a071be677cc
DEVICE=eth3.bak
ONBOOT=yes
IPADDR=11.22.33.82
PREFIX=24
GATEWAY=11.22.33.254
[root@openeuler network-scripts]#
添加ipv6地址
- 直接vi刚才的配置文件,在最后面添加v6的配置信息即可【bclinux添加v6信息也一样,都是下面新增部分内容】
- v6地址:
IPV6ADDR=2409:818e:38cc:114::219
- v6网关:
IPV6_DEFAULTGW=2409:818e:38cc:114::201
- v6地址:
[root@openeuler network-scripts]# vi ifcfg-ens3.bak
[root@openeuler network-scripts]# cat ifcfg-ens3.bak
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=ens3.bak
UUID=b232667c-c868-4bd5-91cb-0847fa6e3768
DEVICE=ens3.bak
ONBOOT=yes
IPADDR=11.22.33.82
PREFIX=24
GATEWAY=11.22.33.254
#-----IPv6------
IPV6_AUTOCONF=no
IPV6INIT=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6ADDR=2409:818e:38cc:114::219
IPV6_DEFAULTGW=2409:818e:38cc:114::201
DHCPV6C=none
[root@openeuler network-scripts]#
修改配置文件信息和名称
- 执行nmcli复制真实网卡的uuid名称。
- 配置文件修改3个地方
NAME=ens3.bak
【去掉.bak,和真实的保持一致】UUID=b232667c-c868-4bd5-91cb-0847fa6e3768
【修改为真实的uuid】DEVICE=ens3
【去掉.bak,和真实的保持一致】
- 修改后如下【uuid不要注释后加一行,执行当行修改,我是为了让你们容易理解才新增一行的】
[root@openeuler network-scripts]# nmcli con
NAME UUID TYPE DEVICE
ens3 fbc49833-4cdb-548b-a293-c38b39836fdb ethernet ens3
ens3.bak aa6cbcde-5a9a-4870-b879-37ab51ea05b2 ethernet --
[root@openeuler network-scripts]# vi ifcfg-ens3.bak
[root@openeuler network-scripts]# mv ifcfg-ens3.bak ifcfg-ens3
[root@openeuler network-scripts]# cat ifcfg-ens3
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=ens3
#UUID=b232667c-c868-4bd5-91cb-0847fa6e3768
UUID=fbc49833-4cdb-548b-a293-c38b39836fdb
DEVICE=ens3
ONBOOT=yes
IPADDR=11.22.33.82
PREFIX=24
GATEWAY=11.22.33.254
#-----IPv6------
IPV6_AUTOCONF=no
IPV6INIT=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6ADDR=2409:818e:38cc:114::219
IPV6_DEFAULTGW=2409:818e:38cc:114::201
DHCPV6C=none
[root@openeuler network-scripts]#
删除创建的网卡信息
如下,直接删除
[root@openeuler ~]# nmcli con
NAME UUID TYPE DEVICE
ens3 fbc49833-4cdb-548b-a293-c38b39836fdb ethernet ens3
ens3.bak aa6cbcde-5a9a-4870-b879-37ab51ea05b2 ethernet --
[root@openeuler ~]#
[root@openeuler ~]#
[root@openeuler ~]# nmcli con delete ens3.bak
Connection 'ens3.bak' (aa6cbcde-5a9a-4870-b879-37ab51ea05b2) successfully deleted.
[root@openeuler ~]# nmcli con
NAME UUID TYPE DEVICE
ens3 fbc49833-4cdb-548b-a293-c38b39836fdb ethernet ens3
[root@openeuler ~]#
重启网卡生效并测试
- 重启命令有2个
- 方式1:
systemctl restart NetworkManager
- 方式2:
nmcli con down ens3 && nmcli con up ens3
- 方式1:
[root@openeuler network-scripts]# ip a
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: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether fa:16:3e:45:76:52 brd ff:ff:ff:ff:ff:ff
inet 11.22.33.82/24 brd 11.22.33.255 scope global noprefixroute ens3
valid_lft forever preferred_lft forever
inet6 fe80::8c94:3fab:23a7:89/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@openeuler network-scripts]#
[root@openeuler network-scripts]# systemctl restart NetworkManager
[root@openeuler network-scripts]#
[root@openeuler network-scripts]# ip a
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: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether fa:16:3e:45:76:52 brd ff:ff:ff:ff:ff:ff
inet 11.22.33.82/24 brd 11.22.33.255 scope global noprefixroute ens3
valid_lft forever preferred_lft forever
inet6 2409:818e:38cc:114::219/64 scope global noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::8c94:3fab:23a7:89/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@openeuler network-scripts]#
[root@openeuler network-scripts]# nmcli con down ens3 && nmcli con up ens3
Connection 'ens3' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/1)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/2)
[root@openeuler network-scripts]#
[root@openeuler network-scripts]# ip a
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: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether fa:16:3e:45:76:52 brd ff:ff:ff:ff:ff:ff
inet 11.22.33.82/24 brd 11.22.33.255 scope global noprefixroute ens3
valid_lft forever preferred_lft forever
inet6 2409:818e:38cc:114::219/64 scope global noprefixroute
valid_lft forever preferred_lft forever
inet6 fe80::8c94:3fab:23a7:89/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@openeuler network-scripts]#
[root@openeuler network-scripts]# ping6 2409:818e:38cc:114::201
PING 2409:818e:38cc:114::201(2409:818e:38cc:114::201) 56 data bytes
64 bytes from 2409:818e:38cc:114::201: icmp_seq=1 ttl=64 time=17.9 ms
64 bytes from 2409:818e:38cc:114::201: icmp_seq=2 ttl=64 time=2.31 ms
^C
--- 2409:818e:38cc:114::201 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 2.311/10.080/17.850/7.769 ms
[root@openeuler network-scripts]#
- ssh没断,说明ipv4是没问题的,我这直接ping6地址的网关,通了就证明配置一切正常
[root@openeuler network-scripts]# ping6 2409:818e:38cc:114::201
PING 2409:818e:38cc:114::201(2409:818e:38cc:114::201) 56 data bytes
64 bytes from 2409:818e:38cc:114::201: icmp_seq=1 ttl=64 time=17.9 ms
64 bytes from 2409:818e:38cc:114::201: icmp_seq=2 ttl=64 time=2.31 ms
^C
--- 2409:818e:38cc:114::201 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 2.311/10.080/17.850/7.769 ms
[root@openeuler network-scripts]#
openEuler23.03系统网络管理说明
-
欧拉系统网络服务和bclinux8+一样,都是基于
NetworkManager
服务,重启网卡直接重启NetworkManager
服务即可 -
欧拉系统的网络管理使用nmcli命令即可,nmcli的命令使用和centos一致。