RHEL7 在不同的环境中使用不同的网络配置文件
比如,我们可以设置RHEL7 系统在公司时使用一个网卡配置文件;在家时则使用另外一个配置文件(可以根据不同的环境设置多个网卡配置文件)。
网卡配置信息如下:
[root@rhel7 ~]# nmcli connection show NAME UUID TYPE DEVICE virbr0-nic e1bc371e-55c0-4196-9f53-6064f446ec47 generic virbr0-nic virbr0 6372487c-61c4-4773-bdf9-bf26a5dbb272 bridge virbr0 enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet enp0s3 [root@rhel7 ~]# ip a s enp0s3 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:73:7a:97 brd ff:ff:ff:ff:ff:ff inet 192.168.1.7/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe73:7a97/64 scope link valid_lft forever preferred_lft forever
现在添加一个网卡配置文件testEnp0s3,设置IP为192.168.1.123:
也可以手动新建testEnp0s3配置文件,并添加相应的参数。
[root@rhel7 ~]# nmcli connection add con-name testEnp0s3 ifname enp0s3 autoconnect yes type ethernet Connection 'testEnp0s3' (813b487d-fec5-4d12-8ad5-4bd3cb50a80d) successfully added. [root@rhel7 ~]# nmcli connection modify testEnp0s3 ipv4.method manual ipv4.addresses 192.168.1.123/24 ipv4.gateway 192.168.1.99 connection.autoconnect yes [root@rhel7 ~]# nmcli connection show NAME UUID TYPE DEVICE virbr0-nic e1bc371e-55c0-4196-9f53-6064f446ec47 generic virbr0-nic virbr0 6372487c-61c4-4773-bdf9-bf26a5dbb272 bridge virbr0 enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet enp0s3 testEnp0s3 813b487d-fec5-4d12-8ad5-4bd3cb50a80d 802-3-ethernet -- [root@rhel7 ~]#
把原配置文件enp0s3对应的网卡设备DEVICE enp0s3禁用,然后启用新配置文件testEnp0s3:
[root@rhel7 Desktop]# nmcli connection down enp0s3 [root@rhel7 Desktop]# nmcli connection up testEnp0s3 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/4) [root@rhel7 Desktop]# nmcli connection show NAME UUID TYPE DEVICE virbr0-nic e1bc371e-55c0-4196-9f53-6064f446ec47 generic virbr0-nic virbr0 6372487c-61c4-4773-bdf9-bf26a5dbb272 bridge virbr0 enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet -- testEnp0s3 813b487d-fec5-4d12-8ad5-4bd3cb50a80d 802-3-ethernet enp0s3 [root@rhel7 Desktop]#
查看网卡IP,已修改为192.168.1.123
[root@rhel7 ~]# ip a s enp0s3 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:73:7a:97 brd ff:ff:ff:ff:ff:ff inet 192.168.1.123/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe73:7a97/64 scope link valid_lft forever preferred_lft forever
我们可以使用相同的方法再添加其它配置文件,然后在不同的环境中使用不同的配置文件。
如果不再需要,可以把新配置文件删除,然后启用原来的网卡配置文件。
[root@rhel7 Desktop]# nmcli connection delete testEnp0s3 Connection 'testEnp0s3' (813b487d-fec5-4d12-8ad5-4bd3cb50a80d) successfully deleted. [root@rhel7 Desktop]# nmcli connection up enp0s3 Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/5) [root@rhel7 Desktop]# nmcli connection show NAME UUID TYPE DEVICE virbr0-nic e1bc371e-55c0-4196-9f53-6064f446ec47 generic virbr0-nic virbr0 6372487c-61c4-4773-bdf9-bf26a5dbb272 bridge virbr0 enp0s3 df34c879-c2bd-4c82-ae7a-39e39a2228dd 802-3-ethernet enp0s3 [root@rhel7 Desktop]# ip a s enp0s3 2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 08:00:27:73:7a:97 brd ff:ff:ff:ff:ff:ff inet 192.168.1.7/24 brd 192.168.1.255 scope global enp0s3 valid_lft forever preferred_lft forever inet6 fe80::a00:27ff:fe73:7a97/64 scope link valid_lft forever preferred_lft forever [root@rhel7 Desktop]#
*******VICTORY LOVES PREPARATION*******