logical router 是JUNOS的一个特性,可以在一台设备上虚拟出多台路由器用来做实验。用VM可以使用千兆网(JUNOS识别为EM),如果安装到真机上面(QEMU) 则是百兆的接口FXP;在以后的中我以这个网上流传最多的118M的VM版JUNOS,它里面有10张千兆网卡,基本上可以做JNCIP的大部分实验 了。
如果我们手上有真机,我把三台路由器如下图所示接线,中间为一个HUB;那么就可以在接口上配置VLAN的子接口的方式来建立logical 拓扑图。在JUNOS的logical router 中正是这样,大家可以想像成真实方式如下图所示接线:
如果使用logical router 的话,我们可以做如下图所示的结构:
在JUNOS中,分配子接口的时候,叫一个UNIT,UNIT是全局唯一的。如上面按我们的使用 习惯可以这样使用。如表示r1---r2互联,可以在r1上使用unit 12 在r2上使用unit 21这样的方式来配置;
set logical-routers r1 interfaces em1 unit 12 vlan-id 12 family inet address 10.0.4.5/30
上 述命令表示在JUNOS上生成一个logical router 名为r1, 这个r1上面有一个接口em1.12(看懂了不,思科/华为是也是一样的,只不过他们没有一个叫unit的概念。如华为的vlan100的子接口是这样的 interface GigabitEthernet1/0/0.100 ,思科也是这样)封装在vlan 12,并这个接口的IP是10.0.4.5/30)
配好后,记得要在接口上启用VLAN封装。
set int em1 vlan-tag
OK,我们从最简单的入手,构建如下图:
配置如下:
root# run show configuration
## Last commit: 2009-12-07 16:39:14 UTC by root
version 8.5R1.14;
system {
root-authentication {
encrypted-password "$1$6yv5D2Es$i8tgXui7sGk82erwEFZ2Z0"; ## SECRET-DATA
}
syslog {
user * {
any emergency;
}
file messages {
any notice;
authorization info;
}
file interactive-commands {
interactive-commands any;
}
}
}
logical-routers {
r1 {
interfaces {
em1 {
unit 12 {
vlan-id 12;
family inet {
address 10.0.4.5/30;
}
}
unit 13 {
vlan-id 13;
family inet {
address 10.0.4.13/30;
}
}
}
lo0 {
unit 1 {
family inet {
address 10.0.6.1/32;
}
}
}
}
}
r2 {
interfaces {
em2 {
unit 21 {
vlan-id 12;
family inet {
address 10.0.4.6/30;
}
}
unit 23 {
vlan-id 23;
family inet {
address 10.0.4.2/30;
}
}
}
lo0 {
unit 2 {
family inet {
address 10.0.6.2/32;
}
}
}
}
}
r3 {
interfaces {
em3 {
unit 31 {
vlan-id 13;
family inet {
address 10.0.4.14/30;
}
}
unit 32 {
vlan-id 23;
family inet {
address 10.0.4.1/30;
}
}
}
lo0 {
unit 3 {
family inet {
address 10.0.6.3/32;
}
}
}
}
}
}
interfaces {
em1 {
vlan-tagging;
}
em2 {
vlan-tagging;
}
em3 {
vlan-tagging;
}
}
[edit]
root#
如何测试互通性呢?
使用:
root> ping logical-router r1 10.0.4.14
这个命令表示,源从R1出发,ping目的IP是10.0.4.14(r2)
可以发现:
root> ping logical-router r1 10.0.4.14 count 3
PING 10.0.4.14 (10.0.4.14): 56 data bytes
64 bytes from 10.0.4.14: icmp_seq=0 ttl=64 time=0.811 ms
64 bytes from 10.0.4.14: icmp_seq=1 ttl=64 time=1.045 ms
64 bytes from 10.0.4.14: icmp_seq=2 ttl=64 time=1.056 ms
--- 10.0.4.14 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 0.811/0.971/1.056/0.113 ms
root>