The result of tag: (2 results)

CentOS6中如何搭建网桥?

by LauCyun Aug 08,2016 13:05:18 7,736 views

首先,安装bridge-utils

[root@localhost ~]# yum install -y bridge-utils

检查一下是否安装成功:

[root@localhost ~]# brctl --version
bridge-utils, 1.2

查看一下当前的网卡信息:

[root@localhost ~]# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:83:D9:2B
          inet addr:192.168.0.163  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe83:d92b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:71757 errors:0 dropped:0 overruns:0 frame:0
          TX packets:40145 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:106907729 (101.9 MiB)  TX bytes:2869292 (2.7 MiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:960 (960.0 b)  TX bytes:960 (960.0 b)

接着创建一个名为br0的网桥:

[root@localhost ~]# brctl addbr br0

接着,把网卡eth0绑定在网桥br0上:

[root@localhost ~]# brctl stp br0 off
[root@localhost ~]# brctl addif br0 eth0
[root@localhost ~]# ifconfig br0 up

查看一下网桥br0的信息:

[root@localhost ~]# brctl show
bridge name	bridge id		STP enabled	interfaces
br0		8000.08002783d92b	no		eth0

好了,网桥br0已经创建好了,那么接下来配置网桥br0

[root@localhost ~]# touch /etc/sysconfig/network-scripts/ifcfg-br0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.230
NETMASK=255.255.255.0
GATEWAY=192.168.0.1

接下来配置网卡eth0

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BRIDGE=br0

注意:请勿添加其它配置项(如GATEWAYBOOTPROTO等),否则会导致桥接配置失败!

然后,重启网络服务:

[root@localhost ~]# service NetworkManager restart

如果重启网卡不起作用的话,就重启系统reboot

查看网卡信息:

[root@localhost ~]# ifconfig
br0       Link encap:Ethernet  HWaddr 08:00:27:83:D9:2B
          inet addr:192.168.0.230  Bcast:192.168.0.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe83:d92b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1965 errors:0 dropped:0 overruns:0 frame:0
          TX packets:171 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:440135 (429.8 KiB)  TX bytes:51639 (50.4 KiB)

eth0      Link encap:Ethernet  HWaddr 08:00:27:83:D9:2B
          inet6 addr: fe80::a00:27ff:fe83:d92b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1973 errors:0 dropped:0 overruns:0 frame:0
          TX packets:185 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:468125 (457.1 KiB)  TX bytes:52965 (51.7 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:960 (960.0 b)  TX bytes:960 (960.0 b)

OK,大功告成!

最后,附上删除网桥的方法:

[root@localhost ~]# brctl delif br0 eth0  # 解除和eth0的绑定
[root@localhost ~]# ifconfig br0 down     # 停止网桥br0
[root@localhost ~]# brctl delbr br0       # 删除网桥br0
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0  # 重置网卡eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=dhcp

(全文完)

...

Tags Read More


Ubuntu中如何搭建网桥?

by LauCyun Apr 08,2016 11:45:18 11,609 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 Read More