DEV Community

Cover image for มุด Proxy ย้อนกลับ
Phongphan Phienphanich
Phongphan Phienphanich

Posted on

1

มุด Proxy ย้อนกลับ

เกริ่น ข้ามไปก็ได้

ปัญหาหนึ่งที่น่ารำคาญเมื่อวาง Server ไว้ที่ Colocation ต่างๆ ส่วนใหญ่ที่จะเจอคือ "ราคาค่า Inter(national) Bandwidth" ที่ค่อนข้างแพง เวลาจะจ่ายก็ต้องให้เหตุผลต่างๆนาๆ ว่ามีบริการที่ต้องวิ่งไปต่างประเทศหรือให้บริการต่างประเทศเยอะแค่ไหน คุ้มมั๊ย ใช่ครับหลายบริการแทบจะไม่ได้สนใจให้บริการต่างประเทศเลย ดังนั้นงบก็ไม่ cover ส่วนนี้

ใช่ครับ ฟังดูดี แต่ๆๆๆ ตอนจะ update patch/security หรือ update อื่นๆ (โดยเฉพาะพวก NVIDIA repo) ที่บางตัวใหญ่มากๆ และไม่มี repo ในไทย รอกันทีหลับแล้วหลับอีกก็อัพเดจไม่เสร็จ (แถมขยันมี update ซะด้วย)

110 kB/s
นี่คือตัวอย่างความเร็วปกติของ inter bandwidth บนเครื่อง

อีกด้านหนึ่ง เน็ตบ้านหรือเน็ตสำนักงาน ถูกและเร็ว แถมไม่เกี่ยงเท่าไหร่ว่าเป็นในประเทศหรือต่างประเทศ แรงเร็วถูก แซงหน้าเน็ต colocation ที่ซื้อ (ไม่เถียงครับว่าเทียบกันไม่แฟร์)

ผมเลยเกิด idea หนึ่งคือ ถ้าลองเอาบ้านเราเป็น proxy แล้วให้ server วิ่งย้อนกลับมา (บ้านเราอยู่ในประเทศแน่ๆ) ให้ออกเน็ตที่บ้านเราจะเป็นยังไง จนพบทางออกครับ ดังนี้ ...

เริ่มกันเลย

ก่อนอื่นเรามาสร้าง Squid Container ที่เครื่องเราก่อน (แน่นอนต้องแบบ Docker ดังนั้นขอข้ามขั้นตอนการลง Docker ไปเลย)

docker run -itd -p 3128:3128 b4tman/squid
Enter fullscreen mode Exit fullscreen mode

ใครจะเพิ่มเติมอะไรก็ตามสะดวก

ต่อด้วย การเพิ่ม Remote Forward Tunnel ไปยัง Server ในคำสั่ง SSH (-R 3128:127.0.0.1:3128)

ssh -R 3128:127.0.0.1:3128 <user>@<server>
Enter fullscreen mode Exit fullscreen mode

จากนั้นสั่งให้ SSH Session (คำสั่งนี้จะไม่ส่งผลต่อ SSH Session อื่น และเมื่อปิดก็จะหายไป) นั้นใช้ Proxy ผ่าน port ที่ forward ให้

export http_proxy=http://127.0.0.1:3128
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export dns_proxy=$http_proxy
export rsync_proxy=$http_proxy
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
Enter fullscreen mode Exit fullscreen mode

เป็นอันจบพิธี เรามาลองความเร็วกัน
6344 kB/s
เร็วขึ้นในระดับที่ใช้ได้ไม่หงุดหงิด (อาจจะมี Overhead ไม่ได้วิ่งได้เต็มขนาดนั้น) ถือว่าแจ่มเลยครับ

ขอสารภาพว่า Capture ไม่ทันใน file เดียวกันที่ download แต่ก็เป็น Inter bandwidth เหมือนกันน่าจะพอทดแทนกันได้

ไว้เดี๋ยวมาแชร์วิธีการมุดแปลกๆใหม่อีก รอติดตามนะฮว๊าฟๆๆๆ

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (0)

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay