网络配置多会话实验
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了网络配置多会话实验相关的知识,希望对你有一定的参考价值。
- nmcli配置多会话
- 绑定两块网卡
-
实验1
网卡支持多会话功能,由于工作环境不同,需要配置不同的网络:如在家里使用使用DHCP获取,在公司使用固定ip,如果使用修改方式比较麻烦,配置多会话功能,在不同场景激活即可。
实验环境:
centos7、home:DHCP、company:static,自动连接
配置过程:配置信息会保存至/etc/sysconfig/network-scripts/ifcfg-name- 添加会话
[[email protected] ~]# nmcli connection add con-name company autoconnect yes ifname ens36 type ethernet Connection ‘company‘ (46f14092-152e-4af3-9273-5acbf573b2a2) successfully added. [[email protected] ~]# nmcli connection add con-name home autoconnect no ifname ens36 type ethernet Connection ‘home‘ (d3c8a326-e494-47b9-b6ea-92f18998b9b6) successfully added. [[email protected] ~]# nmcli connection show NAME UUID TYPE DEVICE eno16777736 2361aff4-2de8-4868-9fd6-5d30ccdada02 802-3-ethernet eno16777736 home d3c8a326-e494-47b9-b6ea-92f18998b9b6 802-3-ethernet -- company 46f14092-152e-4af3-9273-5acbf573b2a2 802-3-ethernet ens36 [[email protected] ~]# nmcli device status DEVICE TYPE STATE CONNECTION eno16777736 ethernet connected eno16777736 ens36 ethernet connected company lo loopback unmanaged --
-
修改IP地址
如果不修改默认为自动分配;
[[email protected] ~]# nmcli connection modify company ipv4.addresses 172.16.0.10/16 ipv4.method manual
还可以配置DNS、gateway... - 查看效果
- 添加会话
[[email protected] ~]# systemctl restart network #重启服务
[[email protected] ~]# nmcli device status #ens36当前自动连接至company会话
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet connected eno16777736
ens36 ethernet connected company
lo loopback unmanaged --
[[email protected] ~]# ifconfig ens36 #ens36的ip信息配置正常
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.0.10 netmask 255.255.0.0 broadcast 172.16.255.255
inet6 fe80::20c:29ff:fe20:b507 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:20:b5:07 txqueuelen 1000 (Ethernet)
RX packets 187 bytes 23730 (23.1 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 88 bytes 10998 (10.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[[email protected] ~]# nmcli connection up home #将网卡会话切换至home会话
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/9)
[[email protected] ~]# nmcli device status
DEVICE TYPE STATE CONNECTION
eno16777736 ethernet connected eno16777736
ens36 ethernet connected home #ens36当前会话状态
lo loopback unmanaged --
[[email protected] ~]# ifconfig ens36 #此时ip信息是自动获取
ens36: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.175.133 netmask 255.255.255.0 broadcast 192.168.175.255
inet6 fe80::20c:29ff:fe20:b507 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:20:b5:07 txqueuelen 1000 (Ethernet)
RX packets 190 bytes 24476 (23.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 98 bytes 12306 (12.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
以上是关于网络配置多会话实验的主要内容,如果未能解决你的问题,请参考以下文章