Linux中的一块网卡可以创建多个配置文件,然后根据需要,将所需的配置文件关联到物理网卡上。
[root@sre01 ~]# nmcli con show --active
NAME UUID TYPE DEVICE
ens33 7791cb1b-8774-49e8-8eaa-fa131ab6c509 ethernet ens33
Wired connection 1 63a5614b-7b26-3011-a96b-33caa5834f07 ethernet ens36
创建一个配置文件demo,关联到网卡ens36上
[root@sre01 ~]# nmcli connection add con-name demo ipv4.addresses 11.11.11.11/24 ipv4.gateway 172.16.236.2 ipv4.dns 4.4.4.4 ipv4.method manual type ethernet ifname ens36
Connection 'demo' (83e8c326-356c-46e6-b83e-bdef791c5eb7) successfully added.
[root@sre01 ~]# nmcli connection
NAME UUID TYPE DEVICE
ens33 7791cb1b-8774-49e8-8eaa-fa131ab6c509 ethernet ens33
Wired connection 1 63a5614b-7b26-3011-a96b-33caa5834f07 ethernet ens36
demo 83e8c326-356c-46e6-b83e-bdef791c5eb7 ethernet --
重新加载新的配置
[root@sre01 ~]# nmcli connection reload
启用新配置的demo配置文件
[root@sre01 ~]# nmcli connection up demo
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/8)
[root@sre01 ~]# nmcli connection show
NAME UUID TYPE DEVICE
ens33 7791cb1b-8774-49e8-8eaa-fa131ab6c509 ethernet ens33
demo 83e8c326-356c-46e6-b83e-bdef791c5eb7 ethernet ens36
Wired connection 1 63a5614b-7b26-3011-a96b-33caa5834f07 ethernet --
[root@sre01 ~]# nmcli dev show ens36
GENERAL.DEVICE: ens36
GENERAL.TYPE: ethernet
GENERAL.HWADDR: 00:0C:29:C0:78:DB
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: demo
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/8
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 11.11.11.11/24
IP4.GATEWAY: 172.16.236.2
IP4.ROUTE[1]: dst = 11.11.11.0/24, nh = 0.0.0.0, mt = 105
IP4.ROUTE[2]: dst = 172.16.236.2/32, nh = 0.0.0.0, mt = 105
IP4.ROUTE[3]: dst = 0.0.0.0/0, nh = 172.16.236.2, mt = 105
IP4.DNS[1]: 4.4.4.4
IP6.ADDRESS[1]: fe80::b6a2:7637:c95c:843e/64
IP6.GATEWAY: --
IP6.ROUTE[1]: dst = fe80::/64, nh = ::, mt = 105
IP6.ROUTE[2]: dst = ff00::/8, nh = ::, mt = 256, table=255
[root@sre01 ~]#