VLANs on Linux

VLANs on Linux

An introduction to VLANs and VLAN trunking, how Linux interacts with VLANs and how you might use them in networks.
To begin, we must have a more formal definition of what a LAN is. LAN stands for local area network. Hubs and switches usually are thought of as participating in a single LAN. Normally, if you connect two computers to the same hub or switch, they are on the same LAN. Likewise, if you connect two switches together, they are both on the same LAN.
A LAN includes all systems in the broadcast domain. That is, all of the systems on a single LAN receive a broadcast sent by any member of that LAN. By this definition, a LAN is bordered by routers or other devices that operate at OSI Layer 3.
Now that we’ve defined a LAN, what is a VLAN? VLAN stands for virtual LAN. A single VLAN-capable switch is able to participate in multiple LANs at once.
This functionality alone has a variety of uses, but VLANs become far more interesting when combined with trunking. A trunk is a single physical connection that can carry multiple VLANs. Each frame that crosses the trunk has a VLAN identifier attached to it, so it can be identified and kept within the correct VLAN.
Trunks can be used between two switches, between a switch and a router or between a switch and a computer that supports trunking. When connecting to a router or computer, each VLAN appears as a separate virtual interface.

How to Configure Your NIC’s IP Address

You need to know all the steps needed to configure IP addresses on a NIC card. Web site shopping cart applications frequently need an additional IP address dedicated to them. You also might need to add a secondary NIC interface to your server to handle data backups. Last but not least, you might just want to play around with the server to test your skills.

This section shows you how to do the most common server IP activities with the least amount of headaches.

Determining Your IP Address

Most modern PCs come with an Ethernet port. When Linux is installed, this device is called eth0. You can determine the IP address of this device with the ifconfig command.

[root@bigboy tmp]# ifconfig -a

eth0 Link encap:Ethernet HWaddr 00:08:C7:10:74:A8
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:11 Base address:0x1820

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:787 errors:0 dropped:0 overruns:0 frame:0
TX packets:787 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:82644 (80.7 Kb) TX bytes:82644 (80.7 Kb)

wlan0 Link encap:Ethernet HWaddr 00:06:25:09:6A:B5
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:47379 errors:0 dropped:0 overruns:0 frame:0
TX packets:107900 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:4676853 (4.4 Mb) TX bytes:43209032 (41.2 Mb)
Interrupt:11 Memory:c887a000-c887b000

wlan0:0 Link encap:Ethernet HWaddr 00:06:25:09:6A:B5
inet addr:192.168.1.99 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:11 Memory:c887a000-c887b000

[root@bigboy tmp]#

Debian / Ubuntu Network Configuration

Many of the core Fedora / Redhat commands and configuration files covered in this chapter can be used in Debian based operating systems, but there are some key differences.

The /etc/network/interfaces File

The main network configuration file is the /etc/network/interfaces file in which all the network interface parameters are defined. The file is divided into stanzas:

The auto Stanza

The auto stanza defines the interfaces that should be automatically initialized when the system boots up.

The mapping Stanza

This stanza maps configuration parameters for an interface depending on the output of a script. For example, on booting the script could prompt you as to whether your laptop Linux system is at home or work with the mapping statement using the answer to configure the appropriate IP address.

By default the much simpler hotplug system is used which assumes that the interfaces will have only one purpose. Typical hotplug configurations simply assign each physical interface with a matching logical interface name (nick name).

mapping hotplug
        script grep
        map eth0 eth0
        map eth1

HOWTO OpenVPN setup(excelent)

1. First of all get a few additional repos, If you already have your repos setup, skip this step

If you have Fedora 3, follow these steps, http://stanton-finley.net/fedora_cor…notes.html#Yum

If you have Fedora 4, follow these steps, http://stanton-finley.net/fedora_cor…notes.html#Yum

If you have Fedora 5, follow these steps, http://stanton-finley.net/fedora_cor…notes.html#Yum

