Skip to content

Instantly share code, notes, and snippets.

@moqmar
Last active May 28, 2018 17:18
Show Gist options
  • Save moqmar/c20b80ef213007e452a228cd137fdfdb to your computer and use it in GitHub Desktop.
Save moqmar/c20b80ef213007e452a228cd137fdfdb to your computer and use it in GitHub Desktop.
Adding a network bridge with IP address under Linux
[Unit]
Description=Network Bridge
After=syslog.target network.target
[Service]
Type=onehot
ExecStart=/opt/bridge.sh
[Install]
WantedBy=multi-user.target
#!/bin/bash
# Enable strict mode (http://redsymbol.net/articles/unofficial-bash-strict-mode/)
IFS=$'\n\t'
set -exuo pipefail
# Add bridge
brctl addbr br0
# Add interfaces
ip link set down enp2s0
ip link set down enp3s0
brctl addif br0 enp2s0
brctl addif br0 enp3s0
# Connect
ip link set up enp2s0
ip link set up enp3s0
ip link set up dev br0
# Assign IP address
ip addr add dev br0 10.0.0.10/24 broadcast 10.0.0.255
route add default gw 10.0.0.1 dev br0
# Allow the bridge in the firewall
iptables -A FORWARD -p all -i br-pi -j ACCEPT
# More information: https://wiki.archlinux.org/index.php/Network_bridge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment