×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùÔÚLinuxÉÏÉèÖö˿Úת·¢

ÔõÑùÔÚlinuxÉÏÉèÖö˿Úת·¢

ÔÚÖÖÖÖÍøÂçÓ¦ÓÃÖÐ £¬¶Ë¿Úת·¢ÊÇÒ»ÏîºÜÊÇÖ÷ÒªµÄ¹¦Ð§¡£ËüÔÊÐíÄ㽫ÍⲿÁ÷Á¿×ª·¢µ½ÄÚ²¿ÍøÂçÖеÄÌض¨¶Ë¿ÚÉÏ¡£ÔÚLinuxϵͳÉÏ £¬Í¨¹ýʹÓÃiptablesºÍsysctlÀ´ÊµÏֶ˿Úת·¢¹¦Ð§¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖö˿Úת·¢ £¬²¢ÌṩÏìÓ¦µÄ´úÂëʾÀý¡£

¼ì²éÄں˲ÎÊý

ÔÚ×îÏÈÉèÖö˿Úת·¢Ö®Ç° £¬ÎÒÃÇÊ×ÏÈÐèÒª¼ì²éÄں˲ÎÊýÊÇ·ñÔÊÐíת·¢¹¦Ð§¡£Í¨¹ýÔËÐÐÒÔÏÂÏÂÁî £¬¿ÉÒÔÉó²éÄ¿½ñϵͳµÄת·¢ÉèÖãº

sysctl net.ipv4.ip_forward

µÇ¼ºó¸´ÖÆ

ÈôÊÇÊä³öЧ¹ûΪnet.ipv4.ip_forward = 1 £¬ËµÃ÷ת·¢¹¦Ð§ÒѾ­¿ªÆô¡£ÈôÊÇÊä³öЧ¹ûΪnet.ipv4.ip_forward = 0 £¬ÔòÌåÏÖת·¢¹¦Ð§Î´¿ªÆô¡£ÔÚת·¢¹¦Ð§Î´¿ªÆôµÄÇéÐÎÏ £¬¿ÉÒÔͨ¹ýÔËÐÐÒÔÏÂÏÂÁîÀ´ÔÝʱ¿ªÆôת·¢¹¦Ð§£º

sysctl -w net.ipv4.ip_forward=1

µÇ¼ºó¸´ÖÆ

ÈôÊÇÐèÒªÓÀÊÀ¿ªÆôת·¢¹¦Ð§ £¬¿ÉÒԱ༭/etc/sysctl.confÎļþ £¬²¢Ìí¼Ó»òÐÞ¸ÄÒÔϲÎÊý£º

net.ipv4.ip_forward=1

µÇ¼ºó¸´ÖÆ

ÐÞ¸ÄÍê±Ïºó £¬ÉúÑÄÎļþ²¢ÔËÐÐÒÔÏÂÏÂÁîʹÆäÉúЧ£º

sysctl -p

µÇ¼ºó¸´ÖÆ

ÉèÖö˿Úת·¢

ʵÏֶ˿Úת·¢µÄ·½·¨ÓÐÐí¶àÖÖ £¬ÏÂÃæÎÒÃǽ«ÏÈÈÝÁ½ÖÖ³£Óõķ½·¨£ºÊ¹ÓÃiptablesºÍʹÓÃsocat¹¤¾ß¡£

A. ʹÓÃiptables

iptablesÊÇLinuxϵͳÉϳ£ÓõķÀ»ðǽ¹¤¾ß £¬ÎÒÃÇ¿ÉÒÔʹÓÃËüÀ´ÉèÖö˿Úת·¢¡£ÒÔÏÂÊÇͨ¹ýiptablesÉèÖö˿Úת·¢µÄʾÀý´úÂ룺

iptables -t nat -A PREROUTING -p tcp --dport <external_port> -j DNAT --to-destination <internal_ip>:<internal_port>
iptables -t nat -A POSTROUTING -j MASQUERADE

µÇ¼ºó¸´ÖÆ