if you have CentOS, follow the “additional third party CentOS repos” http://www.osresources.com/11_6_en.html Then issue these commands, each line is a new command, anything beginning with “#” are comments so dont try to execute those.

# yum update
# yum install openssl openssl-devel
# openssl and openssl-devel may be installed already… so don’t worry

2. Right, now you want to install OpenVPN, here are the commands,

# yum install openvpn -y
// Now check that it works
# service openvpn start
# service openvpn stop

3. A few things to setup before you can make certificates, issue these commands,

# find / -name "easy-rsa"
// you should get an output like this
# /usr/share/doc/openvpn-2.0.7/easy-rsa
// Now, make a copy of the easy-rsa directory, to /etc/openvpn/
( make sure you #have put the right version number in i.e. mine was -2.0.7, change if needed)
# cp -R /usr/share/doc/openvpn-2.0.7/easy-rsa /etc/openvpn/
# cd /etc/openvpn/easy-rsa
# chmod 777 *
# mkdir /etc/openvpn/keys

HOWTO VPN over SSH and tun

Do it with a Script

Introduction

The following script will let you start a full featured VPN using SSH and tun.
Requirements

* OpenSSH with tun support on both sides (tested Debian 4.3 on server, Gentoo 4.5 on client)
* Root access on both sides * Allowed root access and tunnel on server side:

File: /etc/ssh/sshd_config

PermitRootLogin yes
PermitTunnel yes
TCPKeepAlive yes # Not required but makes things much more stable. This is default now
* Compiled ‘tun’ module on both sides
* Loaded ‘tun’ module on server side 
* Allowed ARP proxy (required only for accessing client from within the private network)

Howto create Loop Device on REDHAT, CENTOS or FEDORA

This mini howto explain how to create more loop device on your operating system.You need to create more loop device in some case like encrypted file system or HVM xen virtualization.  By default there are 7 devices available, named /dev/loop0 through to /dev/loop7 .

INFORMATIONS

You can find the loop device like that :

# ls -al /dev/loop*
brw-r----- 1 root disk 7, 0 Mar 19 09:34 /dev/loop0
brw-r----- 1 root disk 7, 1 Mar 19 09:34 /dev/loop1
brw-r----- 1 root disk 7, 2 Mar 19 09:34 /dev/loop2
brw-r----- 1 root disk 7, 3 Mar 19 09:34 /dev/loop3
brw-r----- 1 root disk 7, 4 Mar 19 09:34 /dev/loop4
brw-r----- 1 root disk 7, 5 Mar 19 09:34 /dev/loop5
brw-r----- 1 root disk 7, 6 Mar 19 09:34 /dev/loop6
brw-r----- 1 root disk 7, 7 Mar 19 09:34 /dev/loop7

The creation of the loop device is very simple but you have 2 options for this creation one is without reboot and the other one is with a reboot.

ConvertMboxToMailbox

Converting from UNIX mbox/mailbox to Maildir – postfix, procmail, Squirrelmail, uw-imap and cyrus-imap

This guide discusses transforming a system from the traditional mbox/mailbox format to the more advanced Maildir format.

I assume you are using the postfix mailer – if not, you will probably want to change over to postfix first or some of this material may not be relevant.

Make a backup

Before commencing, backup your entire system.

Stop the mailer

You do not want any mail coming in while doing the conversion. You should also stop any programs that automatically generate mail locally.

# /etc/init.d/postfix stop

Get the necessary tools

If you are running Debian, this command will get everything you need:

# apt-get install mb2md

Convert each users mail

For each user on your system:

 # su daniel
 $ cd ~
 $ mb2md -m
 $ mb2md -s mail
 $ exit
 # mv /var/spool/mail/daniel /var/spool/mail/daniel.preMaildir
 # mv ~daniel/mail ~daniel/mail.preMaildir

NOTE: The second mb2md command is only needed if the user has a directory ~/mail where they store mbox/mailbox format mail folders.

Later on, you will want to delete the .preMaildir versions to recover disk space. Before you do so, make sure everything is working fine.