Ubuntu中如何搭建网桥?

by LauCyun Apr 8,2016 11:45:18 13,164 views

1 安装 uml-utilities

该工具包含建立虚拟网络设备(所谓的“TAP interfaces”)的工具: 

ubuntu@localhost:~$ sudo apt-get install uml-utilities 

2 安装 bridge-utils 

ubuntu@localhost:~$ sudo apt-get install bridge-utils

3 配置 /etc/network/interfaces

ubuntu@localhost:~$ sudo vim /etc/network/interfaces

其配置前的内容:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

其配置后的内容:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet static
	address 192.168.1.104
	network 192.168.1.0
	netmask 255.255.255.0
	broadcast 192.168.1.255
	gateway 192.168.1.1
	dns-nameservers 8.8.8.8
	bridge_ports eth0
	bridge_fd 9
	bridge_hello 2
	bridge_maxage 12
	bridge_stp off

4 修改/etc/sysctl.conf实现转发

上面实现了网桥,但该网桥还不能转发数据,因为在默认情况下,linux系统是不能转发数据的,我们可以通过修改配置文件/etc/sysctl.conf来实现转发,修改地方如下:

# Uncomment the next line to enable packetforwarding for IPv4
net.ipv4.ip_forward=1            # 去掉这一行最前面的注释(#号)

# Uncomment the next line to enable packetforwarding for IPv6
net.ipv6.conf.all.forwarding=1   # 去掉这一行最前面的注释(#号)

修改完之后执行/etc/init.d/procps  restart重启服务。详细可参考:http://www.ducea.com/2006/08/01/how-to-enable-ip-forwarding-in-linux/

5 启动网桥

ubuntu@localhost:~$ sudo /sbin/ifup br0 

重启网络:

ubuntu@localhost:~$ sudo /etc/init.d/networking restart

ubuntu@localhost:~$ sudo restart network-manager

(全文完)

Tags