The ip command performs several actions using the command/subcommand model. To create a bridge, we use the ip link commands.
In this example, there are two NIC cards: eth0 is configured and connected to the 192.168.1.0 subnet, while eth1 is not configured but will be connected to the 10.0.0.0 subnet via the bridge:
# Create a new bridge named br0
ip link add br0 type bridge
# Add an Ethernet adapter to the bridge
ip link set dev eth1 master br0
# Configure the bridge's IP address
ifconfig br0 10.0.0.2
# Enable packet forwarding
echo 1 >/proc/sys/net/ipv4/ip_forward
This creates the bridge allowing packets to be sent from eth0 to eth1 and back. Before the bridge can be useful, we need to add this bridge to the routing tables.
On machines in the 10.0.0.0/24 network, we add a route to the 192.168.1.0/16 network:
route add -net 192.168.1.0/16 gw 10.0.0.2
Machines on the 192.168.1.0/16 subnet need to know how to find the 10.0.0.0/24 subnet. If the eth0 card is configured for IP address 192.168.1.2, the route command is as follows:
route add -net 10.0.0.0/24 gw 192.168.1.2