# 區域網路
# 基本設定
**設定遠端登入的密碼**
> line vty 0 4,該命令是允**許使用者遠端登陸**,即不用使用者插Console線纜,只要裝置連線網路,配置了介面IP地址即可遠端使用Telnet、或者ssh的方式登陸到裝置上,,CISCO裝置一般支援16個並行的遠端虛擬終端,按照編號就是:0 - 15., Line vty 0 4 就是指同時允許5個虛擬終端登陸進行配置,需注意這裡配置完成後一定要注意**配置enable的密碼,要不Telnet是上不去的**。
設定使能加密密碼:
```
Router(config)#enable secret csico
```
設定控制檯密碼:
```
Router(config)#line console 0
Router(config-line)#password csico
Router(config-line)#login
Router(config-line)#exit
```
設定遠端登陸密碼:
```
Router(config)#line vty 0 4
Router(config-line)#password csico
Router(config-line)#login
Router(config-line)#exit
```
**==改良版==**
1.有加密username、password
2.之前沒有加密 可被wireshark追蹤
3.**```ip domain-name example.com```** ==限制在此網域才可登入==

## IPV4 vs IPv6
網路通訊協定(Internet Protocol,IP)
> 是用於網路交換封包的一種協定,它定義了定址方式及資料的封裝結構。而IP位址則是在網路上**替主機定義位址**,簡單來說它類似於公司地址,能夠明確標示出公司所在位址。
**兩者為不同的協定、不能互通**
| | IPv4 | IPv6 |
| -------- | ---------------------- | --------------------------------------- |
| 位址數量 | 2^32個 | 2^128個 |
| 表示方法 | 4組數字、0~255的10進位 | 8組數字、每組為4個字元的16進位 |
| 舉例來說 | 120.165.70.66 | 1079:0BD3:6ED4:1D71:414B:2E2A:7144:72BE |
| 特別之處 | | Unicast對應單點傳送、Multicast則取代廣播 |
### 使用IPv6
>
一樣進入端口、設定位址
ipv6 address 2001:db8:feed:224::2/64
ipv6 enable
**Router設定:**
```
Router>en
Router#config t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host R2
R2(config)#enable secret cisco
R2(config)#line con 0
R2(config-line)#password cisco
R2(config-line)#login
R2(config-line)#line vty 0 4
R2(config-line)#password cisco
R2(config-line)#login
R2(config-line)#exit
R2(config)#ipv6 unicast-routing
R2(config)#int g0/1
R2(config-if)#ip address 209.165.200.226 255.255.255.0
R2(config-if)#ipv6 address 2001:db8:feed:224::2/64
R2(config-if)#ipv6 enable
R2(config-if)#no shut
R2(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to up
R2(config-if)#ipv6 unicast-routing
R2(config)#int g0/0
R2(config-if)#ip address 10.1.1.1 255.255.255.0
R2(config-if)#ipv6 address 2001:db8:cafe:1::1/64
R2(config-if)#ipv6 enable
R2(config-if)#no shut
R2(config-if)#
%LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to up
R2(config-if)#int g0/0
R2(config-if)#ipv6 rip process1 enable
R2(config-if)#int g0/1
R2(config-if)#ipv6 rip process1 enable
R2(config-if)#router rip
R2(config-router)#version 2
R2(config-router)#network 10.1.1.0
R2(config-router)#network 209.165.200.224
R2(config-router)#
```
# DNS-server
**1. WWW server** *最簡單*
只要設定DNS位址

**2. Email server**
加上Domain name //每個使用者都要按set!!!
加上每個使用者的名稱、密碼

## **甚麼是Domain name??**
> 在網路上辨別一台電腦的方式是利用 IP,但是一組 IP 數字很不容易記,且沒有什麼聯想的意義,因此,我們會為網路上的伺服器取一個有意義又容易記的名字,這個名字我們就叫它「Domain Name」。但由於在 Internet 上真實在辨識機器的還是 IP,所以當使用者輸入Domain Name後,瀏覽器必須要先去一台有 Domain Name 和 IP 對應資料的主機去查詢這台電腦的 IP,而這台被查詣的主機,我們稱它為 Domain Name Server,簡稱 DNS,例如:當你輸入 www.twnic.com.tw時,瀏覽器會將www.twnic.com.tw這個名字傳送到離他最近的 DNS Server 去做辨識,如果詢找到,則會傳回這台主機的 IP,進而跟它索取資料,但如果沒查到,就會發生類似 DNS NOT FOUND的情形,所以一旦DNS Server 當機,就像是路標完全被毀壞,沒有人知道該把資料送到那裡。DNS是網域名稱服務的(Domain Name Service)縮寫。DNS 的主要目地是在解決機器的網域名稱 (Domain name) 與 IP address 的對應問題。
**3. DNS server**
把另外兩台server的名稱與ip位址加進去

把每台電腦、伺服器加上DNS

---
## 加上串列線
紅色時鐘

路由器選1941,加上HWIC-2T>>>才有Se0/0/0、Se0/0/1的孔

#### 進入線的那端後記得開啟串列線的設定
>int se0/0/0
ip address xxx.xxx.xxx...
**clock rate 64000**
no shut
---
## PC端如何寄信
1. Email