ÆäÖÐ ÊÇÍⲿ¶Ë¿Ú £¬ ÊÇÄÚ²¿Ð§ÀÍÆ÷µÄIPµØµã £¬ ÊÇÄÚ²¿Ð§ÀÍÆ÷µÄ¶Ë¿ÚºÅ¡£ÕâÁ½ÌõÏÂÁ»á½«ÍⲿÁ÷Á¿×ª·¢µ½ÄÚ²¿Ð§ÀÍÆ÷ÉÏ¡£ÈôÊÇÏ£ÍûÍⲿÁ÷Á¿¾­ÓÉת·¢ºóÈÔÈ»Äܹ»×¼È·Ê¶±ðÔ´IPµØµã £¬¿ÉÒÔÌí¼ÓÒÔÏÂÏÂÁ

iptables -t nat -A POSTROUTING -o <external_interface> -j MASQUERADE

µÇ¼ºó¸´ÖÆ

ÆäÖÐ ÊÇÍⲿ½Ó¿ÚµÄÃû³Æ £¬ºÃ±Èeth0¡£

B. ʹÓÃsocat¹¤¾ß

socatÊÇÒ»¿îÇ¿Ê¢µÄÍøÂ繤¾ß £¬¿ÉÒÔ¾ÙÐÐÖÖÖÖÍøÂçÅþÁ¬ºÍת·¢¡£ÒÔÏÂÊÇͨ¹ýsocatÉèÖö˿Úת·¢µÄʾÀý´úÂ룺

socat TCP-LISTEN:<external_port>,fork TCP:<internal_ip>:<internal_port>

µÇ¼ºó¸´ÖÆ

ÆäÖÐ ÊÇÍⲿ¶Ë¿Ú £¬ ÊÇÄÚ²¿Ð§ÀÍÆ÷µÄIPµØµã £¬ ÊÇÄÚ²¿Ð§ÀÍÆ÷µÄ¶Ë¿ÚºÅ¡£ÕâÌõÏÂÁ»á½«ÍⲿÁ÷Á¿×ª·¢µ½ÄÚ²¿Ð§ÀÍÆ÷ÉÏ¡£

Ó¦ÓÃת·¢¹æÔò

ÎÞÂÛÊÇʹÓÃiptablesÕÕ¾Ésocat¹¤¾ß £¬ÉèÖõÄת·¢¹æÔò¶¼Ö»ÔÚÄ¿½ñ»á»°ÖÐÓÐÓá£ÈôÊÇÏ£ÍûÔÚϵͳÖØÆôºóÒÀÈ»ÓÐÓà £¬ÐèÒª½«ÕâЩ¹æÔòÓ¦Óõ½ÏµÍ³ÖС£

A. ʹÓÃiptables

ͨ¹ýÔËÐÐÒÔÏÂÏÂÁî¿ÉÒÔ½«iptables¹æÔòÓ¦Óõ½ÏµÍ³ÖУº

iptables-save > /etc/sysconfig/iptables

µÇ¼ºó¸´ÖÆ

B. ʹÓÃsocat¹¤¾ß

socat¹¤¾ßĬÈÏÔÚºǫ́ÔËÐÐ £¬ÈôÊÇÏ£Íûsocat¹æÔòÔÚϵͳÖØÆôºóÒÀÈ»ÓÐÓà £¬¿ÉÒÔ½«socatÉèÖüÓÈ뵽ϵͳÆô¶¯¾ç±¾ÖС£ÀýÈç £¬ÔÚUbuntuϵͳÉÏ¿ÉÒԱ༭/etc/rc.localÎļþ²¢Ìí¼ÓÒÔÏÂÄÚÈÝ£º

/path/to/socat TCP-LISTEN:<external_port>,fork TCP:<internal_ip>:<internal_port> &

µÇ¼ºó¸´ÖÆ

×¢ÖØ £¬/path/to/socatÐèÒªÌ滻ΪÏÖʵµÄsocat¹¤¾ß·¾¶¡£

×ܽá

±¾ÎÄÏÈÈÝÁËÔõÑùÔÚLinuxϵͳÉÏÉèÖö˿Úת·¢ £¬ÌṩÁËʹÓÃiptablesºÍsocat¹¤¾ßµÄ´úÂëʾÀý¡£Í¨¹ýÉèÖö˿Úת·¢ £¬¿ÉÒÔÎÞаµØ½«ÍⲿÁ÷Á¿×ª·¢µ½ÄÚ²¿Ð§ÀÍÆ÷ÉÏ £¬ÊµÏÖÍøÂçÓ¦ÓõĸºÔØƽºâ¡¢¶Ë¿ÚÓ³ÉäµÈ¹¦Ð§¡£

ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖö˿Úת·¢µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