Linux高级网络配置

网络桥接

• 网络桥接用网络桥实现共享上网主机和客户机除了利用软件外,还可以用系统自带的网络桥建立连接用双网卡的机器做主机

网络桥接的配置

• vim /etc/sysconfig/network-scripts/ifcfg-eth0

– BRIDGE=br0

• vim /etc/sysconfig/network-scripts/ifcfg-br0

– TYPE=Bridge

网络桥接的管理命令

• brctl

### 桥接管理命令

– show ### 显示

– addbr ### 添加网桥

– delbr ### 删除网桥

– addif ### 添加网桥连接

– delif ### 删除网桥连接

www.westos.orgbond 网络

• Red Hat Enterprise Linux 允许管理员使用bonding 内核模块和称为通道绑定接口的特殊网络接口将多个网络接口绑定到一个通道。根据选择的绑定模式 , 通道绑定使两个或更多个网络接口作为一个网络接口 , 从而增加带宽和 / 提供冗余性

选择 Linux 以太网绑定模式

• 模式 0 ( 平衡轮循 ) - 轮循策略 , 所有接口都使用

采用轮循方式在所有 Slave 中传输封包 ; 任何

Slave 都可以接收

• 模式 1 ( 主动备份 ) - 容错。一次只能使用一个

Slave 接口 , 但是如果该接口出现故障 , 另一个

Slave 将 接替它

• 模式 3 ( 广播 ) - 容错。所有封包都通过所有

Slave 接口广播

利用 nmcli 命令管理 bond

• nmcli con add type bond con-name bond0

ifname bond0 mode active-backup

• nmcli con mod bond0 ipv4.addresses

1.2.3.4/24

• nmcli con add type bond-slave ifname

eth0 master bond0 con-name bond0-eth1

• nmcli con add type bond-slave ifname

eth1 master bond0 con-name bond0-eth2

主动备份配置示例

• 建立绑定接口 bond0 配置文件 :

/etc/sysconfig/network-scripts/ifcfg-bond0

– DEVICE="bond0"

– BOOTPROTO="none"

– IPADDR="10.1.1.250"

– PREFIX=”24”

– ONBOOT="yes"

– BONDING_OPTS=”mode=1 miimon=50”

• 建立 Slave 接口 eth0 配置文件 :

/etc/sysconfig/network-scripts/ifcfg-eth0

– DEVICE="eth0"

– BOOTPROTO="none"

– ONBOOT="yes"

– MASTER="bond0"

– SLAVE="yes“

• 建立 Slave 接口 eth1 配置文件 :

/etc/sysconfig/network-scripts/ifcfg-eth1

– DEVICE="eth1"

– BOOTPROTO="none"

– ONBOOT="yes"

– MASTER="bond0"

– SLAVE="yes“

• 配置系统加载 binding 模块 :

/etc/modprobe.d/bonding.conf

– alias bond0 bonding

• ifenslave bond0 eth0 eth1

• 查看 bonding 状态

– cat /proc/net/bonding/bond0

Team 接口

• Team 和 bond0 功能类似

• Team 不需要手动加载相应内核模块

• Team 有更强的拓展性

– 支持 8 快网卡

Team 的种类

broadcast

roundrobin

activebackup

loadbalance

广播容错

轮询

主备

负载均衡

通过 nmcli 设定 team

• nmcli con add type team con-name team0

ifname team0 config '{"runner": {"name":

"loadbalance"}}'

• nmcli con mod team0 ipv4.addresses 1.2.3.4/24

• nmcli con mod team0 ipv4.method manual

• nmcli con add type team-slave ifname eth0

master team0 con-name team0-eth1

• nmcli con add type team-slave ifname eth1

master team0 con-name team0-eth2

操作实例:

1.桥接

(1)图形桥接

[root@foudation37 ~]# cd /etc/sysconfig//network-scripts/

[root@foudation37 network-scripts]# rm -fr ifcfg-br0 ifcfg-salkdfnv

[root@foudation37 network-scripts]# ifconfig enp0s25

enp0s25: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 172.25.254.37  netmask 255.255.255.0  broadcast 172.25.254.255

        inet6 fe80::221:ccff:fe61:9d31  prefixlen 64  scopeid 0x20<link>

        ether 00:21:cc:61:9d:31  txqueuelen 1000  (Ethernet)

        RX packets 42308  bytes 62994602 (60.0 MiB)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 2734  bytes 196210 (191.6 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

        device interrupt 20  memory 0xd2600000-d2620000  

[root@foudation37 network-scripts]# vim ifcfg-Ethernet_connection_1

[root@foudation37 network-scripts]# vim ifcfg-br0

[root@foudation37 network-scripts]# cat ifcfg-Ethernet_connection_1

BOOTPROTO=none

NAME="Ethernet connection 1"

DEVICE=enp0s25

ONBOOT=yes

BRIDGE=br0

[root@foudation37 network-scripts]# cat ifcfg-br0DEVICE=br0

BOOTPROTO=none

TYPE=bridge

IPADDR=172.25.254.37

PREFIX=24

ONBOOT=yes

[root@foudation37 network-scripts]# systemctl stop NetworkManager.service

[root@foudation37 network-scripts]# systemctl restart network

[root@foudation37 network-scripts]# ifconfig br0

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500

        inet 172.25.254.37  netmask 255.255.255.0  broadcast 172.25.254.255

        inet6 fe80::221:ccff:fe61:9d31  prefixlen 64  scopeid 0x20<link>

        ether 00:21:cc:61:9d:31  txqueuelen 0  (Ethernet)

        RX packets 1  bytes 142 (142.0 B)

        RX errors 0  dropped 0  overruns 0  frame 0

        TX packets 22  bytes 2949 (2.8 KiB)

        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@foudation37 network-scripts]# systemctl start NetworkManager.service

2)命令桥接

[root@localhost ~]# brctl show

bridge name bridge id STP enabled interfaces

[root@localhost ~]# brctl addbr br0    ##建立br0桥接

[root@localhost ~]# brctl show

bridge name bridge id STP enabled interfaces

br0 8000.000000000000 no

[root@localhost ~]# brctl addif br0 eth0 ## 将br0插到eth0上

[root@localhost ~]brctl show

[root@localhost ~]ifconfig br0 172.25.254.237 netmask 255.255.255.0

[root@localhost ~] brctl delif br0 eth0 ##将br0从eth0上取出来

[root@localhost ~] brctl delbr br0 ##删除br0

2.bond   ##支持双网卡

1)运用virt-manger 管理器 添加eth0和eth1双网卡

2)nm-connection-editor 删除所有配置

3)

[root@localhost ~]systemctl start Networkmanger

[root@localhost ~] nmcli con-name bond0 type bond mode active-backup ip4 172.25.254.137/24

[root@localhost ~]  nmcli connection add con-name eth0 ifname eth0 type bond-slave master bond0

[root@localhost ~]  nmcli connection add con-name eth1 ifname eth1 type bond-slave master bond0

##将会有双网络卡支持工作,一个损坏,另一个会顶替

##可用 watch -n 1 cat /proc/net/bonding/bond0来监控

3.team ##最多支持8个网卡

[root@localhost ~] nmcli connection add con-name team0 ifname team0 type team config '{"runner":{“name”:“activebackup”}' ip4 172.25.254.137/24

[root@localhost ~]  nmcli connection add con-name eth0 ifname eth0 type team-slave master team0

[root@localhost ~]  nmcli connection add con-name eth1 ifname eth1 type team-slave master team0

可用 watch -n 1 teamdctl team0 stat来监控

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值