当前位置: 首页 > article >正文

路由器与防火墙配置命令

路由器与防火墙配置命令

小明啊,你不是学计算机的嘛,叔叔家的路由器坏了,可以过来帮叔叔看看吗

命令可以用缩写,造就一堆容易造成歧义的缩写,比如addaddress的缩写,shshutdown的缩写。

默认为Cisco路由器和Cisco防火墙

视图模式介绍

普通视图 router>
特权视图 router#     #在普通模式下输入enable
全局视图 router(config)#   #在特权模式下输入config t
接口视图 router(config-if)#   #在全局模式下输入int 接口名称 例如int f0/0或int e0
路由协议视图 router(config-route)#  #在全局模式下输入router 动态路由协议名称
exit #从接口、协议、line等视图模式下退回到全局配置模式,或从全局配置模式退回到特权模式
end #回到特权模式
router#reload #重新启动路由器

1. 基本配置

router>en	 					#enable的缩写,进入特权模式
router#conf t 					#configure terminal的缩写,进入全局配置模式
router(config)# hostname xxx 	#设置设备名称
router(config)#enable password XXX  #设置进入特权模式密码(低级密码,密码可逆)
Router(config)#enable secret XXX    #设置进入特权模式密码(高级密码,密码不可逆)

router(config)#no ip domain lookup #不允许路由器缺省使用DNS解析命令
router(config)# Service password-encrypt 
	#对所有在路由器上输入的口令进行暗文加密
router(config)#security

router(config)#line vty 0 4 #进入虚拟终端线路配置模式
router(config-line)#password xxx #设置telnet的密码。没有密码远程连接不了
router(config-line)#login #开启登陆密码

router(config)#line con 0 #进入控制口的服务模式
router(config-line)#password xxx #设置console的密码
router(config-line)#login #开启密码

router#Logout  #退出当前路由器登陆模式相对与windows的注销
router#reload #重新启动路由器(热启动)冷启动就是关闭路由器再打开电源开关 

2. 接口配置与网络地址转换

NAT:network address translation,网络地址转换

PAT:port address translation,端口地址转换

router(config)#int s0 
	#进入接口配置模式。serial 0端口配置(如果是模块化的路由器前面加上槽位编号,
	#例如serial0/0 代表这个路由器的0槽位上的第一个接口)
router(config-if)#ip add 10.9.9.1 255.255.255.0   
	#这里的add是address的缩写,设置s0接口的ip地址,子网掩码
router(config-if)#nameif outside
	#设置接口命名为outside
router(config-if)# security-level 0
	#设置接口的安全级别为0
router(config-if)#enca hdlc/ppp 
	#捆绑链路协议 hdlc 或者 ppp。
	#思科缺省串口封装的链路层协议是HDLC,所以在show run中不会显示enca hdlc
	#如果要封装为别的链路层协议例如PPP/FR/X25,show run才会显示enca ppp等配置
	
firewall(config)# int e0 #进入e0接口配置
firewall(config-if)# ip add 10.9.9.1 255.255.255.0 #设置e0接口的ip,netmask
firewall(config-if)# nameif inside #接口命名为inside,表示内部网络
firewall(config-if)# end #回到特权模式
firewall# conf t #进入全局模式
firewall(config)# nat (inside) 101 10.9.9.0 255.255.255.0
	#配置inside接口的网络地址转换,指定转换范围10.9.9.0/24网段的数据包
	#穿越防火墙时将进行地址转换,NAT标识ID为101
firewall(config)# global (outside) 101 192.168.9.9-192.168.9.102 netmask 255.255.255.0
	#配置outside接口的全局地址池,转换NAT标识ID为101的所有数据包源IP地址
	#(需要与nat命令的NAT标识对应),分配出站的全局地址,范围192.168.9.9-192.168.9.102。
	#比如来自内网10.9.9.2的数据包转换成192.168.9.9作为外部地址。
firewall(config)# global (outside) 101 192.168.9.103 netmask 255.255.255.255
	#在上一条命令之后输入这一条,表示当上一条global的全局地址全部分配完毕后,才使用这条命令的全局地址池

