Day 7:实战与综合实验
目标:通过综合实验,将前6天学习的知识应用到实际场景中,提升实战能力。
1. 实验环境准备
- 实验工具:
- 虚拟机软件:VirtualBox、VMware 或 KVM。
- Linux发行版:Ubuntu Server、CentOS 或 Debian。
- 实验拓扑:
- 准备3台虚拟机:
- Router:作为路由器,连接两个子网。
- Client1:位于子网1(192.168.1.0/24)。
- Client2:位于子网2(192.168.2.0/24)。
- 网络拓扑:
- Client1 (192.168.1.100) <---> Router (192.168.1.1, 192.168.2.1) <---> Client2 (192.168.2.100)
2. 实验1:配置Linux路由器
目标:将一台Linux主机配置为路由器,连接两个子网。
- 配置Router:
- 启用IP转发:
echo 1 > /proc/sys/net/ipv4/ip_forward
- 配置网络接口:
- 编辑 /etc/network/interfaces 或/etc/sysconfig/network-scripts/ifcfg-eth0:
# eth0 (192.168.1.1)
auto eth0
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
# eth1 (192.168.2.1)
auto eth1
iface eth1 inet static
address 192.168.2.1
netmask 255.255.255.0
- 配置NAT(可选):
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE
- 配置Client1:
- 设置IP地址和网关:
ip addr add 192.168.1.100/24 dev eth0
ip route add default via 192.168.1.1
- 配置Client2:
- 设置IP地址和网关:
ip addr add 192.168.2.100/24 dev eth0
ip route add default via 192.168.2.1
- 测试连通性:
- 在Client1上ping Client2:
ping 192.168.2.100
3. 实验2:配置桥接网络
目标:配置桥接接口,使虚拟机可以通过桥接网络访问外部网络。
- 创建桥接接口:
- 在Host主机上创建桥接接口 br0:
ip link add name br0 type bridge
ip link set eth0 master br0
ip link set br0 up
- 配置虚拟机网络:
- 在虚拟机软件(如VirtualBox)中,将虚拟机的网络模式设置为“桥接模式”,并选择桥接接口 br0。
- 测试连通性:
- 启动虚拟机,测试是否可以访问外部网络:
ping baidu.com
4. 实验3:配置绑定接口
目标:配置绑定接口,实现链路聚合或冗余。
- 创建绑定接口:
- 在Host主机上创建绑定接口 bond0:
ip link add bond0 type bond mode=802.3ad
ip link set eth0 master bond0
ip link set eth1 master bond0
ip link set bond0 up
- 配置IP地址:
- 为绑定接口配置IP地址:
ip addr add 192.168.1.200/24 dev bond0
- 测试绑定接口:
- 使用 cat /proc/net/bonding/bond0 查看绑定接口状态。断开一个物理网卡,观察绑定接口是否自动切换到备用网卡。
5. 实验4:综合故障排查
目标:模拟网络故障,使用诊断工具排查问题。
- 模拟DNS故障:
- 修改 /etc/resolv.conf,使用错误的DNS服务器。使用 dig 和 nslookup 排查问题。
- 模拟路由故障:
- 删除默认路由: bash ip route del default使用 ip route 和 traceroute 排查问题。
- 模拟防火墙问题:
- 使用 iptables 阻止HTTP流量: bash iptables -A INPUT -p tcp --dport 80 -j DROP使用 nc 和 tcpdump 排查问题。
6. 练习任务
- 完成实验1:配置Linux路由器,确保两个子网可以互相通信。
- 完成实验2:配置桥接网络,确保虚拟机可以访问外部网络。
- 完成实验3:配置绑定接口,测试链路聚合或冗余功能。
- 完成实验4:模拟网络故障,使用工具排查问题。
7. 常见问题与排查
- 路由器配置失败:
- 检查IP转发是否启用:cat /proc/sys/net/ipv4/ip_forward。检查路由表是否正确:ip route。
- 桥接网络无法访问外部网络:
- 检查桥接接口状态:bridge link。确保物理网卡已绑定到桥接接口。
- 绑定接口无法切换:
- 检查绑定模式是否正确:cat /proc/net/bonding/bond0。确保物理网卡已正确绑定。