Difference between revisions of "Bridge with netctl"

From ArchWiki
Jump to: navigation, search
(Adding an explanation about what is a bridge)
m (rm unrelated link)
 
(34 intermediate revisions by 16 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.
+
[[ja:Netctl でブリッジ接続]]
 +
{{Related articles start}}
 +
{{Related|Network bridge}}
 +
{{Related|netctl}}
 +
{{Related articles end}}
  
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.
+
{{Merge|Network bridge|I suggest to move the netctl-specific parts of this article into a subsection of "Network bridge"}}
  
==Installation==
+
Make sure [[netctl]] is installed.
[[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}}):
+
Copy {{ic|/etc/netctl/examples/bridge}} to {{ic|/etc/netctl/bridge}}.
{{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
+
In this example, we create a bridge called {{ic|br0}} which has real Ethernet adapter {{ic|eth0}} and (optionally) a tap device {{ic|tap0}} connected to it. Of course, edit {{ic|br0}}, {{ic|eth0}} and {{ic|tap0}} to your needs.
#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.
+
{{hc|/etc/netctl/bridge|<nowiki>
BRIDGE_INTERFACES="eth0"
+
Description="Example Bridge connection"
</nowiki>}} If you are using an static ip, also edit {{ic|/etc/resolv.conf}} as necessary.
+
Interface=br0
* If {{ic|eth0}} had [[dhcpcd]] enabled, disable and stop it:
+
Connection=bridge
{{bc|
+
BindsToInterfaces=(eth0 tap0)
# systemctl stop dhcpcd@eth0.service
+
IP=dhcp
# systemctl disable dhcpcd@eth0.service
+
</nowiki>}}
}}
 
* 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]].
 
  
It provides {{ic|brctl}}, to manipulate bridges. You can use it to add a device, like this:
+
This example creates a statically assigned bridge called {{ic|br0}} which has real Ethernet adapter {{ic|eth0}} connected to it. Edit {{ic|Interface}}, {{ic|BindsToInterfaces}}, {{ic|Address}}, and {{ic|Gateway}} to your needs.
{{bc|
+
{{hc| /etc/netctl/bridge|<nowiki>
# brctl addif br0 eth1
+
Description="Example Bridge connection"
}}
+
Interface=br0
Read the manual for more info: {{ic|man brctl}}
+
Connection=bridge
 +
BindsToInterfaces=(eth0)
 +
IP=static
 +
Address='192.168.10.20/24'
 +
Gateway='192.168.10.200'
 +
## Ignore (R)STP and immediately activate the bridge
 +
SkipForwardingDelay=yes
 +
</nowiki>}}
 +
{{Tip|If you are using static IP, see man pages of [[netctl]], and also edit {{ic|/etc/resolv.conf}} if necessary.}}
 +
 
 +
This example ensures that the bridge gets assigned the MAC address of the ethernet device (reference https://github.com/joukewitteveen/netctl/issues/111 )
 +
 
 +
{{hc|/etc/netctl/bridge|<nowiki>
 +
Description="Bridge eth0-tap0"
 +
Interface=br0
 +
Connection=bridge
 +
BindsToInterfaces=(eth0 tap0)
 +
IP=no
 +
ExecUpPost="ip link set dev br0 address $(cat /sys/class/net/eth0/address); IP=dhcp; ip_set"
 +
ExecDownPre="IP=dhcp"
 +
 
 +
## Ignore (R)STP and immediately activate the bridge
 +
SkipForwardingDelay=yes
 +
</nowiki>}}
 +
 
 +
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|stop and disable]] the {{ic|dhcpcd@eth0.service}} daemon. Or set {{ic|1=IP=no}} to the netctl profiles.
 +
 
 +
Finally, [[netctl#Just one profile|start and enable]]{{Broken section link}} your {{ic|/etc/netctl/bridge}}.

Latest revision as of 08:50, 8 August 2017

Merge-arrows-2.pngThis article or section is a candidate for merging with Network bridge.Merge-arrows-2.png

Notes: I suggest to move the netctl-specific parts of this article into a subsection of "Network bridge" (Discuss in Talk:Bridge with netctl#)

Make sure netctl is installed.

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 (optionally) 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

This example creates a statically assigned bridge called br0 which has real Ethernet adapter eth0 connected to it. Edit Interface, BindsToInterfaces, Address, and Gateway to your needs.

 /etc/netctl/bridge
Description="Example Bridge connection"
Interface=br0
Connection=bridge
BindsToInterfaces=(eth0)
IP=static
Address='192.168.10.20/24'
Gateway='192.168.10.200'
## Ignore (R)STP and immediately activate the bridge
SkipForwardingDelay=yes
Tip: If you are using static IP, see man pages of netctl, and also edit /etc/resolv.conf if necessary.

This example ensures that the bridge gets assigned the MAC address of the ethernet device (reference https://github.com/joukewitteveen/netctl/issues/111 )

/etc/netctl/bridge
Description="Bridge eth0-tap0"
Interface=br0
Connection=bridge
BindsToInterfaces=(eth0 tap0)
IP=no
ExecUpPost="ip link set dev br0 address $(cat /sys/class/net/eth0/address); IP=dhcp; ip_set"
ExecDownPre="IP=dhcp"

## Ignore (R)STP and immediately activate the bridge
SkipForwardingDelay=yes

You can bridge any combination of network devices editing BindsToInterfaces option.

If any of the bridged devices (e.g. eth0, tap0) had dhcpcd enabled, stop and disable the dhcpcd@eth0.service daemon. Or set IP=no to the netctl profiles.

Finally, start and enable[broken link: invalid section] your /etc/netctl/bridge.