LAN 路由
一、實驗的目的
通過架設路由器可以,訪問外網;通過這個實驗可以深刻了解網絡協議以及網絡訪問的運行環境
二、假設
1. 虛擬子網
VMnet8:192.168.64.0/24
VMnet1:192.168.32.0/24
2. 虛擬機 vm1
ip: 192.168.32.3/24, 屬於子網 VMnet1。網絡連接模式爲僅主機。
三、clone 虛擬機
1. vm1 未啓動時,克隆兩虛擬機,分別命名爲 gate 和 vm2。gate 添加一以太網卡。
右擊管理,克隆,創建完整克隆
在gate設置中添加一個以太網卡;
2. 啓動 vm2,設置
ip: 192.168.64/24, 屬於子網 VMnet8。
開啓vm2。用root遠程登陸。設置vm2的網卡爲192.168.64.3,網絡連接模式爲NAT
3. 啓動 gate, 設置
eth0: 192.168.32.4/24,屬於子網 VMnet1
eth1: 192.168.64.4/24, 屬於子網 VMnet8
開啓gate。用root遠程登陸。
複製eth0,爲了得到eth1
# cd /etc/sysconfig/network-scripts
# cp ifcfg-eth0 ifcfg-eth1
修改eth1配置文件
# vi ifcfg-eth1
DEVICE = eth1
ZPADDR=192.168.64.4
NETWORK=192.168.64.4
BROADCAST=192.168.64.4
...
保存退出
重啓網絡服務
# service network restart
4. 啓動 vm1, 設置
ip: 92.168.32.3/24, 屬於子網 VMnet1。
開啓vm1。用root遠程登陸
四、啓用轉發和添加路由
1. 啓用 gate 轉發
編輯 /etc/sysctl.conf,設置net.ipv4.ip_forward = 1 打開IP轉發功能
# vi /etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
保存退出
執行: sysctl -p 使ip轉發功能隨機啓動,永久有效
# sysctl -p
2. vm1 添加路由
# route add -net 192.168.64.0/24 gw 192.168.32.4
3. vm2 添加路由
# route add -net 192.168.32.0/24 gw 192.168.64.4
五、測試
(說明:按ctrl+C停止)
1. vm1 中
# ping 192.168.64.3
[root@localhost root]# ping 192.168.64.3
PING 192.168.64.3 (192.168.64.3) 56(84) bytes of data.
64 bytes from 192.168.64.3: icmp_seq=1 ttl=63 time=3.15 ms
64 bytes from 192.168.64.3: icmp_seq=2 ttl=63 time=0.919 ms
64 bytes from 192.168.64.3: icmp_seq=3 ttl=63 time=0.570 ms
64 bytes from 192.168.64.3: icmp_seq=4 ttl=63 time=0.535 ms
--- 192.168.64.3 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3024ms
rtt min/avg/max/mdev = 0.535/1.294/3.152/1.083 ms
通了
2. vm2 中
# ping 192.168.32.3
[root@localhost root]# ping 192.168.32.3
PING 192.168.32.3 (192.168.32.3) 56(84) bytes of data.
64 bytes from 192.168.32.3: icmp_seq=1 ttl=63 time=1.62 ms
64 bytes from 192.168.32.3: icmp_seq=2 ttl=63 time=0.755 ms
--- 192.168.32.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1009ms
rtt min/avg/max/mdev = 0.755/1.191/1.628/0.437 ms
通了
六、顯示路由表
1. vm1 中
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.32.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
2. gate 中
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.64.0 * 255.255.255.0 U 0 0 0 eth1
192.168.32.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth1
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
七、畫出本實驗的拓撲圖
vm1(32.3)<---->(32.4)gate(64.4)<--->vm2(64.3)
八、實驗的體會
路由的構建,使我們瞭解到兩臺計算機之間的通信原理,本來在大二的時候沒學好的網絡知識,通過這次實驗,我深刻的瞭解到構建一個網絡的必備條件。剛開始時,做得還不那麼的順利,通過詢問老師,同學的幫助,終於成功地完成了本次實驗。加深了對網絡相關概念的理解和掌握。
通過架設路由器可以,訪問外網;通過這個實驗可以深刻了解網絡協議以及網絡訪問的運行環境
二、假設
1. 虛擬子網
VMnet8:192.168.64.0/24
VMnet1:192.168.32.0/24
2. 虛擬機 vm1
ip: 192.168.32.3/24, 屬於子網 VMnet1。網絡連接模式爲僅主機。
三、clone 虛擬機
1. vm1 未啓動時,克隆兩虛擬機,分別命名爲 gate 和 vm2。gate 添加一以太網卡。
右擊管理,克隆,創建完整克隆
在gate設置中添加一個以太網卡;
2. 啓動 vm2,設置
ip: 192.168.64/24, 屬於子網 VMnet8。
開啓vm2。用root遠程登陸。設置vm2的網卡爲192.168.64.3,網絡連接模式爲NAT
3. 啓動 gate, 設置
eth0: 192.168.32.4/24,屬於子網 VMnet1
eth1: 192.168.64.4/24, 屬於子網 VMnet8
開啓gate。用root遠程登陸。
複製eth0,爲了得到eth1
# cd /etc/sysconfig/network-scripts
# cp ifcfg-eth0 ifcfg-eth1
修改eth1配置文件
# vi ifcfg-eth1
DEVICE = eth1
ZPADDR=192.168.64.4
NETWORK=192.168.64.4
BROADCAST=192.168.64.4
...
保存退出
重啓網絡服務
# service network restart
4. 啓動 vm1, 設置
ip: 92.168.32.3/24, 屬於子網 VMnet1。
開啓vm1。用root遠程登陸
四、啓用轉發和添加路由
1. 啓用 gate 轉發
編輯 /etc/sysctl.conf,設置net.ipv4.ip_forward = 1 打開IP轉發功能
# vi /etc/sysctl.conf
# Kernel sysctl configuration file for Red Hat Linux
# For binary values, 0 is disabled, 1 is enabled. See sysctl(8) and
# sysctl.conf(5) for more details.
# Controls IP packet forwarding
net.ipv4.ip_forward = 1
# Controls source route verification
net.ipv4.conf.default.rp_filter = 1
# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0
# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1
保存退出
執行: sysctl -p 使ip轉發功能隨機啓動,永久有效
# sysctl -p
2. vm1 添加路由
# route add -net 192.168.64.0/24 gw 192.168.32.4
3. vm2 添加路由
# route add -net 192.168.32.0/24 gw 192.168.64.4
五、測試
(說明:按ctrl+C停止)
1. vm1 中
# ping 192.168.64.3
[root@localhost root]# ping 192.168.64.3
PING 192.168.64.3 (192.168.64.3) 56(84) bytes of data.
64 bytes from 192.168.64.3: icmp_seq=1 ttl=63 time=3.15 ms
64 bytes from 192.168.64.3: icmp_seq=2 ttl=63 time=0.919 ms
64 bytes from 192.168.64.3: icmp_seq=3 ttl=63 time=0.570 ms
64 bytes from 192.168.64.3: icmp_seq=4 ttl=63 time=0.535 ms
--- 192.168.64.3 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3024ms
rtt min/avg/max/mdev = 0.535/1.294/3.152/1.083 ms
通了
2. vm2 中
# ping 192.168.32.3
[root@localhost root]# ping 192.168.32.3
PING 192.168.32.3 (192.168.32.3) 56(84) bytes of data.
64 bytes from 192.168.32.3: icmp_seq=1 ttl=63 time=1.62 ms
64 bytes from 192.168.32.3: icmp_seq=2 ttl=63 time=0.755 ms
--- 192.168.32.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1009ms
rtt min/avg/max/mdev = 0.755/1.191/1.628/0.437 ms
通了
六、顯示路由表
1. vm1 中
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.32.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth0
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
2. gate 中
# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.64.0 * 255.255.255.0 U 0 0 0 eth1
192.168.32.0 * 255.255.255.0 U 0 0 0 eth0
169.254.0.0 * 255.255.0.0 U 0 0 0 eth1
127.0.0.0 * 255.0.0.0 U 0 0 0 lo
七、畫出本實驗的拓撲圖
vm1(32.3)<---->(32.4)gate(64.4)<--->vm2(64.3)
八、實驗的體會
路由的構建,使我們瞭解到兩臺計算機之間的通信原理,本來在大二的時候沒學好的網絡知識,通過這次實驗,我深刻的瞭解到構建一個網絡的必備條件。剛開始時,做得還不那麼的順利,通過詢問老師,同學的幫助,終於成功地完成了本次實驗。加深了對網絡相關概念的理解和掌握。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.