一、upgrade kernel

It need linux kernel support mpls stack.Such kernel 4.6.

需要linux内核支持mpls模块,更新内核。

1.下载模块并安装

1
2
3
4
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.6-yakkety/linux-headers-4.6.0-040600_4.6.0-040600.201606100558_all.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.6-yakkety/linux-headers-4.6.0-040600-generic_4.6.0-040600.201606100558_amd64.deb
wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.6-yakkety/linux-image-4.6.0-040600-generic_4.6.0-040600.201606100558_amd64.deb
dpkg -i *.deb

(amd64字段要根据系统调整,此处为64位系统)

2.重启系统

1
2
update-grub
reboot

 

二、Enable MPLS in kernel

调整MPLS内核参数,启用MPLS stack。

1
2
3
4
5
6
modprobe mpls_router
modprobe mpls_gso
modprobe mpls_iptunnel
sysctl -w net.mpls.conf.ens33.input=1
sysctl -w net.mpls.conf.lo.input=1
sysctl -w net.mpls.platform_labels=1048575

(You’ll need to set net.mpls.conf.[interface-name].input=1 for any other
interfaces that you plan to receive MPLS packets on, otherwise the MPLS
route table won’t accept your routes)

(conf之后的接口名称可能会有变化,根据实际情况填写)

 

三、Install Quagga-ldp

安装quagga-ldpd,需要源码编译,因为直接的发行版本默认没有ldpd。

1.下载quagga-ldpd

1
2
git clone https://github.com/rwestphal/quagga-ldpd.git
//没有git的话先"apt install git"

2.安装必要的依赖

1
2
3
4
5
6
apt-get install autoconf
apt-get install automake
apt-get install texinfo
apt-get install libtool
apt-get install gawk
apt-get install libreadline-dev

(可以写成apt-get install autoconf automake texinfo ……)

3.Create Makefile

1
2
cd quagga-ldpd
./bootstrap.sh #autoreconf -i

4../configure

1
./configure --enable-tcp-zebra --enable-mpls --enable-ldpd --sysconfdir=/etc/quagga --localstatedir=/var/run

5.make & make install

1
2
make
make install

6.ldconfig

1
ldconfig /usr/local/lib

 

四、启动quagga-ldpd

启动quagga,需手动建pid文件。

1.user & set permission

1
2
useradd quagga
chown -R quagga.quagga /etc/quagga

2.create pid information

1
2
3
touch /var/run/zebra.pid
chmod 755 /var/run/zebra.pid
chown quagga.quagga /var/run/zebra.pid
1
2
3
touch /var/run/ospfd.pid
chmod 755 /var/run/ospfd.pid
chown quagga.quagga /var/run/ospfd.pid
1
2
3
touch /var/run/ldpd.pid
chmod 755 /var/run/ldpd.pid
chown quagga.quagga /var/run/ldpd.pid

3.create ldpd vty file

1
2
3
4
touch /var/run/ldpd.vty
chmod 755 /var/run/ldpd.vty
chown quagga.quagga /var/run/ldpd.vty
chmod 777 /var/run

4.config

1
2
cp /etc/quagga/zebra.conf.sample /etc/quagga/zebra.conf
cp /etc/quagga/ldpd.conf.sample /etc/quagga/ldpd.conf

5.Linux启用IP转发

1
sysctl net.ipv4.ip_forward net.ipv4.ip_forward=0

6.start

1
2
zebra -d -f /etc/quagga/zebra.conf
ldpd -d -f /etc/quagga/ldpd.conf

如果出现类似于zebra: error while loading shared libraries: libzebra.so.0: cannot open shared object file: No such file or directory的错误,并且在/usr/local/lib下有:

1
2
3
lrwxrwxrwx 1 root root 17 2010-06-21 01:52 libzebra.so -> libzebra.so.0.0.0
lrwxrwxrwx 1 root root 17 2010-06-21 01:52 libzebra.so.0 -> libzebra.so.0.0.0
-rwxr-xr-x 1 root root 778556 2010-06-21 01:52 libzebra.so.0.0.0

则执行:

1
2
cp libzebra.* /lib
rm libzebra.*

至此,Quagga已经正常启动。电脑已经可以作为路由器使用,但是我们还没有对它作任何设置。

 

五、进入设置

1
2
zebra -d -u root -g root
telnet localhost 2612

(初始密码为:“zebra”)

 

六、重启

重启后需要重新设置:

1
2
3
4
cd /home/patch_mpls/
dpkg -i *.deb
update-grub
reboot
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
modprobe mpls_router
modprobe mpls_gso
modprobe mpls_iptunnel
sysctl -w net.mpls.conf.ens33.input=1
sysctl -w net.mpls.conf.lo.input=1
sysctl -w net.mpls.platform_labels=1048575
touch /var/run/zebra.pid
chmod 755 /var/run/zebra.pid
chown quagga.quagga /var/run/zebra.pid
touch /var/run/ospfd.pid
chmod 755 /var/run/ospfd.pid
chown quagga.quagga /var/run/ospfd.pid
touch /var/run/ldpd.pid
chmod 755 /var/run/ldpd.pid
chown quagga.quagga /var/run/ldpd.pid
touch /var/run/ldpd.vty
chmod 755 /var/run/ldpd.vty
chown quagga.quagga /var/run/ldpd.vty
chmod 777 /var/run
cp /etc/quagga/zebra.conf.sample /etc/quagga/zebra.conf
cp /etc/quagga/ldpd.conf.sample /etc/quagga/ldpd.conf
sysctl net.ipv4.ip_forward net.ipv4.ip_forward=0
zebra -d -f /etc/quagga/zebra.conf
ldpd -d -f /etc/quagga/ldpd.conf
zebra -d -u root -g root
telnet localhost 2612
1
2
3
ip link add name lo1 type dummy
ip link set dev lo1 up
ip addr add 4.4.4.4/32 dev lo1

 

参考链接:

1.http://blog.csdn.net/SimonCZW/article/details/52538671?locationNum=13&fps=1

2.http://blog.chinaunix.net/uid-27150370-id-3826080.html