Thursday, June 30, 2011

How to configure network bridge / VLAN on linux machine?

Setup bridge network :

Why bridge : Virtually connect multiple Ethernets in one interface(virtual). May be wireless and physical Ethernet will be connected together for communication.

Install required package :

#yum install bridge-utils

Let machine has two NIC eth0 and eth1 :

So, change it like :

1. vi /etc/sysconfig/network-scripts/ifcfg-eth0

---
DEVICE=eth0
TYPE=Ethernet
HWADDR=##:##:##:##:##:##
ONBOOT=yes
BRIDGE=br0
---

2. vi /etc/sysconfig/network-scripts/ifcfg-eth1

---
DEVICE=eth1
TYPE=Ethernet
WADDR=##:##:##:##:##:##
ONBOOT=yes
BRIDGE=br0
---

3. create a file ifcfg-br0 for the bridge device br0. vi /etc/sysconfig/network-scripts/ifcfg-br0 (Note IP address has been mentioned here)

For static :

---
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.24
NETMASK=255.255.255.0
GATEWAY=192.168.1.254
DELAY=0
STP=off
---

For DHCP :

---
DEVICE=br0
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=dhcp
DELAY=0
STP=off
---

4. service network restart
5. test : brctl show

==========
How to setup VLAN network on linux ?

Why VLAN : create a virual lan(grouping some computers from actual LAN with out using any switch/routers etc. Only needs software. Can also be done using hardware)

Required Packages :

#yum install vconfig

Next, go to the /etc/sysconfig/network-scripts directory and decide which eth# device you're going to add a VLAN to. Note that the VLAN device will run alongside (in parallel to, at the same time) as the original eth# device, so there is no need to change your existing configuration.

1. copy /etc/sysconfig/network-scripts/ifcfg-eth0 to etc/sysconfig/network-scripts/ifcfg-eth0.2 and edit : VLAN=yes like :
---
DEVICE=eth0.2
VLAN=yes
TYPE=Ethernet
HWADDR=##:##:##:##:##:##
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.24
GATEWAY=192.168.1.254
---

Note : VLAN id is here 2 for eth0

2. Do for other nic and increase VLAN ID and check like ifconfig
3. Restart network service. That's it.
------
How to make bridge over VLAN?

Bridging over VLAN's :

By constructing a bridge between a "normal" and a "VLAN" ethernet interface, the Linux computer will add and remove the VLAN headers on behalf of any other device(s) plugged into the "normal" card.

How :

Okay, now for the tricky part. It takes a slight modification of the procedures above. For this example, let's presume we have an Ethernet interface eth0 connected to the network where a VLAN id 2 is present, and we have a device or devices on eth1 that need to be bridged into that VLAN 2.

Go ahead and first construct the VLAN interface like we did before (copy ifcfg-eth#, change DEVICE, add VLAN=yes), except also remove the BOOTPROTO, IPADDR, NETMASK, and GATEWAY lines if present. Add a line BRIDGE=br2 (or a different named bridge device of your choice).

1. vi /etc/sysconfig/network-scripts/ifcfg-eth0.2 (connected to VLAN2)

---
DEVICE=eth0.2
VLAN=yes
TYPE=Ethernet
HWADDR=##:##:##:##:##:##
ONBOOT=yes
BRIDGE=br2
----

2. vi /etc/sysconfig/network-scripts/ifcfg-eth1

--
DEVICE=eth1
TYPE=Ethernet
WADDR=##:##:##:##:##:##
ONBOOT=yes
BRIDGE=br2
---

3. vi /etc/sysconfig/network-scripts/ifcfg-br2

----
DEVICE=br2
TYPE=Bridge
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.2.24
NETMASK=255.255.255.0
GATEWAY=192.168.2.254
DELAY=0
STP=off
---

Note : IP address has in br2

4. service network restart. That's it.

Try :)

No comments:

Post a Comment