Linux »ò Windows ÉÏʵÏֶ˿ÚÓ³Éä
ͨ³£Ð§ÀÍÆ÷»áÓÐÐí¶à¿éÍø¿¨£¬Òò´ËÒ²¿ÉÄÜ»áÅþÁ¬µ½²î±ðµÄÍøÂ磬ÔÚ¸ôÀëµÄÍøÂçÖУ¬Ä³Ð©Ð§ÀÍ¿ÉÄÜ»áÐèÒª¾ÙÐÐͨѶ£¬´ËʱЧÀÍÆ÷¾ÓÉÉèÖþͿÉÒԼ縺ÆðÁËת·¢Êý¾Ý°üµÄ¹¦Ð§¡£
Ò»¡¢Windows ÏÂʵÏֶ˿ÚÓ³Éä
1. ÅÌÎʶ˿ÚÓ³ÉäÇéÐÎ
netsh interface portproxy show v4tov4
µÇ¼ºó¸´ÖÆ
2. ÅÌÎÊijһ¸ö IP µÄËùÓж˿ÚÓ³ÉäÇéÐÎ
netsh interface portproxy show v4tov4 | find "[IP]"Àý£ºnetsh interface portproxy show v4tov4 | find "192.168.1.1"
µÇ¼ºó¸´ÖÆ
3. ÔöÌíÒ»¸ö¶Ë¿ÚÓ³Éä
netsh interface portproxy add v4tov4 listenaddress=[ÍâÍøIP] listenport=[ÍâÍø¶Ë¿Ú] connectaddress=[ÄÚÍøIP] connectport=[ÄÚÍø¶Ë¿Ú]Àý£ºnetsh interface portproxy add v4tov4 listenaddress=2.2.2.2 listenport=8080 connectaddress=192.168.1.50 connectport=80
µÇ¼ºó¸´ÖÆ
4. ɾ³ýÒ»¸ö¶Ë¿ÚÓ³Éä
netsh interface portproxy delete v4tov4 listenaddress=[ÍâÍøIP] listenport=[ÍâÍø¶Ë¿Ú]Àý£ºnetsh interface portproxy delete v4tov4 listenaddress=2.2.2.2 listenport=8080
µÇ¼ºó¸´ÖÆ
¶þ¡¢Linux ϶˿ÚÓ³Éä
1. ÔÊÐíÊý¾Ý°üת·¢
echo 1 >/proc/sys/net/ipv4/ip_forwardiptables -t nat -A POSTROUTING -j MASQUERADEiptables -A FORWARD -i [ÄÚÍøÍø¿¨Ãû³Æ] -j ACCEPTiptables -t nat -A POSTROUTING -s [ÄÚÍøÍø¶Î] -o [ÍâÍøÍø¿¨Ãû³Æ] -j MASQUERADEÀý£ºecho 1 >/proc/sys/net/ipv4/ip_forwardiptables -t nat -A POSTROUTING -j MASQUERADEiptables -A FORWARD -i ens33 -j ACCEPTiptables -t nat -A POSTROUTING -s 192.168.50.0/24 -o ens37 -j MASQUERADE
µÇ¼ºó¸´ÖÆ
2. ÉèÖö˿ÚÓ³Éä
iptables -t nat -A PREROUTING -p tcp -m tcp --dport [ÍâÍø¶Ë¿Ú] -j DNAT --to-destination [ÄÚÍøµØµã]:[ÄÚÍø¶Ë¿Ú]Àý£ºiptables -t nat -A PREROUTING -p tcp -m tcp --dport 6080 -j DNAT --to-destination 10.0.0.100:6090
µÇ¼ºó¸´ÖÆ
ʵÑ飺½«°²ÅÅÔÚÄÚÍøµÄЧÀÍÓ³Éäµ½ÍâÍø
ʵÑéÇéÐÎ
VMWare Workstation Pro
5 ̨×îС»¯×°ÖÃµÄ centos 7 ÐéÄâ»ú
ʵÑéÍØÆË
ÄÚÍøºÍÍâÍøÊÇÏà¶ÔServer4À´ËµµÄ¡£
Server1ºÍServer2ΪÄÚÍøÇéÐεÄÁ½Ì¨Ð§ÀÍÆ÷£»
Server3ΪÍâÍøÇéÐÎϵÄһ̨ЧÀÍÆ÷£»
Server4Ϊһ̨˫Íø¿¨Ö÷»ú£¬»®·ÖÅþÁ¬192.168.50.0/24ºÍ172.16.2.0/24Á½¸öÍøÂç¡£
ÉèÖÃʵÑéÇéÐÎ
1. Server1,2,3 Éϴ HTTP ЧÀÍ
Óà Python ÔÚServer1Éϴһ¸ö¼òÆ HTTP ЧÀÍ
cd ~echo "server1" > index.htmlpython -m SimpleHTTPServer 8080
µÇ¼ºó¸´ÖÆ
Server2¡¢Server3ͬÀí
±ÈÕÕʵÑé
ÔÚclientÉÏ»á¼ûServer1µÄ×ÊÔ´
curl http://192.168.50.11:8080/index.html
µÇ¼ºó¸´ÖÆ
ÔÚclientÉÏ»á¼ûServer2µÄ×ÊÔ´
curl http://192.168.50.12:8080/index.htm
µÇ¼ºó¸´ÖÆ
ÔÚclientÉÏ»á¼ûServer3µÄ×ÊÔ´
curl http://172.16.2.11:8080/index.html
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
¿ÉÒÔ¿´µ½£¬ÍâÍøµÄclientÊÇÎÞ·¨»á¼ûÄÚÍøServer1,Server2µÄ×ÊÔ´µÄ¡£
ÔÚServer4ÉÏÉèÖö˿ÚÓ³Éä
ÔÝʱÉèÖÃ
#ÔÊÐíÊý¾Ý°üת·¢echo 1 >/proc/sys/net/ipv4/ip_forwardiptables -t nat -A POSTROUTING -j MASQUERADEiptables -A FORWARD -i ens33 -j ACCEPTiptables -t nat -A POSTROUTING -s 192.168.50.0/24 -o ens37 -j MASQUERADE#ÉèÖö˿ÚÓ³Éäiptables -t nat -A PREROUTING -p tcp -m tcp --dport 8081 -j DNAT --to-destination 192.168.50.11:8080iptables -t nat -A PREROUTING -p tcp -m tcp --dport 8082 -j DNAT --to-destination 192.168.50.12:8080
µÇ¼ºó¸´ÖÆ
ÓÀÊÀÉèÖÃ
ÈôÊÇÐèÒªÓÀÊÀÉèÖã¬Ôò½«ÒÔÉÏÏÂÁî×·¼Óµ½/etc/rc.localÎļþ¡£
¼ì²éЧ¹û
ÔÚclientÉÏ»á¼û Server1 µÄ×ÊÔ´
curl http://172.16.2.100:8081/index.html
µÇ¼ºó¸´ÖÆ
ÔÚclientÉÏ»á¼ûServer2µÄ×ÊÔ´
curl http://172.16.2.100:8082/index.html
µÇ¼ºó¸´ÖÆ
ÔÚclientÉÏ»á¼ûServer3µÄ×ÊÔ´
curl http://172.16.2.11:8080/index.html
µÇ¼ºó¸´ÖÆ µÇ¼ºó¸´ÖÆ
ÈôÊÇServer4Ϊ Windows£¬Ìæ»»Ò»ÏÂÏìÓ¦µÄÏÂÁî¼´¿É
Windows µÄ IP ÐÅÏ¢ÈçÏÂ
Íø¿¨ | IP µØµã | ×ÓÍøÑÚÂë | ĬÈÏÍø¹Ø | ±¸×¢ |
---|---|---|---|---|
Ethernet0 | 192.168.50.105 | 255.255.255.0 | – | ÄÚÍøÍø¿¨ |
Ethernet1 | 172.16.2.105 | 255.255.255.0 | – | ÍâÍøÍø¿¨ |
ÉèÖò¢Éó²é¶Ë¿ÚÓ³ÉäÇéÐÎ
netsh interface portproxy add v4tov4 listenaddress=172.16.2.105 listenport=8081 connectaddress=192.168.50.11 connectport=8080netsh interface portproxy add v4tov4 listenaddress=172.16.2.105 listenport=8082 connectaddress=192.168.50.12 connectport=8080netsh interface portproxy show v4tov4
µÇ¼ºó¸´ÖÆ
¼ì²éЧ¹û
ÔÚclient½ÚµãÉÏ
curl http://172.16.2.105:8081/index.htmlcurl http://172.16.2.105:8082/index.htmlcurl http://172.16.2.11:8080/index.html
µÇ¼ºó¸´ÖÆ
ÒÔÉϾÍÊÇLinux »ò Windows ÉÏʵÏֶ˿ÚÓ³ÉäµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