拓撲如下:
192.168.1.1/24與192.168.2.1/24同屬於vrf ***a
CEI上的主要配置如下:
interface Loopback0
ip address 192.168.1.1 255.255.255.0
interface Serial1/1
ip address 10.10.11.1 255.255.255.252
serial restart-delay 0
ip route 0.0.0.0 0.0.0.0 10.10.11.2
CE2的主要配置如下:
interface Loopback0
ip address 192.168.2.1 255.255.255.0
interface Serial1/0
ip address 10.10.22.1 255.255.255.252
serial restart-delay 0
ip route 0.0.0.0 0.0.0.0 10.10.22.2
PE1與PE2的主要配置如下:
PE1:
ip vrf ***a
rd 64512:0
route-target export 64512:0
route-target import 64512:0 // 定義***,名字爲***a 並設定其路由標識符,並指定哪些路由可以被輸入或輸出 ***a
ip cef //開啓CEF
no tag-switching ip propagate-ttl //禁止通告TTL,在***網絡中隱藏骨幹網路由
interface Loopback0
ip address 2.2.2.2 255.255.255.255 //定義環回口,用來建立BGP鄰居,以及建立LDP/TDP鄰居,作爲LDP/TDP-ID來使用
interface Serial1/0
ip vrf forwarding ***a //將指定接口綁定到***a,通過S1/0的數據將屬於***a
ip address 10.10.11.2 255.255.255.252
serial restart-delay 0
clock rate 64000
!
interface Serial1/1
ip address 200.0.12.1 255.255.255.252
mpls label protocol ldp //指定MPLS標籤交換的協議爲LDP,思科默認爲TDP
tag-switching ip //在與P路由器相連的所有接口啓用MPLS,使用MPLS ip 命令
serial restart-delay 0
clock rate 64000
router ospf 100 //啓用OSPF路由,爲BGP建立鄰居關係打好通道
router-id 2.2.2.2 //指定router-id 如不指定使用最大的環回口IP,如果環回口IP掩碼設爲24位,會導致LDP鄰居無法建立
log-adjacency-changes
network 2.2.2.2 0.0.0.0 area 0 //通告環回口
network 200.0.12.0 0.0.0.3 area 0
!
router bgp 64512 //啓用BGP
no synchronization //默認是關閉同步的
bgp router-id 2.2.2.2 //最好手工指定爲環回口的IP
bgp log-neighbor-changes
neighbor 4.4.4.4 remote-as 64512 //與PE2建立鄰居
neighbor 4.4.4.4 update-source Loopback0 //並指定更新源
no auto-summary //默認是自動彙總的,有些IOS例外,所以先要關閉同步,再關閉彙總
address-family ***v4 //定義***v4地址簇
neighbor 4.4.4.4 activate //在該簇激活鄰居
neighbor 4.4.4.4 send-community extended // 發送community 擴展,即RD
exit-address-family
!
address-family ipv4 vrf ***a //定義ipv4 vrf ***a 地址簇
redistribute connected // 將直連網段發佈到***a中
redistribute static // 將靜太路由發佈到***a中
no auto-summary // 關閉彙總
no synchronization // 關閉同步
exit-address-family
!
ip classless
ip route vrf ***a 192.168.1.0 255.255.255.0 10.10.11.1 //指定vrf ***a 路由,此路由會把重發布到BGP中,發送到PE2
PE2配置與上面一樣,只需要更換相關參數即可。
P路由器上只需要啓用OSPF即可
interface Loopback0
ip address 3.3.3.3 255.255.255.255 //如果先配置環回口後配置LDP,那麼一定要把環回口在OSPF中通告出去,不然LDP鄰居無法建立,如果反過來,即可以不用發佈,LDP/TDP會使用接口IP爲Peer IP。(這就是因爲這個原來,配置都配好了,檢查了很多東西都正常就是LDP鄰居無法建立。)
interface Serial1/0
ip address 200.0.12.2 255.255.255.252
mpls label protocol ldp
tag-switching ip
serial restart-delay 0
!
interface Serial1/1
ip address 200.0.21.2 255.255.255.252
mpls label protocol ldp
tag-switching ip
serial restart-delay 0
router ospf 100
log-adjacency-changes
network 3.3.3.3 0.0.0.0 area 0
network 200.0.12.0 0.0.0.3 area 0
network 200.0.21.0 0.0.0.3 area 0