firewall(config)# static (dmz,outside) 192.168.9.21 172.5.5.2
	#static [(internal_if_name,external_if_name)] global_ip local_ip[netmask network_mask][max_conns [em_limit]][norandomseq]
	#配置静态网络地址转换,内部网络接口名dmz,外部网络接口名outside,
	#指定dmz区域的ip地址为172.5.5.2,转换为防火墙外部区域的IP地址192.168.9.21

firewall(config)# show run nat #查看正在运行的nat
firewall(config)# no nat (inside) 101 10.9.9.0 255.255.255.0 #删除这条配置

router(config)#int loopback 
	#建立环回口(逻辑接口)模拟不同的本机网段
router(config-if)#ip add 192.168.1.1 255.255.255.255  
	#添加ip 地址和掩码给环回口
router(config-if)#no sh  		#sh是shutdown的缩写,开启接口
router(config-if)#shutdown 		#管理性的关闭接口

3. 静态路由与动态路由

(1)静态路由

firewall(config)# route outside 0 0 10.9.9.13
	#route if_name ip_address netmask gateway_ip [metric]
    #ip_address为目的ip,metric为到gateway_ip的跳数
	#配置默认路由为10.9.9.13,从防火墙outside接口出站的所有数据包,通过默认路由到达外网

router(config)#ip route 0.0.0.0 0.0.0.0 192.168.9.1
	#目的地址为0.0.0.0(任意地址),下一跳地址192.168.9.1

(2)动态路由

rip协议
router(config)#router rip 	#启动rip协议
router(config-router)#network xxx.xxx.xxx.xxx #宣告自己的网段
router(config-router)#version 2  #转换为rip 2版本
router(config-router)#no auto-summary #关闭自动汇总功能,rip V2才有作用
router(config-router)# passive-int 接口名 
	#启动本路由器的那个接口为被动接口,该接口不会发送RIP更新
router(config-router)# nei xxx.xxx.xxx.xxx 
	#neighbor的缩写,广播转单播报文,指定邻居的接收ip
igrp协议
router(config)#router igrp xxx #启动igrp协议 
router(config-router)#network xxx.xxx.xxx.xxx #宣告自己的网段
router(config-router)#variance xxx #调整倍数因子,使用不等价的负载均衡
eigrp协议
router(config)router eigrp xxx #启动协议
router(config-router)#network xxx.xxx.xxx.xxx #宣告自己的网段
router(config-router)#variance xxx #调整倍数因子,使用不等价的负载均衡
router(config-router)#no auto-summary #关闭自动汇总功能
ospf协议
router(config)router ospf xxx #启动协议启动一个OSPF协议进程
router(config-router)network xxx.xxx.xxx.xxx area xxx 
	#宣告自己的接口或网段,在ospf的区域中可以把不同接口宣告在不同区域中
router(config-router)router-id xxx.xxx.xxx.xxx #配置路由的id
router(config-router)aera xxx stub 
	#配置xxx区域为末梢区域,加入这个区域的路由器全部要配置这个条命令
router(config-router)aera xxx stub no-summary  
	#配置xxx区域为完全末梢区域,只在ABR上配置
router(config-router)aera xxx nssa 
	#配置xxx区域为非纯末梢区域(NSSA)加入这个区域的路由器全部要配置这个条命令
router(config-router)aera xxx nssa no-summary  
	#配置xxx区域为完全非纯末梢区域,只在ABR上配置,
	#并发布缺省路由信息给进入这个区域内的路由器

4. 保存配置

router#wr 
	#write的缩写,将RAM中的当前配置存储到NVRAM中,下次路由器启动就是执行保存的配置
router#Copy running-config startup-config 
	#命令与write效果一样

5. 查看命令

特权模式下:
router#show ip int br 
	#brief的缩写,查看当前的路由器的接口ip地址启用情况
router#show ip route #查看当前的路由表
router#show ? #查看show命令用法
firewall(config)#show running-config nat #查看当前的 NAT 配置
firewall(config)#show running-config global #查看global命令配置
firewall#show config #查看防火墙配置
firewall#show run interface e0 #查看e0接口的nameif,security-level,ip address

