例一:用物理接口建立BGP邻居关系
R4和R2建EBGP邻居关系:
R4:
router bgp 4
bgp router-id 4.4.4.4
neighbor 24.1.1.2 remote-as 123 //指定EBGP邻居
R2:
router bgp 123
bgp router-id 2.2.2.2
neighbor 24.1.1.4 remote-as 4 //指定EBGP邻居
R2和R3建立IBGP邻居关系:(需要先在AS123内部运行IGP)
R2:
router bgp 123
neighbor 13.1.1.3 remote-as 123
neighbor 13.1.1.3 next-hop-self //IBGP中,边界路由器需要对邻居打上这一命令
R3:
router bgp 123
neighbor 12.1.1.2 remote-as 123
neighbor 12.1.1.2 next-hop-self
例二:用环回接口建立BGP邻居关系:
R4和R2建EBGP邻居关系:
R4:
ip route 2.2.2.0 255.255.255.0 24.1.1.2 //先确保有去邻居的路由
router bgp 4
bgp router-id 4.4.4.4
neighbor 2.2.2.2 remote-as 123 //指定EBGP邻居
neighbor 2.2.2.2 update-source lo0 //指定自已的更新源
neighbor 2.2.2.2 ebgp-multihop 2 //设置EBGP的多跳,修改EBGP中的TTL可达,默认255
R2:
ip route 4.4.4.0 255.255.255.0 24.1.1.4 //先确保有去邻居的路由
router bgp 123
bgp router-id 2.2.2.2
neighbor 4.4.4.4 remote-as 4 //指定EBGP邻居
neighbor 4.4.4.4 update-source lo0 //指定自已的更新源
neighbor 4.4.4.4 ebgp-multihop 2 //设置EBGP的多跳,修改EBGP中的TTL可达,默认255
或者使用nei 2.2.2.2 disable-connected-check //关闭直连检测
To disable connection verification to establish an eBGP peering session with a single-hop peer that uses a loopback interface, use the neighbor disable-connected-check command in address family or router configuration mode. To enable connection verification for eBGP peering sessions, use the no form of this command.
neighbor {ip-address | peer-group-name} disable-connected-check
no neighbor {ip-address | peer-group-name} disable-connected-check
ip-address |
IP address of a neighbor. |
peer-group-name |
Name of a BGP peer group. |
A BGP routing process will verify the connection of single-hop eBGP peering session (TTL=254) to determine if the eBGP peer is directly connected to the same network segment by default. If the peer is not directly connected to same network segment, connection verification will prevent the peering session from being established.
R2和R3建立IBGP邻居关系:(需要先在AS123内部运行IGP)
R2:
router bgp 123
neighbor 3.3.3.3 remote-as 123
neighbor 3.3.3.3 update-source lo0
neighbor 3.3.3.3 next-hop-self
R3:
router bgp 123
neighbor 2.2.2.2 remote-as 123
neighbor 2.2.2.2 update-source lo0
neighbor 2.2.2.2 next-hop-self
其它命令:
·宣告路由进BGP,注意BGP的network能够通告路由表中的所有非BGP路由量。
router bgp 123
network 172.16.1.0 mask 255.255.255.0 //宣告网络时要说明掩码
·下面这条命令修改对所有邻居的keepalive-interval和hold-time
router bgp 123
timers bgp keepalive-interval hold-time
·下面这条命令修改对特定邻居的keepalive-interval和hold-time。
router bgp 123
neighbor 1.1.1.1 times keepalive-interval hold-time
·各类显示命令:
show ip bgp summary //摘要的邻居邻居信息
show ip bgp 2.2.2.0/24 //显示明细路由的详细信息
show tcp brief //可以看到是谁发起的TCP链接
show ip bgp neighbors //详细的邻居信息
show ip bgp rib-failure //可以看到提示有更高AD的路由
show ip bgp neighbors 2.2.2.2 advertised-routes //看向这个邻居发了哪些路由信息
show ip bgp neighbors 3.3.3.3 received-routes //看这个邻居给我发了哪些路由信息,必须在本路由器上用下面这条命令开启后才能用
R2(config-router)#neighbor 3.3.3.3 soft-reconfiguration inbound //开启查看接收到的路由信息的功能
debgu ip routing //查看路由表调试信息
debug ip bgp updata //查看BGP更新信息
------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
<关于更新源>Update-Source
路由器用来和邻居建立邻居关系的地址,我们称之为更新源地址。
注意:在BGP建邻居过程中,neighbor命令所指定的邻居的IP地址,也必须是邻居用来和本路由器建立TCP连接的地址。如果不匹配,两端建立不起邻居关系。
"show ip bgp summary中的Neighbor" / "show ip bgp中的Next Hop "
都是指Update-Source。
可以在路由器上用以下命令指定使用哪个接口来和邻居建立联系,这个接口就是自已的更新源:
router bgp 123
neighbor 3.3.3.3 update-source loopback 0
<Peer-Group>对等体组,类似于建立一个批处理文件
BGP中,建立邻居关系的时候,有可能要对邻居指上多条命令,peer-group可以将多条命令组合在一起,用来在建邻居关系的时候一次性调用。减少了配置量。
BGP为每个邻居都占用一部分Buffer,使用Peer-Group可以使多个邻居共用同一部分Buffer。减少资源占用。
而且针对比较多的邻居关系,可以减少配置量。
router bgp 123
neighbor WOLF peer-group //定义一个peer-group组
neighbor WOLF remote-as 64513 //向组中加入命令
neighbor WOLF update-source loopback 0 //向组中加入命令
neighbor 2.2.2.2 peer-group WOLF //在邻居上调用