linux系统中高级网络控制

                             高级网络控制:

一.配置网络桥接

二.配置bond网络接口

三.配置team网络接口



一.配置网络桥接(真机):

1.  cd /etc/sysconfig/network-scripts/      进入目录

2.ls                                                              显示文件


3.mv ifcfg-br0 ifcfg-enp0s25  /mnt/        把文件备份到/mnt

4.ifconfig                                 查看网卡名称


5.vim ifcfg-enp0s25                        编辑配置文件配置网卡信息内容:

DEVICE=enp0s25

ONBOOT=yes

BOOTPROTO=none

IPADDR=172.25.254.7

PREFIX=24


6.reboot                                                     重启

7.cd /etc/sysconfig/network-scripts/       进入目录

8.ls                                                              显示文件

9.rm -fr ifcfg-iPhone__-2-               

删除ifcfg开头的文件,除了ifcfg-br0  ifcfg-enp0s25    ifcfg-lo

10.vim ifcfg-enp0s25                        编辑配置文件把网卡信息改为br0

内容:

DEVICE=enp0s25

ONBOOT=yes

BOOTPROTO=none

BRIDGE=br0

11.vim ifcfg-br0                            编辑配置文件搭建桥接

内容:

DEVICE=br0

ONBOOT=yes

BOOTPROTO=none

IPADDR=172.25.254.7

NETMASK=255.255.255.0

TYPE=Bridge

12.systemctl restart network                重启网络

13.reboot                                               重启(可以不重启)

14.brctl show                                         查看桥接

删除桥接:

1.rm -fr ifcfg-enp0s25

  rm -fr ifcfg-br0                 删除自己搭建的桥接

2.mv /mnt/ifcfg-* .                恢复之前备份的桥接

临时搭建桥接(虚拟机):

1.brctl show                查看桥接

2.brctl addbr  br0                                添加br0

3.ifconfig  br0  172.25.254.207           添加ip

4.ip addr show                                    查看ip

5.brctl addif br0 eth0       添加桥接

6.brctl show                    查看桥接

删除桥接:

1.brctl   delif  br0 eth0     删除桥接

2.ifconfig  br0  down       把br0下下来(如果不down下来删不掉)

3.brctl  delbr   br0           删除br0

bond主备:

1.watch -n 1 /proc/net/bonding/bond0   监控命令

2.virt-manager   打开虚拟机管理器,点open,点灯泡,ADD Hardware,Network,Device model添加一块网卡。

3.nmcli connection delete  “system eth0”                删除网卡配置

4.systemctl start NetworkManager                            打开网络

5.nmcli connection add con-name bond0 ifname bond0 type bond mode active-backup ip4 172.25.254.207/24                                                  添加bond地址,类型ipv4

6.nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0                                                                           添加网卡

7.ping 172.25.254.7                                                    ping网络

8.nmcli connection add con-name eth1 ifname eth1 type bond-slave

master bond0                                                                 添加网卡

9.ifdown  eth0                                                             down掉eth0,那么eth1就会定上去工作

ping的172.25.254.7主机网络没断。


删除bond主备:

1.nmcli connection delete eth0   删除eth0

2.nmcli connection delete eth1   删除eth1

3.nmcli connection delete bond0  删除bond0

ping的172.25.254.7主机网络ping 不通。

三.配置team网络接口

平衡轮循:wtach -n 1 teamdctl team0 stat   监控命令

1.nmcli connection add type team con-name team0 ifname team0 config '{"runner":{"name":"activebackup"}}'  ip4 172.25.254.171/24

添加team网络接口


2.nmcli connection add con-name eth0 type team-slave ifname eth0 master team0         添加eth0网卡

3.nmcli connection add con-name eth1 type team-slave ifname eth1 master team0         添加eth1网卡

4.systemctl restart network    重启网络

5.ifconfig eth0 down           down掉eth0,eth1会工作

6.ifconfig eth0 up             添加eth0

删除team网络接口:

1.nmcli connection delete eth0   删除eth0

2.nmcli connection delete eth1   删除eth1

3.nmcli connection delete team0  删除team0