6. 访问控制列表

防火墙流量过滤只关注第一个初始化的数据包,而非响应包。防火墙接口没有绑定ACL时,出站的流量默认是放行,入站流量默认说拒绝。那么,拒绝默认可以出站的流量,放行默认不能入站的流量,就需要通过配置访问控制列表(Access Control List,ACL)实现流量过滤。

防火墙上的一个接口只能绑定一个ACL

#创建访问控制规则
pixfirewall(config)# access-list acl_id [line line-num] deny|permit protocol source_addr source_mask [operator [port]] destination_addr destination_mask operator [port]

acl_id 指定ACL名称
deny|permit 拒绝|允许通过PIX防火墙的数据包
operator 有效的操作符有lt,gt,eq,neq,range
remark 添加到ACL中的注释
text 用于remark注释的正文

show access-list		 #显示ACL
clear access-list [acl_id] #删除所有或指定条目的ACL
no access-list acl_id 	#删除指定条目的ACL

#绑定到防火墙的特定接口
pixfirewall(config)# access-group acl_id in interface interface_name
	#绑定一个ACL到一个接口

show access-group acl_id in interface interface_name	 #显示绑定在interface_name接口的ACL
clear access-group acl_id in interface interface_name #删除acl_id标识的ACL中的所有条目
no access-group acl_id in interface interface_name 	#删除绑定在接口上acl_id标识的ACL

示例:

pixfirewall(config)# access-list 101 extended permit icmp any any echo-reply
	#创建ACL,放行ping命令回显数据包,标识ID为101
pixfirewall(config)# access-list 101 permit tcp any host 192.168.9.21 eq 23
	#创建ACL,放行所有到目的主机192.168.9.21且端口号为23的TCP协议数据包,标识ID为101
pixfirewall(config)# show access-list
access-list cached ACL log flows: total 0, denied 0 (deny-flow-max 4096)
            alert-interval 300
access-list 101; 2 elements
access-list 101 line 1 extended permit icmp any any echo-reply (hitcnt=0) 0x30901cd
access-list 101 line 2 extended permit tcp any host 192.168.9.21 eq telnet (hitcnt=0) 0x17597d2

pixfirewall(config)# access-group 101 in interface outside
	#接口outside绑定标识为101的ACL
pixfirewall(config)# access-group 101 in interface dmz
	#接口dmz绑定标识为101的ACL
pixfirewall(config)# show run access-group
access-group 101 in interface outside
access-group 101 in interface dmz

http://www.kler.cn/a/587541.html

相关文章:

  • 【大模型技术】怎么用agent和prompt工程实现用户的要求?
  • Windows根据文件名批量在文件夹里查找文件并复制出来,用WPF实现的详细步骤
  • LLM - Dify(1.0.1)搭建本地私有RAG知识库完整指南
  • 【观察】拓展大模型应用交付领域“新赛道”,亚信科技为高质量发展“加速度”...
  • Flutter框架开发的安卓App的抓包以及Frida安装和hook使用教程
  • 基于yolo11+flask打造一个精美登录界面和检测系统
  • WPF Prism事件聚合器EventAggregator
  • 代码随想录二刷|图论11
  • SpringMVC (一)基础
  • 三种算法对比!改进麻雀、麻雀、粒子群算法求解微电网优化调度|Matlab
  • Flutter Dart 面向对象编程全面解析
  • matlab 八自由度汽车垂向动力学参数优化带座椅
  • 2.5 python接口编程
  • Vue3全局化配置(ConfigProvider)
  • 设计模式学习笔记——命令模式
  • 如何设计可扩展、高可靠的移动端系统架构?
  • 前置机跟服务器的关系
  • 大模型推理后JSON数据后处理
  • 【股票数据API接口24】如何获取最近10天资金流入趋势数据之Python、Java等多种主流语言实例代码演示通过股票数据接口获取数据
  • HOT100——栈篇Leetcode739. 每日温度