OVS+Docker实现TCP/IP详解中的实验环境

本文详细介绍了如何使用OVS与Docker搭建TCP/IP详解中的实验环境,包括网络配置、Docker安装、OVS桥接设置、下载镜像以及启动整个实验环境的步骤。通过此环境,读者可以进行TCP/IP协议的相关学习和实验。

ovs+docker实现TCP/IP详解中的实验环境

本文搭建了TCP/IP详解中的实验环境,以用于学习TCP/IP协议。


一.网络配置

 

  1. 为VMARE虚拟机添加NAT和Host网络,DHCP启动
  2. 修改网络配置文件 vi /etc/network/interfaces,编辑如下
    # This file describes the network interfaces available on your system
    # and how to activate them. For more information, see interfaces(5).
    
    # The loopback network interface
    auto lo
    iface lo inet loopback
    
    # The primary network interface
    auto eth0
    iface eth0 inet dhcp
    
    auto eth1
    iface eth1 inet dhcp

     

  3. 重启虚拟机,然后查看两个网卡是否正确配置,ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0c:29:b5:2a:d3  
          inet addr:192.168.112.134  Bcast:192.168.112.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feb5:2ad3/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:79 errors:0 dropped:0 overruns:0 frame:0
          TX packets:98 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:8361 (8.3 KB)  TX bytes:15990 (15.9 KB)

eth1      Link encap:Ethernet  HWaddr 00:0c:29:b5:2a:dd  
          inet addr:192.168.217.130  Bcast:192.168.217.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:feb5:2add/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:746 (746.0 B)  TX bytes:1332 (1.3 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)


          
二、安装Docker 

参见Docker安装教程,https://blog.csdn.net/walkerkalr/article/details/87002330

apt-get remove docker docker-engine docker.io
apt-get -y update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg > gpg
apt-key add gpg
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get -y update
apt-cache madison docker-ce
apt-get -y install docker-ce=18.06.0~ce~3-0~ubuntu


三、安装OVS和Bridge


参见OVS安装教程

apt-get install openvswitch-vtep openvswitch-pki openvswitch-ipsec python-openvswitch openvswitch-dbg openvswitch-common openvswitch-switch 
apt-get install bridge-utils
apt-get install arping

四、下载docker镜像

使用docker来模拟服务器,作者已经Docker镜像上传到仓库中,方便大家下载。

docker pull hub.c.163.com/liuchao110119163/ubuntu:tcpip

或者使用Dockerfile构建docker镜像

FROM hub.c.163.com/public/ubuntu:14.04
RUN apt-get -y update && apt-get install -y iproute2 iputils-arping net-tools tcpdump curl telnet iputils-tracepath traceroute
RUN mv /usr/sbin/tcpdump /usr/bin/tcpdump
ENTRYPOINT /usr/sbin/sshd -D


五、启动整个环境

启动整个环境之前需要先从github上下载启动脚本及其以来的文件。
使用setupenv.sh脚本启动整个环境,可以执行这个脚本,里面有两个参数,一个参数是 NAT 网卡的名字,一个是镜像的名称。

git clone https://github.com/popsuper1982/tcpipillustrated.git
cd tcpipillustrated
docker pull hub.c.163.com/liuchao110119163/ubuntu:tcpip
chmod +x setupenv.sh 
./setupenv.sh eth0 hub.c.163.com/liuchao110119163/ubuntu:tcpip

启动完成之后便可以通过以下命令进入docker环境,来做TCP/IP书中的相关实验

docker exec -it slip /bin/bash 

其中slip可替换为其他的主机名称。

本文参考:《趣谈网络协议》 https://time.geekbang.org/column/85

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值