2. 使用者、收信/出信端、剛剛在Email server端上的帳號密碼

3. save>compose 打另一個人的mail位址>send

4. 另一端一樣設定使用者帳號>>接信:receive

5. 開啟www server端的網址


---
# VLSM分割設定
頭:網域名稱
尾:廣播位址
---
題目:

**200.200.學號.0/24**
綠色A區:需要100個+頭尾>>>256/2=128
藍色B區:需要20個+頭尾>>>128/2=64/2=32
SERVER端:需要4個+頭尾>>>32/2=16/2=8
R1-R2兩個+頭尾>>>8/2=4
R2-R3兩個+頭尾>>>8/2=4
R3-R1兩個+頭尾>>>8/2=4


| 區域 | 網域名稱 | IP可用範圍 | 遮罩 | Default Gate Way | prefix length |
| ------ | -------- | -------- | --- | --- | --- |
| A | 200.200.41.0 |.1~.126 |255.255.255.128| .1 | /25 |
| B |200.200.41.128 |.129~.158 |255.255.255.224| .129| /27|
| SERVER(C)|200.200.41.160 |.161~.166|255.255.255.248 | .161 | /29 |
| R1-R2 |200.200.41.168 |.169、.170 |255.255.255.252 | | /30 |
| R2-R3 |200.200.41.172| .173、.174|255.255.255.252 | | /30 |
| R3-R1 |200.200.41.176 |.177、.178 |255.255.255.252| | /30 |
## 子網路遮罩對照表

# 設定Security
1. Authentication
2. authorization
3. and accounting
可以採取幾個步驟來幫助確保密碼**在 Cisco 路由器和交換機上保密**,包括:
**service password-encryption** 對所有明文密碼進行加密。
**security passwords min-length** 設置可接受的最小密碼長度。
**login block-for # attempts # within #** 阻止暴力密碼猜測攻擊。
**exec-timeout** 在指定時間後禁用非活動特權 EXEC 模式訪問。

**設定Cisco 設備以支持 SSH:**
配置唯一的設備主機名。 設備必須具有默認主機名以外的唯一主機名。
配置IP域名。 使用全局配置模式命令 ip-domain name 配置網絡的 IP 域名。
生成密鑰以加密 SSH 流量。 SSH 加密源和目標之間的流量。 但是,為此,必須使用全局配置命令 crypto key generate rsa general-keys modulus bits 生成唯一的身份驗證密鑰。 模數位決定密鑰的大小,可以配置為 360 位到 2048 位。 位值越大,密鑰越安全。 但是,更大的位值也需要更長的時間來加密和解密信息。 推薦的最小模數長度為 1024 位。
驗證或創建本地數據庫條目。 使用 username 全局配置命令創建本地數據庫用戶名條目。
針對本地數據庫進行身份驗證。 使用登錄本地線路配置命令根據本地數據庫驗證 vty 線路。
啟用 vty 入站 SSH 會話。 默認情況下,vty 線路上不允許輸入會話。 您可以使用傳輸輸入 [ssh | 指定多個輸入協議,包括 Telnet 和 SSH telnet] 命令。

**Router:**
```
User Access Verification
Password:
R2>en
Password:
R2#config t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#service password-encryption
R2(config)#security password min-length 8
R2(config)#login block-for 120 attempt 3 within 60
R2(config)#line vty 0 4
R2(config-line)#password ciscocisco
R2(config-line)#exec-timeout 5 30
R2(config-line)#transport input ssh
R2(config-line)#end
R2#
%SYS-5-CONFIG_I: Configured from console by console
R2#show running-config | section line vty
line vty 0 4
exec-timeout 5 30
password 7 0822455D0A16061E010803
login
transport input ssh
R2#config t
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#ip domain-name www.mcu.edu.tw
R2(config)#crypto key generate rsa general-keys modulus 1024
The name for the keys will be: R2.www.mcu.edu.tw
% The key modulus size is 1024 bits
% Generating 1024 bit RSA keys, keys will be non-exportable...[OK]
*Mar 1 0:58:18.367: %SSH-5-ENABLED: SSH 1.99 has been enabled
R2(config)#username R2 secret ciscocisco
R2(config)#line vty 0 4
R2(config-line)#login local
R2(config-line)#transport input ssh
R2(config-line)#exit
R2(config)#
%LINK-3-UPDOWN: Interface Serial0/0/0, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0/0, changed state to down
R2 con0 is now available
Press RETURN to get started.
%LINK-5-CHANGED: Interface Serial0/0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0/0, changed state to up
User Access Verification
Password:
R2>enable
Password:
Password:
R2#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
R2(config)#interface GigabitEthernet0/0
R2(config-if)#
R2(config-if)#exit
R2(config)#interface GigabitEthernet0/1
R2(config-if)#
R2(config-if)#exit
R2(config)#interface Serial0/0/0
R2(config-if)#
R2 con0 is now available
```
## **PC遠端登入Router:**
### **ssh -l username ip**

**[SSH 的基本運作原理](https://ithelp.ithome.com.tw/articles/10277498)**