1、实验环境搭建
如下为实验拓扑图,该实验nginx服务走linux内核协议栈
另外一种情况是走vpp的协议栈,此时需要将nginx监听的listen函数,通过LD_PRELOAD参数替换成vpp的函数,实现nginx变成VPP的一个APP
注:
10.10.10.1和10.10.10.2 为两块不同服务器上的网卡
192.168.10.1和192.168.10.2为虚拟网卡队上的IP
eth1(10.10.10.2网卡被vpp接管)
2、策略配置
#服务器一
ifconfig eth0 10.10.10.1/24
#服务器二
##创建虚拟网卡队
ip link add name vpp1out type veth peer name vpp1host
ip link add name vpp2out type veth peer name vpp2host
##配置接口ip
ifconfig vpp1host 192.168.10.2/24
#vpp配置
create host-interface name host-vpp1out
set interface state host-vpp1out up
create host-interface name host-vpp2out
set interface state host-vpp2out up
set interface ip address eth1 10.10.10.2/24
set interface ip address host-vpp2ou 192.168.10.2/24
##设置cnat策略
set interface feature host-vpp2ou ip4-cnat-snat arc ip4-unicast
cnat translation add proto TCP vip 10.10.10.2 22432 to -> 192.168.10.2 80
3、实验结果
#在服务器一中
curl http:10.10.10.2:22432
即可实现目的ip地址net功能,访问远端服务器的nginx服务
4、cnat源码解析
在了解cnat源码前需要直到vpp的路由转发原理
未完待续。。。。。。