路由拓扑
要求
一 AR1/AR2/AR3 构建MGRE环境,R1为中心站点;R1/R4为点到点GRE
二 整个私网基于RIP全网可达
三 所有PC均可访问AR5环回地址
四 AR5为ISP 只能进行IP地址配置,其余接口均为公有地址
解题思路:
首先配IP地址 然后配置MGRE 与GRE环境 ,除R5外全部使用RIP协议进行通信,因为RIP有水平分割机制,要保障网络收敛正常,所以需要在R1,R2,R3 Tunnel接口上关闭RIP的水平分割, PCpingR5环回,私网上外网 需要在路由器出口上做NAT。
使用python telnetlib库来实现自动化
import telnetlib
import time
import tqdm
TN=telnetlib.Telnet('127.0.0.1',2000)
clis=['system-view',
'interface GigabitEthernet0/0/0',
' ip address 15.1.1.1 255.255.255.0',
'nat outbound 2000',
'interface GigabitEthernet0/0/1',
' ip address 192.168.1.1 255.255.255.0',
'interface Tunnel0/0/0',
' ip address 10.0.0.1 255.255.255.0',
' undo rip split-horizon',
' tunnel-protocol gre p2mp',
' source 15.1.1.1',
' nhrp entry multicast dynamic',
' nhrp network-id 10',
'interface Tunnel0/0/1',
' ip address 100.0.0.1 255.255.255.0',
' tunnel-protocol gre',
' source 15.1.1.1',
' destination 45.1.1.1',
'rip 1',
' undo summary',
' version 2',
' network 192.168.1.0',
' network 10.0.0.0',
' network 100.0.0.0',
'ip route-static 0.0.0.0 0.0.0.0 15.1.1.2',
]
count_err = []
count_ok = []
def auto(command):
for cli in tqdm.tqdm(command):
TN.write(cli.encode('ascii')+b'\n')
if cli=='system-view':
time.sleep(1)
time.sleep(0.5)
res=TN.read_very_eager().decode('ascii')
if 'Error' in res:
count_err.append(cli)
else:
count_ok.append(cli)
print(f'一共执行了{len(clis)}条命令')
print(f'成功了{len(count_ok)}', f'分别是{count_ok}')
print(f'失败了{len(count_err)}条', f'分别是{count_err}')
TN.close()
if __name__ == '__main__':
auto(clis)
最后pc1也是成功ping通AR5环回,与其他PC