3 # Author: Amos Kong <kongjianjun@gmail.com>
5 # Description: this script is used to create/delete a private bridge,
6 # launch a dhcp server on the bridge by dnsmasq.
8 # @ ./set_private_br.sh $bridge_name $subnet_prefix
9 # @ ./set_private_br.sh vbr0 192.168.33
16 echo "add new private bridge: $brname"
17 /usr
/sbin
/brctl addbr
$brname
18 echo 1 > /proc
/sys
/net
/ipv
6/conf
/$brname/disable_ipv6
19 echo 1 > /proc
/sys
/net
/ipv
4/ip_forward
20 /usr
/sbin
/brctl stp
$brname on
21 /usr
/sbin
/brctl setfd
$brname 0
22 ifconfig
$brname $subnet.1
24 # Add forward rule, then guest can access public network
25 iptables
-t nat
-A POSTROUTING
-s $subnet.254/24 ! -d $subnet.254/24 -j MASQUERADE
26 /etc
/init.d
/dnsmasq stop
27 /etc
/init.d
/tftpd-hpa stop
2>/dev
/null
28 dnsmasq
--strict-order --bind-interfaces --listen-address $subnet.1 --dhcp-range $subnet.1,$subnet.254 $tftp_cmd
33 echo "cleanup bridge setup"
34 kill -9 `pgrep dnsmasq|tail -1`
36 /usr
/sbin
/brctl delbr
$brname
37 iptables
-t nat
-D POSTROUTING
-s $subnet.254/24 ! -d $subnet.254/24 -j MASQUERADE