LVS-nat實驗
實驗拓撲:
環境準備:
Client配置172.22.23.10網卡,網關指向LVS
LVS配置VIP與DIP,開啓核心轉發功能
後端RS1與RS1配置對應的RIP,並將網關指向LVS
測試Client與RS一、RS2是否可以相互ping通html
LVS主機配置:
[root@centos6 ~ 18:56:44]#yum -y install ipvsadm
[root@centos6 ~ 18:58:19]#ipvsadm -A -t 172.22.23.20:80 -s rr
[root@centos6 ~ 18:58:44]#ipvsadm -a -t 172.22.23.20:80 -r 192.168.0.30:80 -m
[root@centos6 ~ 18:59:03]#ipvsadm -a -t 172.22.23.20:80 -r 192.168.0.40:80 –mvim
RS1主機配置:
[root@centos6 ~ 18:47:28]#yum -y install httpd
[root@centos6 ~ 18:51:43]#echo "RS1" > /var/www/html/index.html
[root@centos6 ~ 18:59:39]#service httpd start
RS2主機配置:
[root@centos6 ~ 18:47:28]#yum -y install httpd
[root@centos6 ~ 18:51:43]#echo "RS2" > /var/www/html/index.html
[root@centos6 ~ 18:59:39]#service httpd start
驗證成功:
後端
下面來抓包,查詢一次請求時包流動的整個過程
192.168.0.0/24網段抓包
172.22.0.0/16網段抓包
能夠查看得知,CIP請求的VIP,VIP對CIP進行迴應,整個過程就像是直接對172.22.23.20的httpd服務進行請求同樣,其實在LVS中是經過調度至後端的服務器來進行響應的,連後端服務器也感受就像是直接對CIP進行通訊同樣
centos
lvs-dr實驗
實驗拓撲:
RS1配置:
[root@centos6 ~ 21:05:20]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@centos6 ~ 21:05:47]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@centos6 ~ 21:05:48]#ifconfig lo:1 192.168.0.21 netmask 255.255.255.255 #broadcast 192.168.0.21 up服務器
RS2配置:
[root@centos6 ~ 21:05:20]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@centos6 ~ 21:05:47]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@centos6 ~ 21:05:48]#ifconfig lo:1 192.168.0.21 netmask 255.255.255.255 #broadcast 192.168.0.21 uptcp
LVS配置:
[root@centos6 ~ 21:11:20]#ifconfig lo:1 192.168.0.21 netmask 255.255.255.255 #broadcast 192.168.0.21 up
[root@centos6 ~ 21:11:25]#ipvsadm -A -t 192.168.0.21:80 -s rr
[root@centos6 ~ 21:11:51]#ipvsadm -a -t 192.168.0.21:80 -r 192.168.0.30
[root@centos6 ~ 21:12:15]#ipvsadm -a -t 192.168.0.21:80 -r 192.168.0.40ide
驗證:
下面來抓包查看報文流動的過程,黑色的表示被LVS修改目標MAC後轉發的報文
測試
Lvs-dr實驗2
實驗拓撲:
RS1配置:
[root@centos6 ~ 21:05:20]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@centos6 ~ 21:05:47]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@centos6 ~ 21:05:48]#ifconfig lo:1 192.168.0.21 netmask 255.255.255.255 #broadcast 192.168.0.21 up3d
RS2配置:
[root@centos6 ~ 21:05:20]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@centos6 ~ 21:05:47]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@centos6 ~ 21:05:48]#ifconfig lo:1 192.168.0.21 netmask 255.255.255.255 #broadcast 192.168.0.21 uphtm
LVS配置:
[root@centos6 ~ 21:11:20]#ifconfig lo:1 192.168.0.21 netmask 255.255.255.255 #broadcast 192.168.0.21 up
[root@centos6 ~ 21:11:25]#ipvsadm -A -t 192.168.0.21:80 -s rr
[root@centos6 ~ 21:11:51]#ipvsadm -a -t 192.168.0.21:80 -r 192.168.0.30
[root@centos6 ~ 21:12:15]#ipvsadm -a -t 192.168.0.21:80 -r 192.168.0.40
Router配置:配置好ip地址,開啓核心轉發
[root@centos6 ~ 22:35:43]#vim /etc/sysctl.conf
[root@centos6 ~ 22:36:08]#sysctl -p
客戶端配置:網關指向172.22.23.10
測試是否可ping通
測試請求VIP
這裏的lvs-dr模式中的LVS的網關不必定要指向路由,網關的配置就是爲了跨網段通訊,由於它不須要跨網段通訊,但不配置網關也不能夠,由於tcp的三次握手請求syn過來 lvs中,lvs雖然實際不響應tcp三次握手的請求,但若是不配置網關,它就認爲你沒法進行三次握手,因此就不能通訊了,因此能夠欺騙式的配置假網關來欺騙tcp三次握手
lvs-dr實驗VIP與DIP相同VLAN不一樣網段
實驗拓撲:
RS1配置:
[root@centos6 ~ 21:05:20]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@centos6 ~ 21:05:47]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@centos6 ~ 21:05:48]#ifconfig lo:1 172.16.0.20 netmask 255.255.255.255 #broadcast 172.16.0.20 up
[root@centos6 ~ 21:05:48]#route add -net default gw 192.168.0.10
RS2配置:
[root@centos6 ~ 21:05:20]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@centos6 ~ 21:05:47]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
[root@centos6 ~ 21:05:47]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[root@centos6 ~ 21:05:48]#ifconfig lo:1 172.16.0.20 netmask 255.255.255.255 #broadcast 172.16.0.20 up
[root@centos6 ~ 21:05:48]#route add -net default gw 192.168.0.10
lvs配置
[root@centos6 ~ 21:11:20]#ifconfig lo:1 172.16.0.20 netmask 255.255.255.255 #broadcast 172.16.0.20 up
[root@centos6 ~ 21:11:25]#ipvsadm -A -t 172.16.0.20:80 -s rr
[root@centos6 ~ 21:11:51]#ipvsadm -a -t 172.16.0.20:80 -r 192.168.0.30:80
[root@centos6 ~ 21:12:15]#ipvsadm -a -t 172.16.0.20:80 -r 192.168.0.40:80
[root@centos6 ~ 21:05:48]#route add -net default gw 192.168.0.10
路由配置:
配置好172.22.23.10地址與192.168.0.10地址,在192.168.0.10地址在再綁定一個地址172.16.0.10,用於與lvs的172.16.0.20通訊
[root@centos6 ~ 21:05:48]#ifconfig eth1:0 172.16.0.21/16 up
客戶端192.168.0.50測試: