DEV Community

tumit
tumit

Posted on

2

VPN แค่บางส่วนกับ openconnect กับ vpn-slice

ช่วง WFH แน่นอนสิ่งที่เราต้องใช้เสมอคือ VPN สำหรับเข้าถึง network ของที่ทำงาน แต่ปัญหาคือพอ VPN แล้วเราก็เหมือนเข้าไปในจักรวาลอีกจักรวาล บางทีก็ช้าจนแชร์ screen ไม่ได้หรือบล็อกบางเว็บที่เรา วันนี้เลยมาเสนอตัวช่วยคือ Openconnet & vpn-slice 

Openconnect คือ

เป็น cross-platform VPN Client (อย่างผมใช้ Manjaro Linux จะมีมาให้เลย MacOS ก็น่าจะ install ผ่าน brew ได้) ในการต่อ vpn เราสามารถใช้ openconnect ผ่าน command line ตัวอย่างเช่น

openconnect https://vpn.mycompany.com/

ข้อดีคือมันสามารถใช้กับ VPN ที่เราคุ้ยเคยอย่าง PAN GlobalProtect หรือ Fortinet SSL VPN ได้ด้วยการเพิ่ม param - protocal ได้ด้วย ตัวอย่างเช่น
openconnect --protocol=gp vpn.example.com
หรือ
openconnect --protocol=fortinet fortigate.example.com

vpn-slice พระเอกของงาน

vpn-clice เป็น python project สามารถ install ผ่าน pip ได้เลย 

sudo pip3 install "vpn-slice[dnspython,setproctitle]"

พอ install เสร็จแล้วเราสามารถเพิ่ม vpn-slice ไปเป็น param ที่ openconnect เพิ่มได้ว่า "เอาแค่ network หรือ domain นี้นะที่ไปกับ VPN"
ตัวอย่างที่ผมใช้จะเป็นประมาณนี้

ทำเป็น bash ไว้เช่น myvpn.sh (chmod u+x ให้เรียบร้อยจะได้ run ได้)

echo "super-password" | sudo openconnect --protocol=gp --user=tumit --script='vpn-slice 172.16.0.0/12 myweb.tumit.co.th db.tumit.co.th' vpn.tumit.co.th --passwd-on-stdin

  • เนืองจากไม่อยากกรอก password ทุกครั้งเลยให้ echo "password" แล้วใส่ | เพื่อส่งไปให้ openconnect แทน
  • เรียกคำสั่ง openconnect ตามด้วย param อย่างผมใช้ GlobolProtect ก็ใส่เป็น protocal=gp ตาม user 
  • ต่อมาส่วนที่ช่วยให้กำหนดว่า network หรือ domain ไหนที่เราอยาก VPN ก็มากำหนดที่ param script อย่างของผมอยากเข้าแค่ IP ที่เป็น 172.16.0.0/12 กับพวก web ใน dev environtment กับ db ก็ใส่ ๆ ไป
  • ที่เหลือก็ vpn domain กับส่วน password รับมาจาก echo ด้วย passwd-on-stdin

ก็จะประมาณนี้นั้นแล ~

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (1)

Collapse
 
gsew3433 profile image
yter dgd

Public Wi-Fi networks are often vulnerable to cyberattacks. Free VPN Planet adds an extra layer of security by encrypting your data while connected to public Wi-F i 在线 vpn, reducing the risk of unauthorized access to your personal information.

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay