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)

八、实验的体会
路由的构建,使我们了解到两台计算机之间的通信原理,本来在大二的时候没学好的网络知识,通过这次实验,我深刻的了解到构建一个网络的必备条件。刚开始时,做得还不那么的顺利,通过询问老师,同学的帮助,终于成功地完成了本次实验。加深了对网络相关概念的理解和掌握。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章