CentOS:
1、配置临时网桥,重启后风格配置丢失
[[email protected] ~]# yum -y install bridge-utils
[[email protected] ~]# brctl addbr br0 #创建网桥逻辑接口
[[email protected] ~]# brctl addif br0 eth0 #将eth0网卡添加到网桥中
[[email protected] ~]# brctl addif br0 eth1 #将eth1网卡添加到网桥中
[[email protected] ~]# ifconfig eth0 0.0.0.0 #将eth0网卡设为为混杂模式
[[email protected] ~]# ifconfig eth1 0.0.0.0 #将eth1网卡设为为混杂模式
[[email protected] ~]# ifconfig br0 #查看桥网卡配置
[[email protected] ~]# ifconfig br0 10.10.10.82/24 #给桥网卡设置IP地址
2、创建永久网桥
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-br0 #创建网桥配置文件
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=172.16.100.1
NETMASK=255.255.255.0
ONBOOT=yes
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 #将网卡加入到网桥中
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=0.0.0.0
BRIDGE=br0
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth1 #将网卡加入到网桥中
DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=0.0.0.0
BRIDGE=br0
Debian:
1、配置临时网桥
[email protected]:~# apt-get install bridge-utils #安装依赖包
[email protected]:~# brctl addbr br0 #创建网桥
[email protected]:~# ifconfig br0 up #启用网桥
[email protected]:~# ip addr show #查看网桥
[email protected]:~# brctl addif br0 eth0 eth1 #将网卡加入到网桥
[email protected]:~# brctl delif br0 eth1 #从网桥中删除eth1网卡
[email protected]:~# ifconfig br0 down #关闭网桥
[email protected]:~# brctl delbr br0 #删除网桥
2、创建永久网桥
[email protected]:~# nano /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
# auto lo br0 两行写成一行
auto lo
auto br0
iface lo inet loopback
iface br0 inet static
iface eth0 inet manual
iface eth1 inet manual
address 10.1.1.122
broadcast 10.1.1.255
netmask 255.255.255.0
gateway 10.1.1.1
bridge_ports eth0 eth1 #把eth0,eth1加入到网桥
bridge_stp off # disable Spanning Tree Protocol
bridge_waitport 0 # no delay before a port becomes available
bridge_fd 0 # no forwarding delay