# Manual de Redes
## Links Úteis
[Netacad](https://www.netacad.com/)
[IP Calculator](https://wintelguy.com/subnetcalc.pl)
[Subnet Mask](https://www.aelius.com/njh/subnet_sheet.html)
[CCNA Routing and Switching - Livro Completo](http://www.modir-shabake.com/wp-content/uploads/2016/07/CCNA_Routing_and_Switching_Portable_Command_Guide_Technet24.pdf)
## Subnet Masks
| | Nº de IP | Nº de Hosts | Netmask | Wildcard |
| --- | -------- | ----------- | --------------- | ------------- |
| /30 | 4 | 2 | 255.255.255.252 | 0.0.0.3 |
| /29 | 8 | 6 | 255.255.255.248 | 0.0.0.7 |
| /28 | 16 | 14 | 255.255.255.240 | 0.0.0.15 |
| /27 | 32 | 30 | 255.255.255.224 | 0.0.0.31 |
| /26 | 64 | 62 | 255.255.255.192 | 0.0.0.63 |
| /25 | 128 | 126 | 255.255.255.128 | 0.0.0.127 |
| /24 | 256 | 254 | 255.255.255.0 | 0.0.0.255 |
| /23 | 512 | 510 | 255.255.254.0 | 0.0.1.255 |
| /22 | 1024 | 1022 | 255.255.252.0 | 0.0.3.255 |
| /21 | 2048 | 2046 | 255.255.248.0 | 0.0.7.255 |
| /20 | 4096 | 4094 | 255.255.240.0 | 0.0.15.255 |
| /19 | 8192 | 8190 | 255.255.224.0 | 0.0.31.255 |
| /18 | 16384 | 16382 | 255.255.192.0 | 0.0.63.255 |
| /17 | 32768 | 32766 | 255.255.128.0 | 0.0.127.255 |
| /16 | 65536 | 65534 | 255.255.0.0 | 0.0.255.255 |
| /15 | *** | *** | 255.254.0.0 | 0.1.255.255 |
| /14 | *** | *** | 255.252.0.0 | 0.3.255.255 |
| /13 | *** | *** | 255.248.0.0 | 0.7.255.255 |
| /12 | *** | *** | 255.240.0.0 | 0.15.255.255 |
| /11 | *** | *** | 255.224.0.0 | 0.31.255.255 |
| /10 | *** | *** | 255.192.0.0 | 0.63.255.255 |
| /9 | *** | *** | 255.128.0.0 | 0.127.255.255 |
| /8 | *** | *** | 255.0.0.0 | 0.255.255.255 |
## Housekeeping
`enable`
`configure terminal`
`hostname *nome equipamento*`
`enable secret *password para aceder ao enable*`
`line con 0`
`login local` / `login authetication *nome do grupo*`
`exit`
`line vty 0 15 / 0 4`
`pass “password”`
`login local` / `login authetication *nome do grupo*`
`exit`
`banner motd “Requires Authentication”`
`do wr`
`service password`
`user *utilizador* secret *palavra-passe*`
**Nota: Nos switches devem ainda ser desligadas as portas não utilizadas**
`en`
`conf t`
`int r fa “portas”`
`shu`
**Podem ainda ser associadas as portas ao MAC Address do dispositivo a elas ligado**
`en`
`conf t`
`int “port”`
`sw port-security mac-address sticky - Ports should add the learned MAC addresses to the running configuration.`
`sw port-security maximum 1 - Configure the ports to accept a maximum of x MAC addresses.`
`sw port-security violation restrict - If a violation occurs, configure the port to drop frames from the unauthorized MAC address, log it, and send an alert.`
`interface f0/1`
`switchport port-security mac-address 00D0.D3DC.2825`
`switchport port-security aging time 10 - MAC addresses should be present in the MAC address table for a maximum of 10 minutes before they are removed.`
## Protocolos de Routing
**Nota: Para ativar routing num Switch Layer 3 têm de ser realizados os comandos em infra:**
`en`
`conf t`
`ip routing (transformar switch em router para permitir comandos de router)`
`int "porta"`
`no switch (para mudar uma porta de switch para uma porta terminal)`
### RIPv2
`conf t`
`router rip`
`version 2`
`no auto-summary`
`network "Ip de rede" "subnet"`
Outros comandos:
`timers basic 5 5 5 5 5` (define intervalos de tempo entre atualizações etc)
`distance`
`passive-interface` (interfaces para não direcionar tráfico)
**Nota: Associamos ao protocolo apenas as redes que o router conhece**
----------------------------
### EIGRP
`conf t`
`router eigrp nº`
`no auto summary`
`network "Ip de rede" "Wildcard"`
`do wr`
**Exemplo:**
`network 172.16.1.0 0.0.0.255`
**Nota: Associamos ao protocolo apenas as redes que o router conhece**
----------------------------
### OSPF

**No router 1**
`router ospf 1`
`network 10.0.1.0 0.0.0.255 area 0`
`network 172.16.0.0 0.0.255.255 area 0`
**No router 2**
`router ospf 1`
`network 172.16.0.0 0.0.255.255 area 0`
`network 192.168.0.0 0.0.0.255 area 1`
**No router 3**
`router ospf 1`
`network 192.168.0.0 0.0.0.255 area 1`
`network 90.10.0.0 0.0.0.255 area 1`
---
**Start the OSPF routing process on all three routers. Use process ID 10.**
**Open configuration window**
Router(config)# router ospf "process-id"
**Use the router-id command to set the OSPF IDs of the three routers as follows**
* R1: 1.1.1.1
* R2: 2.2.2.2
* R3: 3.3.3.3
**Use the following command:**
Router(config-router)# router-id rid
---
**Configure each interface using the command syntax shown below:**
Router(config-if)# ip ospf process-id area area-id
----------------------------
Configure R2 with a directly attached default route to the Internet.
R2(config)# ip route 0.0.0.0 0.0.0.0 Serial0/1/0
Propagate the route in OSPF.
Configure OSPF to propagate the default route in OSPF routing updates.
R2(config)# router ospf 1
R2(config-router)# default-information originate
---
### Redistribute
Para efetuar a redistribuição de protocolos é necessário anunciar as redes correspondentes a cada protocolo, e efetuar os seguintes comandos de redistribute
**Redistribute RIP - EIGRP**

**Redistribute EIGRP - OSPF**

**Redistribute EIGRP - Static**
```
Router(config)#router eigrp 10
Router(config-router)#redistribute static
```
**NOTA:Caso a redistribuição não funcione, confirmar no auto-summary
### Rota estática
`ip route *ip da rede de destino* *subnet mask* *IP ou interface de saída do router*`
**Nota: Para fins de teste podemos utilizar o comando `ip route 0.0.0.0 0.0.0.0 0.0.0.0` que redireciona TODAS as redes conhecidas ao router**
## Access-List Standard Vs Extended
| Standard ACL | Extended ACL |
| --- | -------- |
| Por norma utilizado pra bloquear um host, uma rede em especifico | Por norma utilizado para bloquear um serviço em especifico |
| ACL RANGE 1-99 | ACL RANGE 100-199 |
| A ACL Standard bloqueia todos os serviços| A ACL Extended bloqueia serviços em especifico |
| A ACL Standard bloqueia a Destination | A ACL Extended bloqueia a source |
### Access-List Standard
`conf t`
`access list nº (1-99) permit "A.B.C.D" ` - De modo a permitir uma rede em especifico
`access list nº (1-99) permit "any" ` - De modo a permitir todas as redes
`access list nº (1-99) permit "Host" ` - De modo a permitir um IP em especifico
`access list nº (1-99) deny "A.B.C.D" ` - De modo a proibir uma rede em especifico
`access list nº (1-99) deny "any" ` - De modo a proibir todas as redes
`access list nº (1-99) deny "Host" ` - De modo a proibir um IP em especifico
**Caso queiramos bloquear o acesso a uma host em especifico e permitir todas as outras rede**
`conf t`
`access list nº (1-99) deny Host "IP especifico"`
`access list nº (1-99) permit any`
`int "interface aplicar a ACL"`
`IP access-group nº in`
**Caso queiramos permitir o acesso a uma host em especifico e proibir todas as outras rede**
`conf t`
`access list nº (1-99) permit Host "IP especifico"`
`access list nº (1-99) deny any`
`int "interface aplicar a ACL"`
`IP access-group nº in`
### dar nome a access list
ip access-list standard BRANCH-OFFICE-POLICY
### adicionar comentarios na access list
access-list 1 remark Allow R1 LANs Access
-----------------------------------------
### Access-List Extended
`conf t`
`access list nº (100-199) permit "tcp" "A.B.C.D" eq 22(porta do protocolo) "Host" "IP do dispositivo que aloja o serviço"` - De modo a permitir uma rede em especifico para os serviços que utilizam o protocolo TCP
`access list nº (100-199) permit "tcp" "any" eq 22(porta do protocolo) "Host" "IP do dispositivo que aloja o serviço"` - De modo a permitir todas as redes para os serviços que utilizam o protocolo TCP
`access list nº (100-199) permit "tcp" "Host" "Ip source" eq 22(porta do protocolo) "Host" "IP do dispositivo que aloja o serviço"` - De modo a permitir um IP em especifico para os serviços que utilizam o protocolo TCP
## SSH

`hostname (nome)`
`ip domain-name (exemplo.local)`
`**crypto key generate rsa**`
**The name for the keys will be: R1.exemplo.local**
**Choose the size of the key modulus in the range of 360 to 4096 for your**
**General Purpose Keys. Choosing a key modulus greater than 512 may take**
**a few minutes.**
**How many bits in the modulus [512]:** `2048`
**% Generating 2048 bit RSA keys, keys will be non-exportable...**
**[OK] (elapsed time was 3 seconds)**
`ip ssh version 2`
`line vty 0 4`
`transport input ssh`
`login local`
`username (nome) password (palavra passe)`
**NOTA: No caso dos switches, é necessário acrescentar o comando ip default-gateway aos mesmos**
**Para entrar pelo o ssh**
`ssh -l (user) (ip da porta do equipamento que se quer entrar)`
## **Túnel**
`en`
`conf t`
`int tunnel "nº"`
`ip add "ip do túnel" "subnet (normalmente /30)"`
`tunnel destination "ip de destino (PORTA FÍSICA)"`
`tunnel source "porta de origem"`
`tunnel mode gre ip `
`ip route "ip da rede" "subnet" "ip do tunnel de chegada"`
**Nota: No Router da extremidade oposta tem de ser criada uma interface túnel de forma semelhante**
## **DHCP**
`en`
`conf t`
`ip dhcp excluded-address *1º IP a ser exluido* *Último IP a ser excluído*`
`ip dhcp pool *nome da pool*`
`network *ip da rede* *subnet mask*`
`default-router *default-gateway a atribuir aos clientes*`
`dns-server *ip do servidor DNS*`
`interface g0/0/1`
`ip address dhcp - Configure an interface as a DHCP client.`
#### ip dhcp snopping :
`ip dhcp snooping - Activate DHCP snooping globally.`
`ip dhcp snooping vlan 10,999 - Activate DHCP snooping for the two VLANs that you configured.`
`interface range f0/1-5, g0/1`
`ip dhcp snooping limit rate 5 -Configure the ports to limit the rate to 5 DHCP packets per second.`
`exit`
`interface g0/1`
`ip dhcp snooping trust - Configure the port that links to the router as trusted.`
`exit`
## **NTP**
Quando feito no servidor, basta definir nos dispositivos de rede (Router ou Switch) o IP do servidor NTP, através do seguinte comando:
`ntp server *IP servidor NTP*`
`ntp authenticate`
`ntp authentication-key nº md5 "Password"`
`ntp update-calendar`
Para testar:
`show ntp status`
## **RSYSLOG**
Após configuração do serviço no servidor, é necessário efetuar os seguintes comandos nos routers/switches dos quais pretendemos receber logs:
`logging "ip do servidor"`
`logging trap debugging`
## **Radius/AAA**
Após criação e configuração do serviço RADIUS/AAA no servidor, é necessário aplicar as seguintes configurações nos dispositivos:
`aaa new-model`
`aaa authentication login default local none`
`aaa authentication login *nome* group radius`
`radius-server host *ip do servidor* auth-port 1645 key *secret do AAA*`
`line con 0`
`login authentication *nome* `
`tacacs-server host "ip"`
`tacacs-server key tacacspa55 `
`aaa new-model`
`aaa authentication login default group *nomedoserver* local`
`line console 0`
`login authentication default`
`aaa authentication login TELNET-LOGIN local`
## **NAT**
`int "porta de dentro"`
`ip nat inside`
`int "porta de fora" `
`ip nat outside`
`access-list "100" permit ip "ip de dentro" "wildcard" any`
` ip nat inside source list "acl criada anteriomente" interface "porta de fora" overload `
---
**Refer to the Topology. Create a static NAT translation to map the Server1 inside address to its outside address.**
R1(config)# ip nat inside source static 172.16.16.1 64.100.50.1
**Configure the G0/0 interface as an inside interface.**
R1(config)# interface g0/0
R1(config-if)# ip nat inside
b.Configure the s0/0/0 public interface as an outside interface.
---
show running-config
show ip nat translations
show ip nat statistics
----
## nat dynamic
**access list**
access-list 1 permit 172.16.0.0 0.0.255.255
**nat pool**
ip nat pool R2pool 209.165.200.229 209.165.200.230 netmask 255.255.255.252
**associar a access-lists ao nat**
ip nat inside source list 1 pool R2pool
**Portas**
R2(config)#int s0/0/0
R2(config-if)#ip nat out
R2(config-if)#ip nat outside
R2(config-if)#exit
R2(config)#int s0/0/1
R2(config-if)#ip nat inside
---
## Configure Dynamic NAT with Overload
**Access-list**
access-list 1 permit 172.16.0.0 0.0.255.255
**nat pool**
ip nat pool ANY_POOL_NAME 209.165.200.233 209.165.200.234 netmask 255.255.255.252
**Associate ACL 1 with the NAT pool and allow addresses to be reused.**
ip nat inside source list 1 pool ANY_POOL_NAME overload
**Portas**
R1(config)#int s0/1/0
R1(config-if)#ip nat outside
R1(config-if)#int g0/0/0
R1(config-if)#ip nat inside
R1(config-if)#int g0/0/1
R1(config-if)#ip nat inside
## PAT
**Access-list**
access-list 2 permit 172.17.0.0 0.0.255.255
**Associate ACL 2 with the NAT pool and allow addresses to be reused.**
ip nat inside source list 2 interface s0/1/1 overload
**Portas**
R2(config)#int s0/1/1
R2(config-if)#ip nat outside
R2(config-if)#int g0/0/0
R2(config-if)#ip nat inside
R2(config-if)#int gig0/0/1
R2(config-if)#ip nat inside
## **IPV6**
**Router**
`ipv6 unicast-routing` (De forma a que o Router receba IPv6 Packets)
`ipv6 address - 2001:db8:1:1::1/64`
`ipv6 address fe80::1 link-local` (Default Gateway)
## **IP ROUTE IPV6**
`ipv6 route "rede que se quer conhecer" "ip da porta que nos fornece essa rede"`
## Spanning tree
`show spanning-tree vlan "x"`
`spanning-tree mode pvst` - para vlan
`spanning-tree portfast bpduguard` - para todas as portas
`spanning-tree portfast default` - para todas as portas em acess
`show interfaces trunk`
`interface range f0/21 - 22`
`shutdown`
`channel-group 1 mode desirable`
`no shutdown`
`interface port-channel 1`
`switchport mode trunk`
`show etherchannel summary`
`interface range g0/1 - 2`
`shutdown`
`channel-group 2 mode active/passive`
`no shutdown`
`interface port-channel 2`
`switchport mode trunk`
`show spanning-tree active`
`spanning-tree vlan 1 root primary`
## HSRP
`int gig0/1`
`standby version 2`
`standby 1 ip 192.168.1.254 ` - ip da default gateway virtual
`standby 1 priority 150`
`standby 1 preempt`
`do show standby`
## ARP
`ip arp inspection vlan 10,999`
`interface g0/1`
`ip arp inspection trust`
`exit`
## SNMP



## As ultimas POR ORGANIZAR
`access-list 110 deny icmp any 172.16.2.16 0.0.0.7 echo`
`access-list 110 deny icmp any 172.16.2.0 0.0.0.15 echo`
`access-list 110 permit ip any any`
`switchport port-security`
`switchport port-security mac-address sticky `
` switchport port-security violation restrict`
## CDP
cdp run
interface s0/0/1
no cdp enable
exit
show cdp neighbors
show cdp neighbors detail
## LLDP
lldp run
int g0/0
no lldp transmit
exit
## VTP
vtp domain "Domain-name"
vtp mode server/client/transparent
cliente = vtp mode client
vtp password "cisco" --optional
---
lldp run
interface g0/0
no lldp transmit
no lldp receive
exit