Konfigurieren Sie das Bridge-Netzwerk auf dem Linux-Server
Hintergrund
Some times we need to create plenty of virtual machines or containers in a physical linux server and there is a requirement that all the virtual machines or containers have unique ip address, besides all ip address must in same subnet with the physical server.
We can configure bridge network to realize this requirement. Let all the virtual adapters bridged to physical network.
Condition
In physical server(suppose that system is RHEL6 or centos6)
eth0:
ip: 192.168.137.41 Netzmaske: 255.255.255.0 gateway: 192.168.137.1
in virtual machines
eth0:
ip: 192.168.7.x netmask: 255.255.255.0 gateway: 192.168.137.1
Steps
1. create virtual adapter ifcfg-br0,formate like below
NAME=br0
DEVICE=br0
BOOTPROTO=none
NM_CONTROLLED=no
ONBOOT=yes
IPADDR=192.168.137.41
NETMASK=255.255.255.0
GATEWAY=192.168.137.1
USERCTL=no
TYPE=Bridge
PEERDNS=yes
IPV6INIT=no
2. Modify physical adapter ifcfg-eth0,formate like below.
DEVICE=eth0
HWADDR=00:0C.:29:F0:D5:3D.
TYPE=Ethernet
UUID=07ca40d2-253d-4052-ab92-42f269b86c77
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
NAME=”System eth0″
USERCTL=no
PEERDNS=yes
IPV6INIT=no
BRIDGE=br0
3. Restart netwok service
As you know, restarting netwrok service from remote is a dangerous operation, especially you are not sure whether the network configuration
is correct or not. the network probability won’t up if configuration isn’t right , this means that you can’t access this server from remote connection any more. So I highly suggest that you’d better restart network server in local .
Result
[root @ localhost ~]# ip a
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc mq state UP qlen 1000
link/ether 3c:a8:2ein:ed:b5:f0 brd ff:ff:ff:ff:ff:ff
inet6 fe80::3ea8:2aff:feed:b5f0/64 scope link
valid_lft forever preferred_lft forever
3: br0: mtu 1500 qdisc noqueue state UNKNOWN
link/ether 3c:a8:2ein:ed:b5:f0 brd ff:ff:ff:ff:ff:ff
inet 192.168.137.41/24 brd 192.168.7.255 scope global br0
inet6 fe80::3ea8:2aff:feed:b5f0/64 scope link
It’s obviously that bridge network adaptor br0 has same mac address with physical network adapter eth0 and ip 192.168.7.50 had been migrated from eth0 to br0. This means that eth0 had bridged to br0. If there is a need that eth0 send or receive message ,the traffic must pass by br0.
If in RHEL7 or CentOS7
The configuration of network adapter ifcfg-eth0 and ifcfg-br0 may like below.
ichfcfg-br0
NAME=br0
DEVICE=br0
BOOTPROTO=none
NM_CONTROLLED=no
ONBOOT=yes
IPADDR=192.168.137.41
NETMASK=255.255.255.0
GATEWAY=192.168.137.1
USERCTL=no
TYPE=Bridge
PEERDNS=yes
IPV6INIT=no
ifcfg-br0
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=64b46db6-9122-44d8-9444-f186eb04a240
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0