Difference between revisions of "Bridge with netctl"

From ArchWiki
Jump to: navigation, search
(Adding an explanation about what is a bridge)
m (Configuration: fixed link; style)
(12 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
[[Category:Networking]]
 
[[Category:Networking]]
A bridge is a piece of software used to unite two or more network segments. A bridge behaves like a virtual network switch, working transparently (the other machines don't need to know or care about its existance). Real devices (like '''eth''' ones) and virtual devices (like '''tap''' ones) can be connected to it.
+
A bridge is a piece of software used to unite two or more network segments. A bridge behaves like a virtual network switch, working transparently (the other machines don't need to know or care about its existence). Any real devices (e.g. {{ic|eth0}}) and virtual devices (e.g. {{ic|tap0}}) can be connected to it.
  
This article explains how to create a bridge that contains at least a ethernet device. This is useful for things like the bridge mode of qemu, setting a software based access point, etc.
+
This article explains how to create a bridge that contains at least an ethernet device. This is useful for things like the bridge mode of [[QEMU]], setting a software based access point, etc.
  
==Installation==
+
== Installation ==
[[pacman|Install]] the {{Pkg|netcfg}} package from the [[Official Repositories|official repositories]].
+
==Configuration==
+
* Enable the {{ic|bridge}} module:
+
{{bc|
+
# modprobe bridge
+
}}
+
And to make it permanent, add it to your {{ic|/etc/modules-load.d}}:
+
{{bc|
+
echo bridge>/etc/modules-load.d/bridge.conf
+
}}
+
  
* Create a bridge called {{ic|br0}} to have, at least, your real Ethernet adapter (assuming {{ic|eth0}}):
+
[[pacman|Install]] the {{Pkg|netctl}} package from the [[Official Repositories|official repositories]].
{{hc|
+
/etc/network.d/bridge|<nowiki>
+
INTERFACE="br0"
+
CONNECTION="bridge"
+
DESCRIPTION="Bridge"
+
IP='dhcp'
+
  
#Uncomment this fields as necessary if you are using a static ip instead
 
#IP='static'
 
#ADDR='10.0.0.1'
 
#GATEWAY='10.0.0.1'
 
#DNS=('8.8.8.8')
 
 
# Add your network adapter(s) here, separated by spaces.
 
BRIDGE_INTERFACES="eth0"
 
</nowiki>}} If you are using an static ip, also edit {{ic|/etc/resolv.conf}} as necessary.
 
* If {{ic|eth0}} had [[dhcpcd]] enabled, disable and stop it:
 
{{bc|
 
# systemctl stop dhcpcd@eth0.service
 
# systemctl disable dhcpcd@eth0.service
 
}}
 
* Then enable and start your {{ic|br0}} bridge:
 
{{bc|
 
# systemctl start netcfg@bridge.service
 
# systemctl enable netcfg@bridge.service
 
}}
 
==Tips and Tricks==
 
===Manually adding/removing network devices===
 
 
[[pacman|Install]] the {{Pkg|bridge-utils}} package from the [[Official Repositories|official repositories]].
 
[[pacman|Install]] the {{Pkg|bridge-utils}} package from the [[Official Repositories|official repositories]].
  
It provides {{ic|brctl}}, to manipulate bridges. You can use it to add a device, like this:
+
== Configuration ==
{{bc|
+
 
# brctl addif br0 eth1
+
* Copy {{ic|/etc/netctl/examples/bridge}} to {{ic|/etc/netctl/bridge}}.
}}
+
* In this example, we create a bridge called {{ic|br0}} which has real Ethernet adapter {{ic|eth0}} and a tap device {{ic|tap0}} connected to it. Of course, edit {{ic|br0}}, {{ic|eth0}} and {{ic|tap0}} to your needs.
Read the manual for more info: {{ic|man brctl}}
+
 
 +
{{hc|/etc/netctl/bridge|<nowiki>
 +
Description="Example Bridge connection"
 +
Interface=br0
 +
Connection=bridge
 +
BindsToInterfaces=(eth0 tap0)
 +
IP=dhcp
 +
## sets forward delay time
 +
#FwdDelay=0
 +
## sets max age of hello message
 +
#MaxAge=10
 +
</nowiki>}}
 +
 
 +
{{Tip|If you are using static IP, see man pages of [[netctl]], and also edit {{ic|/etc/resolv.conf}} if necessary.}}
 +
 
 +
* You can bridge any combination of network devices editing {{ic|BindsToInterfaces}} option.
 +
* If any of the bridged devices (e.g. {{ic|eth0}}, {{ic|tap0}}) had [[dhcpcd]] enabled, [[systemd#Using units|disable and stop]] the {{ic|dhcpcd@eth0.service}} daemon. Or set {{ic|1=IP=no}} to the netctl profiles.
 +
* Finally, [[netctl#Just one profile|enable and start]] your {{ic|/etc/netctl/bridge}}.
 +
 
 +
== Tips and tricks ==
 +
 
 +
=== Manually adding/removing network devices ===
 +
 
 +
The {{Pkg|bridge-utils}} package provides tool ''brctl'' to manipulate bridges. You can use it to manually add or remove a device from a bridge:
 +
 
 +
# brctl addif br0 eth1
 +
# brctl delif br0 eth0
 +
 
 +
See {{ic|brctl(8)}}
 +
 
 +
=== Wireless interface on a bridge ===
 +
 
 +
To add a wireless interface to a bridge, you first have to assign the wireless interface to an access point or start an access point with hostapd. Otherwise the wireless interface won't be added to the bridge.

Revision as of 09:53, 23 July 2013

A bridge is a piece of software used to unite two or more network segments. A bridge behaves like a virtual network switch, working transparently (the other machines don't need to know or care about its existence). Any real devices (e.g. eth0) and virtual devices (e.g. tap0) can be connected to it.

This article explains how to create a bridge that contains at least an ethernet device. This is useful for things like the bridge mode of QEMU, setting a software based access point, etc.

Installation

Install the netctl package from the official repositories.

Install the bridge-utils package from the official repositories.

Configuration

  • Copy /etc/netctl/examples/bridge to /etc/netctl/bridge.
  • In this example, we create a bridge called br0 which has real Ethernet adapter eth0 and a tap device tap0 connected to it. Of course, edit br0, eth0 and tap0 to your needs.
/etc/netctl/bridge
Description="Example Bridge connection"
Interface=br0
Connection=bridge
BindsToInterfaces=(eth0 tap0)
IP=dhcp
## sets forward delay time
#FwdDelay=0
## sets max age of hello message
#MaxAge=10
Tip: If you are using static IP, see man pages of netctl, and also edit /etc/resolv.conf if necessary.
  • You can bridge any combination of network devices editing BindsToInterfaces option.
  • If any of the bridged devices (e.g. eth0, tap0) had dhcpcd enabled, disable and stop the dhcpcd@eth0.service daemon. Or set IP=no to the netctl profiles.
  • Finally, enable and start your /etc/netctl/bridge.

Tips and tricks

Manually adding/removing network devices

The bridge-utils package provides tool brctl to manipulate bridges. You can use it to manually add or remove a device from a bridge:

# brctl addif br0 eth1
# brctl delif br0 eth0

See brctl(8)

Wireless interface on a bridge

To add a wireless interface to a bridge, you first have to assign the wireless interface to an access point or start an access point with hostapd. Otherwise the wireless interface won't be added to the bridge.