神刀安全网

Build a network bridge with Fedora

Network switches are common these days. You can even find quite a few designed for home use. But you can also build a virtual switch using a network bridge in Fedora.

Maybe you have a complex home network requirement. You might want to firewall some systems from others. Maybe you want to research how network protocols work. Or perhaps you just have extra hardware and want to learn more about enterprise level networking. You can use Fedora on any system with two or more network adapters to build a bridge for this purpose .

A bridge is a network connection that combines multiple network adapters. This way devices attached via the different adapters can talk to each other. The devices behave as if directly connected with a normal network switch. They can speak any local network protocol such as Samba or NFS to each other.

The bridge in this scenario is a virtual switch. It serves the same function as any switch to which you connect multiple systems in a single network. In this case, since the switch runs Fedora, you can precisely configure, log, monitor, analyze, or automate in practically any way you can imagine.

Using brctl

The brctl utility allows you to set up and inspect network bridges at the command line. To create a new bridge, use this command:

brctl addbr br0

You can then add physical network interfaces to the bridge using brctl. These commands add the  eth0 and  eth1  interfaces to the bridge just created:

brctl addif br0 eth0 brctl addif br0 eth1

Now you can create an IP address on the bridge host, so it can be addressed on the network:

ip address add 192.168.1.100/24 dev br0

If you’d like to see the configuration of the bridge, use this command:

brctl show br0

While these commands will properly set up a bridge, the network setup won’t be persistent. In other words, when you reboot the system, you’d have to set up the bridge again.

Persistent bridge configuration

Let’s assume one of the network adapters to be connected to the bridge is eth0 . You may want to start by making a backup of the configuration file:

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

Now create a configuration file for the bridge br0 with the following contents, as /etc/sysconfig/network-scripts/ifcfg-br0 :

DEVICE=br0 TYPE=Bridge IPADDR=192.168.1.100 NETMASK=255.255.255.0 ONBOOT=yes BOOTPROTO=none NM_CONTROLLED=no DELAY=0

Adjust the configuration of the eth0 network adapter as follows, as  /etc/sysconfig/network-scripts/ifcfg-eth0:

DEVICE=eth0 TYPE=Ethernet HWADDR=AA:BB:CC:DD:EE:FF BOOTPROTO=none ONBOOT=yes NM_CONTROLLED=no BRIDGE=br0

For each additional network adapter to be added to the bridge, adjust the configuration file accordingly. Note this configuration removes each adapter from the control of NetworkManager, the automatic network service. The directive NM_CONTROLLED=no sets this property.

Image courtesy Johnny Lam –  originally posted to Unsplash  as  Connect

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Build a network bridge with Fedora

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址